'************************************************************************ ' File: AutoSignRegconfig.vbs (WSH in VBScript) ' Author: M. I. Gallant ' Date: 06/17/2002 ' Site: http://home.istar.ca/~neutron/wsh ' ' Configures win32 registry with "Digitally Sign" verb for ' specified list of file-types supporting Authenticode signing. ' Requires signcode.exe (Authenticode 5 tools or Platform SDK) ' Edit "autosignscript" variable for the location of the "autosignwiz.vbs" script ' Default file types configured are vbs, js and exe '************************************************************************ Option Explicit Const autosignscript = "c:\scriptaids\autosignwiz.vbs" 'edit this for your install path to autosignwiz.vbs Dim WshShell, fso, scriptinfo, ProgIDs, result, changes, signkey, signcmd, i signcmd = "wscript.exe " & autosignscript & " ""%L""" ProgIDs = Array("VBSFile", "JSFile", "exefile") ' file types to modify changes = "" scriptinfo = "****** AutoSignRegconfig.vbs *******" & vbCrLf & vbCrLf & _ "This script extends the shortcut menu of certain files with a " & vbCrLf & _ """Digitally Sign"" selection (verb). Changes are automatically make" & vbCrLf & _ "to registry for file-types that support Authenticode signing using" & vbCrLf & _ "signcode.exe. The command associated with ""Digitally Sign"" depends " & vbCrLf & _ "on a script file ""autosignwiz.vbs"" which should be installed" & vbCrLf & _ "before executing this shortcut configuration script." & vbCrLf & vbCrLf & _ "Do you wish to continue?" result = MsgBox(scriptinfo, vbYesNo+vbInformation, "About autosignregconfig.vbs") If result = vbNO Then WScript.Quit End If '------- Check for installation of autosignwiz.vbs script ---- Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(autosignscript) Then MsgBox """" & autosignscript & """ shortcut command script was found. " & vbCrLf & vbCrLf & _ "Proceeding with registry configuration .... ", vbOKOnly+vbInformation, "Check autosignwiz.vbs install" Else MsgBox """" & autosignscript & """ shortcut command script was NOT found. " & vbCrLf & vbCrLf & _ " - install the required ""autosignwiz.vbs"" script to any directory " & vbCrLf & _ " - edit the ""autosignscript"" variable above for your chosen directory " & vbCrLf & _ " - run this configuration script again. " & vbCrLf & vbCrLf & _ "Exiting this script .... ", vbOKOnly+vbExclamation, "Check autosignwiz.vbs install" WScript.Quit End If Set fso = Nothing '------- End check for autosigwiz.vbs script -------------- For i=0 to UBound(ProgIDs) changes = changes & "HKEY_CLASSES_ROOT\" & ProgIDs(i) & "\Shell\Digitally Sign\Command " & vbCrLf & _ vbTab & signcmd & vbCrLf & vbCrLf Next result = MsgBox ("Configure registry with these settings?" & vbCrLf & vbCrLf & _ changes & vbCrLf & _ "Configure these changes now?? ", vbYesNo+vbExclamation, "Digitally Sign Registry Configuration") If result = vbNO Then WScript.Echo "You have decided NOT to modify the registry for digital signature modifications" WScript.Quit End If Set WshShell = CreateObject("WScript.Shell") For i = 0 to UBound(ProgIDs) signkey = "HKCR\" & ProgIDs(i) & "\Shell\Digitally Sign\Command\" 'WScript.Echo "signkey " & signkey & vbCrLf & "signcmd " & signcmd If KeyExists(signkey) Then 'WScript.Echo signkey & " exists " & WshShell.RegRead(signkey) If WshShell.RegRead(signkey) = signcmd Then WScript.Echo signkey & " is already configured and up-to-date" else WScript.Echo "Updating " & signkey WshShell.RegWrite signkey, signcmd , "REG_EXPAND_SZ" End If else WScript.Echo "Generating key " & signkey WshShell.RegWrite signkey, signcmd , "REG_EXPAND_SZ" End If Next MsgBox "Registry configuration complete", vbOKOnly+vbInformation, "Digitally Sign Registry Configuration" Set WshShell = Nothing Function KeyExists(key) Dim key2 On Error Resume Next key2 = WshShell.RegRead(key) If Err <> 0 Then KeyExists = False Else KeyExists = True End If On Error GoTo 0 End Function