' ****************************************************************************** '* vbscript to prompt user to close open applications ' ****************************************************************************** Option Explicit ' ****************************************************************************** 'Global Constants const HKEY_CURRENT_USER = &H80000001 const HKEY_LOCAL_MACHINE = &H80000002 'Global variabels and objects Dim objShell : Set objShell = WScript.CreateObject("WScript.Shell") Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objreg : Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 'Define Paths Dim strBasePath : strBasePath = objFSO.GetParentFolderName(Wscript.ScriptFullName) 'Base Path is the directory the script is run from 'Other variables and constants Dim strMode Dim strName1, strName2, strName3, strName4, strname5, strProcess1, strProcess2, strProcess3, strProcess4, strProcess5 Dim strCheckprocess, strCheckname Dim Counter Dim strKeyPath 'Main Script 'Sets counter for how many minutes the timeout will be Counter = 30 strKeyPath = "SOFTWARE" '------------------------- ParseArgs Promptuser Checkprocess strprocess1, strName1 ' ------------------------------- Sub ParseArgs() 'Used to parse the arguments from command-line Dim count : count = 0 strName2 = "blank" If WScript.Arguments.Count = 0 then objShell.Popup "Example usage: " & vbCrLf & wscript.scriptname & " Internet Explorer iexeplore.exe" wscript.quit(1) Else StrName1 = WScript.Arguments.Item(0) StrProcess1 = Chr(34) & WScript.Arguments.Item(1) & Chr(34) End if End Sub Sub PromptUser Dim intButton, strMessage1, intButton1 Dim strmessage Dim StrValuName, StrValue 'Checks if program have been canceled before and how many times by reading/storing a value in the registry objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strName1,strValue 'wscript.echo strValue Do until Counter = 0 StrMessage1 = Strname1 & " will be installed/upgraded automatically in " & Counter & " Minutes." & vbCrLf & "To start the installation now press OK" intButton = objshell.Popup (strmessage1, 120, , 65) select case intButton case -1 Counter = Counter - 2 case 1 Counter = 0 If isNull(strvalue) then Else objReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strName1 End IF Case 2 objReg.getStringValue HKEY_LOCAL_MACHINE,strKeyPath,strName1,strValue If isNull(strvalue) then strvalue = 0 objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strName1,strValue End IF If strValue = 3 then Counter = 0 msgbox "The Installation have been postponed 3 times and will now start",64 objReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strName1 Else strValue = strValue + 1 objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strName1,strValue intbutton1 = msgbox ("The installation have been postponed " & strValue & " times, after 3 times the installation will start automatically",64, "Installation") Wscript.quit 1 End if End Select loop End Sub Function checkprocess(strcheckprocess, strcheckname) Dim objWMIService, colItems, objItem, iRetVal Dim strRunning strRunning = true If strcheckprocess <> "" then Do while strRunning = true Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select Name From Win32_Process Where Name = " & strcheckprocess & " ") strRunning = False For Each objItem in colItems strRunning = True iRetVal = objShell.Popup("Please close " & strCheckName & " for the installation to continue",, "Installation", 64) If iRetVal = 2 Then iRetVal = objShell.Popup("Installation has been canceled.",, "Installation", 1) wscript.quit(1) End If Next WScript.Sleep 2000 Loop end if End Function