Page 1 of 4 1234>
Topic Options
#137850 - 2005-04-13 05:30 PM Need help with EnumProcess
Broxoth Offline
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137852 - 2005-04-13 06:13 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
2 things:
1) So this will, in fact, display the results?
2) The syntax of this seems to be going over my head. Where should I be placing that $arraycomputers string?

Top
#137853 - 2005-04-13 06:15 PM Re: Need help with EnumProcess
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
1) that is the "? $computer" statement

2) anywhere before the "for each" statement
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137854 - 2005-04-13 06:46 PM Re: Need help with EnumProcess
Broxoth Offline
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 Offline
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)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137856 - 2005-04-13 08:57 PM Re: Need help with EnumProcess
Broxoth Offline
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 Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You seem to be missing a "NEXT" to close your loop.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#137858 - 2005-04-13 09:57 PM Re: Need help with EnumProcess
Broxoth Offline
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137860 - 2005-04-13 10:25 PM Re: Need help with EnumProcess
Broxoth Offline
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
#137861 - 2005-04-14 02:04 AM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
I think I figured out my problem. The particular program runs under different processes depending upon the module used. I didn't realize that. Therefore, could I just use OR statements for as many processes as I need? (BTW, if so it doesn't work. Shocker...) Thanks!!
Top
#137862 - 2005-04-14 02:56 AM Re: Need help with EnumProcess
Radimus Moderator Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137863 - 2005-04-14 06:43 PM Re: Need help with EnumProcess
Broxoth Offline
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 Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
change
? $computer
into
$=sendmessage(@wksta,$computer +' is running '+ $proc)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137865 - 2005-04-15 12:03 AM Re: Need help with EnumProcess
Broxoth Offline
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
#137866 - 2005-04-18 04:19 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Ok, I think after a few days of "beta" testing this in a production environment there is a hang up. The script works great only if the particular $computer's are reachable, hence, on. If it is not on then the script seems to hang or just takes an inordinate amount of time to complete. Unfortunately, I run this script manually at the end of the day and need it to be as quick as possible. I realize, just by the nature of what this script is doing, it can take some time. However, it simply takes too long. Would running a ping script to check that "the system is down, yo" be a good option or would there be a better way of doing it? Thanks again!
Top
#137867 - 2005-04-18 04:21 PM Re: Need help with EnumProcess
Shawn Administrator Offline
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 Moderator Offline
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
#137869 - 2005-04-18 05:30 PM Re: Need help with EnumProcess
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't even bother to pipe to find.
Code:

Function Ping($PC)
Dim $PC
Shell'%comspec% /c ping -n 1 '+$PC+' >nul'
$Ping = NOT @error
EndFunction

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 4 1234>


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

Who's Online
1 registered (mole) and 405 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.076 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

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