Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript to check if Explorer.exe process running on a 64-Bit Windows PC?

Status
Not open for further replies.

TrickyDicky12

Technical User
Oct 30, 2012
4
GB
Hi,

I have had a vbscript which has worked perfectly on a server which pings workstations to determine whether the PC is free for users to use.
I did this my pinging the PC and then checking if the explorer.exe process was running on the system. See below

' Check if Process is running on pinged PC that was Successful
Sub Query_Process_Running
'--- *******************************************
On Error Resume next
Set objLocator=CreateObject("WbemScripting.SWbemLocator")
Set objWMISer = objLocator.ConnectServer(strComputer,"root\cimv2",,,,,128)
' Wscript.Echo "after set loc"&cNoPCS&","&nct&","&strComputer
' Set objWMISer = GetObject("winmgmts:" _
' & "{impersonationLevel=impersonate}!\\" _
' & strComputer & "\root\cimv2")
If Err.Number = 0 Then
Set colProcessList = objWMISer.ExecQuery _
("Select Name from Win32_Process Where Name = 'explorer.exe'",,48)
If Err.Nmber = 0 Then
For Each objProcess in colProcessList
flagLog = True
Next
End If
Else
Err.Clear
End If
' objTextFile.WriteLine(Now&","&strComputer&","&flagLog)
On Error goto 0

End Sub

This all worked fine when the PCs were 32-bit Windows 7, however we have moved to 64-bit Windows 7 images, and my script no longer works. The ping works, but the explorer.exe process is not being reached. Can anyone else me achieve this so it will be able to check if explorer.exe is running on a 64-bit PC?

Thanks,
 
You have a typo. Also, I would initialize flagLog. Otherwise your code should work on 64-bit
Code:
On Error Resume next
[highlight #FCE94F]flagLog = True[/highlight]
Set objLocator=CreateObject("WbemScripting.SWbemLocator")
Set objWMISer = objLocator.ConnectServer(strComputer,"root\cimv2",,,,,128)
' Wscript.Echo "after set loc"&cNoPCS&","&nct&","&strComputer
' Set objWMISer = GetObject("winmgmts:" _
' & "{impersonationLevel=impersonate}!\\" _
' & strComputer & "\root\cimv2")
If Err.Number = 0 Then
   Set colProcessList = objWMISer.ExecQuery _
      ("Select Name from Win32_Process Where Name = 'explorer.exe'",,48)
   [highlight #FCE94F]If [COLOR=#EF2929]Err.Nmber[/color] = 0 Then[/highlight]
      For Each objProcess in colProcessList
         flagLog = True
      Next
   End If
Else
   Err.Clear
End If
' objTextFile.WriteLine(Now&","&strComputer&","&flagLog)
On Error goto 0

End Sub
 
To note, if you removed that on error resume next or more efficiently used it you'd maybe have captured this error.
Currently you have it set to 'ignore errors' and keep proceeding but then are capturing it w/ Err.number and then ignoring it again in the else
and then turning on error off.
All the while never truly capturing, logging or noting any error.


[yinyang] Tranpkp [pc2]
 
I agree. Ironically, the one time vbscript error trapping breaks down (even when done properly) is when the error is in the line of code where you test for an error!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top