Saturday, March 8, 2014

VBScript to check processor warn user install application notify the user

If we need to deploy an application to an end user device with the following requirements;
- The script should check for a process whether it is running or not
- If the processor is running, prompt the user to close the application check in a loop until it is closed
- Install the application
- Advise the user that the application deployment is completed

There are many script with different methods. I have created the below simple script to fulfil the requirements
********************************************************************
strComputer="."
 ProcWatch="Notepad.exe"

Set objShell = CreateObject("WScript.Shell")
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name ='" & ProcWatch & "'")
 Do Until colProcesses.Count = 0
 MsgBox "Notepad is running." & vbNewLine & "Please close the application then click OK." ,48, "Close the application"
wscript.sleep 500
  Set colProcesses = objWMIService.ExecQuery _
  ("Select * from Win32_Process Where Name ='" & ProcWatch & "'")
 Loop

oWSH.Run "MSIEXEC.EXE /i ""Test.msi "" /passive", 0, True
 MsgBox "Application installed successfully." & vbNewLine &  "You can start using the application." ,64, "Application Installed"

*************************************************************************
Few things to remember when using this script with SCCM,
- The deployment should run only when a user is logged on
- The deployment should run in interactive mode
- Change the processor name from Notepad.exe to the actual processor
- Change the name of the Test.msi to the actual MSI name

No comments:

Post a Comment