Programmatically Signing a Script

Microsoft® Windows® 2000 Scripting Guide

WSH 5.6 includes the Scripting.Signer object that allows you to digitally sign a script using another script. To do this you need to:

  • Create an instance of the Scripting.Signer object.

  • Use the SignFile method, specifying both the file name of the script to be signed and the name of the digital certificate to be used to sign the script.

For example, this script uses the IT Department certificate to sign the script C:\Scripts\CreateUsers.vbs.

set objSigner = WScript.CreateObject("Scripting.Signer")
objSigner.SignFile "C:\Scripts\CreateUsers.vbs", "IT Department"

You can also digitally sign a number of scripts at the same time. This script loops through and signs all the files found in the C:\Scripts folder. (The assumption is that the only scripts are stored in C:\Scripts.)

set objSigner = WScript.CreateObject("Scripting.Signer")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\scripts")
Set colListOfFiles = objFolder.Files
For each objFile in colListOfFiles
    objSigner.SignFile objFile.Name, "IT Department"