Overview It is sometimes much easier (and easier to maintain) to use a Visual Basic Script on Windows to perform system functions rather than coding those functions in C++ (WMI is a good example of this). Consequently, there are a number of products that we have developed and maintain that internally use VBS files to perform Windows system functions. We sign all of our products (including VBS scripts) with a DSG VeriSign certificate. If you write scripts that are run on Windows computers you should seriously consider signing those scripts. The VBScript Signing Tool will make this task easier and well as generate C and RealBasic Code for you that you can include in projects that need to run VBS scripts. Program Start When you start the VB Script Signer, you will see the main program window: May 11, 2009 1
As you can see from the screen shot, the tool is very simple, so the best way to explain how it works is to present the information as a step by step tutorial. Step 1 Identify the location of SIGNCODE.EXE Click on the "SignCode.exe Dir" toolbar icon ( contains SIGNCODE.EXE: ) and navigate to the directory that SIGNCODE.EXE is distributed by Microsoft in the.net SDK. Step 2 Identify the location of your VerSign certificate Clicking on the "Cert Dir" ( VeriSign certificate: ) toolbar icon and navigate to the directory that contains your May 11, 2009 2
Step 3 Identify the location of your private key Clicking on the "Private Key Dir" ( your VeriSign certificate: ) toolbar icon and navigate to the directory that contains May 11, 2009 3
Once you have defined all certificate directories the "Save Dirs" toolbar icon will switch from disabled: to enabled:. Now would be a good time to click on the "Save Dirs" icon. The VBS Script Signer will save your preferences to the registry so that the next time you run the VBS Script Signer, the directory entries will be pre populated with your selections: Step 4 Select the VBS script to sign Click on the "VBS Script" toolbar icon ( ) to browse to the VBS script that you want to sign: Once you select a VBS file, the "Action" toolbar icons change from disabled ( ) to enabled ( ). The icons are: May 11, 2009 4
This will create source code that will be displayed in the "Code" text box that you can paste into a C program which will create a text string that you can output to a temporary file, and run. This will create source code that will be displayed in the "Code" text box that you can paste into either a Visual Basic or REALbasic program which will create a text string that you can output to a temporary file, and run. This will display a standard "Save As" dialog box that will allow you to save the signed VBS script. Clicking on any of these icons will launch SIGNCODE.EXE which will present a window where you are prompted to enter your password: Enter your password and click "OK" to sign the VBS file. May 11, 2009 5
Output Details The Sample Input VBS file strcomputer = "." Set objwmiservice = GetObject("winmgmts:\\" & strcomputer & "\root\cimv2") Set colitems = objwmiservice.execquery( _ "SELECT * FROM Win32_BootConfiguration",,48) For Each objitem in colitems Next Wscript.Echo "-----------------------------------" Wscript.Echo "Win32_BootConfiguration instance" Wscript.Echo "-----------------------------------" Wscript.Echo "BootDirectory: " & objitem.bootdirectory The sample script simply displays the Win32 Boot Directory (usually C:\Windows). Generate C Code After the "C Code" toolbar icon is pressed, the code that is created is displayed in the "Code" text box: May 11, 2009 6
You can copy this text to the clipboard and paste it into any C or CPP file. Here is some pseudo code that demonstrates how to use this function: char *scontents = NULL; // Build the VBS file contents scontents = BuildScript(); // Output the contents to a temporary VBS file // Run cscript.exe and pass it the path to the temporary VBS file // Examine the output of the script // Free the contents buffer free(scontents); Generate Basic Code After the "Basic Code" toolbar icon is pressed, the code that is created is displayed in the "Code" text box: May 11, 2009 7
You can copy this text to the clipboard and paste it into any Basic project. Here is some pseudo code that demonstrates how to use this function: dim scontents as string // Build the VBS file contents scontents = BuildScript(); // Output the contents to a temporary VBS file // Run cscript.exe and pass it the path to the temporary VBS file // Examine the output of the script Save the Signed VBS Script to a File After "Save VBS" is clicked and you specify the file path, the VBS Script Signer will save the signed script. Here is what the example input script looks like after signing: strcomputer = "." Set objwmiservice = GetObject("winmgmts:\\" & strcomputer & "\root\cimv2") Set colitems = objwmiservice.execquery( _ "SELECT * FROM Win32_BootConfiguration",,48) For Each objitem in colitems Next Wscript.Echo "-----------------------------------" Wscript.Echo "Win32_BootConfiguration instance" Wscript.Echo "-----------------------------------" Wscript.Echo "BootDirectory: " & objitem.bootdirectory '' SIG '' Begin signature block '' SIG '' MIIVGQYJKoZIhvcNAQcCoIIVCjCCFQYCAQExDjAMBggq '' SIG '' hkig9w0cbquamgygcisgaqqbgjccaqsgwdbwmdigcisg '' SIG '' AQQBgjcCAR4wJAIBAQQQTvApFpkntU2P5azhDxfrqwIB '' SIG '' AAIBAAIBAAIBAAIBADAgMAwGCCqGSIb3DQIFBQAEEATG '' SIG '' Z83JTjbDYwxTZDjzuPKgghECMIIDejCCAmKgAwIBAgIQ '' SIG '' OCXX+vhhr570kOcmtdZa1TANBgkqhkiG9w0BAQUFADBT '' SIG '' MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24s '' SIG '' IEluYy4xKzApBgNVBAMTIlZlcmlTaWduIFRpbWUgU3Rh May 11, 2009 8
'' SIG '' bxbpbmcgu2vydmljzxmgq0ewhhcnmdcwnje1mdawmdaw '' SIG '' WhcNMTIwNjE0MjM1OTU5WjBcMQswCQYDVQQGEwJVUzEX '' SIG '' MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAMT '' SIG '' K1ZlcmlTaWduIFRpbWUgU3RhbXBpbmcgU2VydmljZXMg '' SIG '' U2lnbmVyIC0gRzIwgZ8wDQYJKoZIhvcNAQEBBQADgY0A '' SIG '' MIGJAoGBAMS18lIVvIiGYCkWSlsvS5Frh5HzNVRYNerR '' SIG '' Nl5iTVJRNHHCe2YdicjdKsRqCvY32Zh0kfaSrrC1dpbx '' SIG '' qupjrucuawustksrjo5ysovub+qalpicqljzzulzlcb1 Many more lines follow until '' SIG '' End signature block You can run the script as you would normally (cscript.exe, or wscript). When you right click on the VBS file and choose "Properties you should notice a new tab "Digital Signatures". Selecting the tab will allow you to examine the signing details: May 11, 2009 9
May 11, 2009 10