Page 1 of 1 1
Topic Options
#210321 - 2015-05-29 04:31 AM WMI Query for Win32_Process - getting owner
efarayenkay Offline
Just in Town

Registered: 2015-05-29
Posts: 2
Loc: Bathurst, Australia
Hi all

Long time KiXtart user, first time poster. I'm writing a script that lists people using MYOB (an accounting package for those unaware, and yes it does stand for that) because their data file has gotten to the point where it crashes regularly, locking out users and requiring a manual flush of the lock files before they can get in. To make matters worse, sometimes some goose leaves MYOB open and goes to lunch, leaving everyone else in the lurch.

To resolve this problem, I'm writing a script to allow the users to handle this process themselves (as an ASE executable running as an administrator user to give them the access they need without giving them full administrator rights) - not (just) because we're lazy, but because sometimes it happens outside our office hours and if it happens to someone on the west coast (we're east) after 5pm local time, they're stuck until tomorrow. It sort of came to a head when it happened to someone in Perth while they were processing pays...

To this end, I have the following code to look for anyone using that particular data file:

 Code:
Dim $sUser, $sDomain
	
$sFileName = "SNR Dodgy Constructions Pty Ltd.MYO"

$oWmi = GetObject("winmgmts://./root/cimv2")
	
$oEnum = $oWmi.ExecQuery("SELECT * From Win32_Process WHERE CommandLine LIKE '%%$sFileName%%'")

For Each $oInst in $oEnum
	$ = $oInst.getOwner($sUser, $sDomain)
	? "User: " $sUser
Next


Which works great, except it doesn't get the owner. Since KiX doesn't support passing by reference, what (if any) other options do I have for getting this information?

EDIT: KiXtart 4.64, running Windows Server 2008 R2


Edited by efarayenkay (2015-05-29 04:32 AM)

Top
#210322 - 2015-05-29 05:29 AM Re: WMI Query for Win32_Process - getting owner [Re: efarayenkay]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
If you are trying to get the owner of the process there are a couple of known options. The following udf works as long as it has admin privs.

GetProcessOwner()
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=204086#Post204086

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1


The other links that might be useful:
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=203743#Post203743
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83278

Please post your results.

Top
#210323 - 2015-05-29 06:16 AM Re: WMI Query for Win32_Process - getting owner [Re: Allen]
efarayenkay Offline
Just in Town

Registered: 2015-05-29
Posts: 2
Loc: Bathurst, Australia
Huh. Didn't even think of using ExecMethod. New script is:

 Code:
Dim $sUser, $sDomain
	
$sFileName = "SNR Dodgy Constructions Pty Ltd.MYO"

$oWmi = GetObject("winmgmts://./root/cimv2")
$iIndex = 3
	
$oEnum = $oWmi.ExecQuery("SELECT * From Win32_Process WHERE CommandLine LIKE '%%$sFileName%%'")

For Each $oInst in $oEnum
	$oParams = $oWMI.ExecMethod($oInst.path_, "getOwner")
	? "User: " $oParams.user
Next


Did exactly what I wanted it to do. Thanks, greatly appreciated. Now to work out how to log off the session for the users it finds...

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.049 seconds in which 0.021 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org