Programmatically Verifying a Signed Script

Microsoft® Windows® 2000 Scripting Guide

The Scripting.Signer object can also be used to programmatically verify the digital signature on a script. To do this, you need to use the VerifyFile method, along with two arguments:

  • The file name of the script whose signature is to be verified.

  • A Boolean value indicating whether or not you want the Security Warning dialog box to appear in case the signature cannot be verified. If this value is set to False, the dialog box will not appear. If the value is set to True, however, a dialog box will be displayed, warning you that the script signature could not be verified, and asking you whether or not you still want to run the script.

The following script verifies the signature on the file C:\Scripts\CreateUsers.vbs, and suppresses the Security Warning dialog box. The script will return one of two values: True means that the digital signature has been verified, False means either that the script has not been signed or the signature could not be verified.

Set objSigner = WScript.CreateObject("Scripting.Signer")
blnShowGUI = False
blnIsSigned = objSigner.VerifyFile("C:\Scripts\CreateUsers.vbs", blnShowGUI)
If blnIsSigned then
    WScript.Echo objFile.Name & " has been signed."
Else
    WScript.Echo objFile.Name & " has not been signed."
End If

Alternatively, you might want to use the VerifyFile method to verify the digital signatures on a number of scripts. For example, this script verifies the digital signatures on all the scripts found in the C:\Scripts folder.

Set objSigner = WScript.CreateObject("Scripting.Signer")
blnShowGUI = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Scripts")
Set colListOfFiles = objFolder.Files
For each objFile in colListOfFiles
    blnIsSigned = objSigner.VerifyFile(objFile.Name, blnShowGUI)
    If blnIsSigned then
        WScript.Echo objFile.Name & " has been signed."
    Else
        WScript.Echo objFile.Name & " has not been signed."
    End If
Next