#137850 - 2005-04-13 05:30 PM
Need help with EnumProcess
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
For about two seconds I was posting this under the UDF forum but I thought better of it and figured this question would be better posted here. I have read everything I could about EnumProcess but am a bit stumped. I have a group of useres who run a particular app all day. At the end of the day I have to run a backup of that program but it will not allow me to do so unless they are out of it. I need to be able to run an admin script that will tell me who in this user group is running this particular program. This is all I have so far and I am 100% sure that it is all wrong: Code:
If InGroup("Administration") EnumProcess($program,,$officecomputers) EndIf
Any help will be greatly appreciated! Thanks.
|
Top
|
|
|
|
#137851 - 2005-04-13 05:54 PM
Re: Need help with EnumProcess
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$arraycomputers='computer1','computer2','computer3' for each $computer in $ArrayComputers if EnumProcess($exe, , $Computer) ? $computer endif next
will display the computer that is running the process Place a value in the second parameter and it will end the task
|
Top
|
|
|
|
#137853 - 2005-04-13 06:15 PM
Re: Need help with EnumProcess
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
1) that is the "? $computer" statement
2) anywhere before the "for each" statement
|
Top
|
|
|
|
#137854 - 2005-04-13 06:46 PM
Re: Need help with EnumProcess
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
Okay, I tried that out and I do seem to get some progress but it's hard to measure as there is no visual output. So to be clear, to run this I do need local admin credentials to the computers in question, correct? Edit: Let me correct that. This is the only output:
Quote:
select * from Win32_Process where Name='program.exe'
I guess where I'm lost mainly is how the stings $computer and $arraycomputers are related. Shouldn't I need to add something (what I'm not sure yet) to associate the strings together?
|
Top
|
|
|
|
#137855 - 2005-04-13 07:57 PM
Re: Need help with EnumProcess
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
yes, you need admin on the remote PCs
$arraycomputers='computer1','computer2','computer3'
for each (element of array) in (array of elements)
|
Top
|
|
|
|
#137856 - 2005-04-13 08:57 PM
Re: Need help with EnumProcess
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
Okay, I'm gonna list the script as is. Please tell me where I'm going wrong. Code:
$exe='program.exe' $arraycomputers='computer1','computer2','computer3' For Each $computer in $ArrayComputers If EnumProcess($exe, , $Computer) ? $computer EndIf
Now if I change one of the elements in that array to @wksta the script works properly for my system only. I tried running this script with admin privs and still no dice for the other remote machines.
|
Top
|
|
|
|
#137857 - 2005-04-13 09:45 PM
Re: Need help with EnumProcess
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You seem to be missing a "NEXT" to close your loop.
|
Top
|
|
|
|
#137858 - 2005-04-13 09:57 PM
Re: Need help with EnumProcess
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
Sure was, thanks. But that didn't solve the problem. In my mind, it's definitely something to do with my syntax in the array. Let's say I had computers named kiXn00b and a domain called domain.tld. Would the proper syntax be?: Code:
$arraycomputers='kiXn00b1','kiXn00b2','kiXn00b3'
or Code:
"...'kiXn00b1.domain.tld',..."
Or would I include the domain.tld?
|
Top
|
|
|
|
#137859 - 2005-04-13 10:09 PM
Re: Need help with EnumProcess
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$arraycomputers='kiXn00b1','kiXn00b2','kiXn00b3'
is correct
And of course, enumProcess is somewhere in your script and the target machines are NT sp4 or better and there are no firewalls blocking the connection and you have admin on each box
|
Top
|
|
|
|
#137860 - 2005-04-13 10:25 PM
Re: Need help with EnumProcess
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
EnumProcess is in the script. Otherwise, it wouldn't have worked for @wksta, right? Target machines are XP. No firewalls. I have Domain Admin privs and DA's have full local admin privs.
|
Top
|
|
|
|
#137862 - 2005-04-14 02:56 AM
Re: Need help with EnumProcess
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$arraycomputers='computer1','computer2','computer3' $processes='a.exe','b.exe','c.exe' for each $computer in $ArrayComputers for each $proc in $processes if EnumProcess($proc, , $Computer) ? $computer endif next next
|
Top
|
|
|
|
#137863 - 2005-04-14 06:43 PM
Re: Need help with EnumProcess
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
Thanks, Radimus. It is beginning to show signs of working. It only seems to be working for the first couple of listed processes but I'll keep tweaking on it until it does what I need it to. I did find a command-line tool that can do the same function. It's called PSTools. But I wanted a way to do this with KiXtart. Now, on the same note, could someone give me a push in the right direction to do this: I would like to parse the data from the above script into a messagebox that told me which $computer is running which $proc. Seems like it should be simple enough to do...
|
Top
|
|
|
|
#137864 - 2005-04-14 07:19 PM
Re: Need help with EnumProcess
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
change ? $computer into $=sendmessage(@wksta,$computer +' is running '+ $proc)
|
Top
|
|
|
|
#137865 - 2005-04-15 12:03 AM
Re: Need help with EnumProcess
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
Awesome!! It pops up that box for every instance of a $proc that's found. Mission fully accomplished. Here's the code in it's final form: Code:
$arraycomputers='@wksta','COMP1','COMP2','COMP3' $processes='PROC1','PROC2','PROC3' For Each $computer in $ArrayComputers For Each $proc in $processes If EnumProcess($proc, , $Computer) $=SendMessage(@wksta,$computer +' is running '+ $proc) EndIf Next Next
Thanks a ton to everyone who helped me, especially Radimus. I think I'm beginning to understand KiX a bit better after all of that.
|
Top
|
|
|
|
#137867 - 2005-04-18 04:21 PM
Re: Need help with EnumProcess
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Running a ping is an EXCELLENT idea. I would suggest you make the ping part of your main script, instead of a seperate script. This is what I (we) do:
Code:
shell("%comspec% /c ping -n 2 $hostname | findstr /i ttl= >nul 2>nul")
if @ERROR = 0
; then do your stuff
else
; the machine is not pingable
endif
-Shawn
|
Top
|
|
|
|
#137868 - 2005-04-18 04:30 PM
Re: Need help with EnumProcess
|
Mart
KiX Supporter
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
There is a ping UDF in the UDF forum. Sending a ping would be the way to go IMHO.
[edit] Shwan is fast today [/edit]
Edited by R2D2 (2005-04-18 04:31 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 496 anonymous users online.
|
|
|