'*************************************************************************************** ' File: AutoSigncode56.vbs (WSH in VBScript) ' Author: M. I. Gallant ' Date: 11/28/2001 ' Site: http://home.istar.ca/~neutron/ ' ' Automatic signing script for MS signcode.exe. Requires WSH 5.6 ' - WARNING: IT IS NOT ADVISABLE TO STORE PASSWORDS IN PROGRAMS - ' - THIS SCRIPT IS NOT SUPPORTED IN ANY WAY '***************************************************************************************** Option Explicit Const filetosign = "yourfiletosign.exe" Const signcommand = "signcode -cn ""Yourcert CN"" -t http://timestamp.verisign.com/scripts/timstamp.dll" Const promptTitle = "Signing data with your private signature key!" 'Window title for pswd prompting Const tmpFolder = 2 ' System's temp folder Const pswd = "xxxxxxxxxxxxxxxxxxxxxxx" ' password Const ShowSigningStatus = True Dim Wshshell, fso, oExec, shell, counter, tmp, signResult, exeError If WScript.Version < 5.6 Then MsgBox "AutoSigncode56.vbs requires WSH 5.6+", vbCritical WScript.Quit End If Set Wshshell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") If NOT fso.FileExists(filetosign) Then MsgBox "File : " & filetosign & " does not exist", vbCritical WScript.Quit End If set fso = nothing set oExec = Wshshell.exec(signcommand & " " & filetosign) counter=0 Do While NOT Wshshell.AppActivate(promptTitle) ' wait until signcode prompt title appears WScript.Sleep 200 counter = counter + 1 If counter > 10 Then 'trap errors if for some reason password prompt window does not show within 2 seconds signResult = ReadAllFromAny(oExec) MsgBox signResult, vbCritical WScript.Quit End If Loop WScript.Sleep 200 Wshshell.AppActivate(promptTitle) Wshshell.SendKeys(pswd) ' type pswd WScript.Sleep 200 Wshshell.SendKeys("{ENTER}") ' return signResult = ReadAllFromAny(oExec) Do While oExec.Status = 0 WScript.Sleep 100 Loop Wshshell.Popup "Signing " & filetosign & vbCrLf & _ signResult, 4, "AutoSigncode56.vbs", vbInformation WScript.Quit Function ReadAllFromAny(oExec) If Not oExec.StdOut.AtEndOfStream Then ReadAllFromAny = oExec.StdOut.ReadAll Exit Function End If If Not oExec.StdErr.AtEndOfStream Then ReadAllFromAny = "STDERR: " + oExec.StdErr.ReadAll Exit Function End If ReadAllFromAny = -1 End Function '********************** End Script ******************************