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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to compare Logged On User with Process Owner?

Status
Not open for further replies.

CurtisLGray

Technical User
Jan 13, 2005
3
0
0
US
To Anyone that can help:

I'm writing a script and I need to wait for an external process to finish before continuing to the next step. The process I want to monitor is "msiexec.exe", but since multiple instances run when an MSI application is launched, I need to monitor the "msiexec.exe" process which was started by the user currently logged in, NOT the system account.

Using VBScript, does anyone know how to Compare the username returned by a WMI query from Win32_ComputerSystem, and the username returned by a WMI query from Win32_Process.

I think that this will really help resolve my issue.

Thanks in advance!
 
when you say 'compare' are you meaning a text comparison?

Lcase(CStr()) etc.
do you have example code for getting both of these usernames returned from the 2 wmi queries?

would account of the number of msiexec processes before running your app, and then looping checking for when the number instances returns to this figure,,,,hmm not that bomb proof really.

right then, im interested. if you can get me started with a couple of wmi scripts i will give you a hand with it as i typically go for the start and end counters which has worked for me in the past but the solution you propose seems to hold more water
 
'from ms's site

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery( _
"select * from win32_process" )
For Each objProcess in colProcesses

If objProcess.GetOwner ( User, Domain ) = 0 Then
Wscript.Echo "Process " & _
objProcess.Caption & _
" belongs to " & Domain & _
"\" & User
Else
Wscript.Echo "Problem " & Rtn & _
" getting the owner for process " _
& objProcess.Caption
End If
Next

returns the domain and user, prob only need the user.
i would just go for a simple

WshShell.ExpandEnvironmentStrings("%username%")
or
WshNetork.Username
WshNetwork.DomainName
 
Thanks for the help, but I found another way to resolve my issue, which was to wait for the installation of an MSI application to complete before proceeding with the script. I thought that the following line wasn't working because the script would continue after launching the installation:

objShell.Run strApplicationfile, 1, True

But the problem was that I was actually running a setup.exe file which then triggered the MSI file, so the script only monitored the setup.exe.

Thanks for your help though.
 
Hallo CurtisLGray,

I have the same problem with you, how do you solve the problem exactly?
My case:
Unattended install of windows xp/2k3, application install:
...
a) adobe acrobat reader 7.0
b) java runtime 5.01sp1
...
the wmi script to watch the msiexec.exe of "a)" proccess(acrobat reader 7) would not report the correctly because the system have also msiexec.exe in background...
but the owner of the "a)" proccess is "admin". It should be a way to solve it...
code:
blnRunning = True
Do While blnRunning = True
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name from Win32_Process where Name='" & Wscript.Arguments(0) & "'",,48)
blnRunning = False
For Each objItem in colItems
blnRunning = True
Next
WScript.Sleep 500
Loop

Many THX in advance.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top