'********************************************************************* ' File: AutoVerifySig.vbs (WSH in VBScript) ' Author: M. I. Gallant ' Date: 10/14/2002 ' Site: http://home.istar.ca/~neutron/wsh ' ' Provides drag/drop Authenticode signature verification ' with automatic file selection entered. ' ' Can use either approach (depending on useCapicom boolean): ' - WSH 5.6 Scripting.Signer.Verify ' - CAPICOM 2 CAPICOM.SignedCode.Verify ' ' Use also to extend shortcut context-menu for semi-automation for signing: ' e.g: ' HKEY_CLASSES_ROOT\VBSFile\Shell\Digitally Sign\Command ' wscript.exe c:\scriptaids\autoverifysig.vbs "%L" ' Add this registry setting for any file-types supporting Authenticode ' signature (exe, dll, cab, ctl, ocx, cat, vbs, js, wsh) ' ' See related registry configuration script: autoverifyregconfig.vbs '********************************************************************** Option Explicit Dim oSigner, oSignedCode, fso, sourcefile, fileargs Dim OK :OK = False Dim useCapicom :useCapicom = True Set fileargs = WScript.Arguments If fileargs.Count<1 Then MsgBox "autoverifysig.vbs requires a single argument", _ vbOKOnly + vbExclamation, "About autoverifysig.vbs" WScript.Quit End If sourcefile = fileargs(0) 'get dragged file name Set fso = CreateObject("Scripting.FileSystemObject") If NOT fso.fileExists(sourcefile) Then MsgBox sourcefile & " not found, or is not a valid file. ", _ vbOKOnly + vbCritical, "Bad file" WScript.Quit End If If NOT useCapicom Then 'use WSH 5.6 Set oSigner = CreateObject("Scripting.Signer") OK = oSigner.VerifyFile(sourcefile) Veristatus("WSH 5.6") Set oSigner= Nothing Else ' use CAPICOM 2 Set oSignedCode = CreateObject("CAPICOM.SignedCode") oSignedCode.FileName = sourcefile On Error Resume Next oSignedCode.Verify If Err.Number <>0 Then ' If failed signature verification OK = False Else OK = True End If On Error Goto 0 Veristatus("CAPICOM 2") Set oSignedCode = Nothing End If Sub VeriStatus(style) If OK Then MsgBox sourcefile & vbCrLf & vbCrLf & "Verification SUCCEEDED.", _ vbOKOnly + vbInformation, style & " signature Verification" Else MsgBox sourcefile & vbCrLf & vbCrLf & _ "Verification FAILED!" & vbCrLf & _ "This file is not signed, or the signature is invalid !!!", _ vbOKOnly + vbCritical, style & " signature Verification" End If End Sub '------- End autoverifysig.vbs script -------------------