'*************************************************************************************** ' File: AutoSigncode.vbs (WSH in VBScript) ' Author: M. I. Gallant ' Date: 11/27/2001 ' Site: http://home.istar.ca/~neutron/ ' ' Automatic signing script for MS signcode.exe ' - WARNING: IT IS NOT ADVISABLE TO STORE PASSWORDS IN PROGRAMS - ' - THIS SCRIPT IS NOT SUPPORTED IN ANY WAY '***************************************************************************************** Option Explicit Const filetosign = "yourapptosign" Const signcommand = "%COMSPEC% /C signcode -cn ""YourCertCN"" -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 = "xxxxxxxxxxxxxxxxxxxxxx" ' password Const ShowSigningStatus = True Dim Wshshell, fso, shell, counter, tmp, signResult Set Wshshell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") tmp = fso.GetTempName ' temp filename for signcode output tmp = fso.GetSpecialFolder(tmpFolder) & "\" & tmp ' Create temporary file path. If NOT fso.FileExists(filetosign) Then MsgBox "File : " & filetosign & " does not exist", vbCritical WScript.Quit End If Wshshell.Run signcommand & " " & filetosign & " >" & tmp, 1 counter=0 Do While NOT Wshshell.AppActivate(promptTitle) ' wait until signcode prompt title appears WScript.Sleep 200 counter = counter + 1 If counter > 100 Then 'avoid infinite loop (20 secs), if problem with timestamping, for example. Exit Do End If Loop WScript.Sleep 200 Wshshell.AppActivate(promptTitle) Wshshell.SendKeys(pswd) ' type pswd WScript.Sleep 200 Wshshell.SendKeys("{ENTER}") ' return counter=0 Do Until fso.FileExists(tmp) AND fso.getFile(tmp).Size >5 'make sure output file is available and written to WScript.Sleep 200 counter = counter +1 If counter > 100 Then 'avoid infinite loop (20 secs), if problem generating redirect output file. WScript.Echo "Problem with signing script or generating output file" WScript.Quit End If Loop If ShowSigningStatus Then signResult = fso.OpenTextFile(tmp).ReadLine() If Instr(1,fso.OpenTextFile(tmp).ReadLine(), "Succeeded", 1) >0 Then WScript.Echo "Signing Succeeded" ElseIf Instr(1,fso.OpenTextFile(tmp).ReadLine(), "Error: Signing Failed", 1) >0 Then WScript.Echo "Signing Failed: wrong password or other error " End If End If If fso.FileExists(tmp) Then 'cleanup temp file fso.getFile(tmp).delete() End If WScript.Quit '********************** End Script ******************************