Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need VBScript to monitor a 64 bit process and take action when the process closes

Posted on 2009-06-30
2
Medium Priority
?
1,571 Views
Last Modified: 2013-11-29
I have been using a VBScript to launch a special 32 bit application, then monitor it's process to see when it closes, then log the user off automatically.  But now I need to modify this to run on W2K3 x64 (and the process is also 64 bit now).  Can someone help me modify the below portion of a script so that it would work on W2K3 x64, and when MyProgram.EXE is also 64 bit?

(This was the VBScript for 32 bit version of the program)
'Connect to wmi
'set objWMIService = GetObject("winmgmts:root\cimv2")
Do
 found = false
'List the processes
strQuery = "Select * from win32_process where name='MyProgram.EXE'"
set colProcesses = objWMIService.ExecQuery(strQuery)
 
for each proc in colProcesses
 
   ' Get the reference class linking processes to sessions to get the session object path
   strQuery = "References of {win32_process.handle='" & proc.handle & "'} where ResultClass=Win32_SessionProcess"
   set colSessionReferences = objWMIService.ExecQuery(strQuery)
 
   for each oSessionReference in colSessionReferences
      'Get associators of the session object that are user accounts (linked by win32_loggedonuser)
      strQuery = "Associators of {" & oSessionReference.antecedent & "} where AssocClass=win32_LoggedOnUser"
      set colUsers = objWMIService.ExecQuery(strQuery,,48)
         for each user in colUsers
         if user.name = MUser then found = true
      next
   next
next
Loop While found = true
 
'Run the Windows 2003 logoff utility
wshShell.Run "c:\windows\system32\shutdown.exe -l -f"

Open in new window

0
Comment
Question by:Herrmannator
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
asrdias earned 2000 total points
ID: 24761533
The script should be fine... it works in my x64 Win7...

You must check if your wscript or cscript are running in 32bit or 64bit. Use task manager to check those processes. If there is a *32 in front of them then you're on 32 bit.
The 32 bit versions are stored in C:\Windows\SysWOW64 and the 64 bit ones should be on System32

0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question