Page 2 of 4 <1234>
Topic Options
#137870 - 2005-04-18 08:26 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Okay, good to hear that I'm heading down the right track. Only thing is, since I am using an array of computers how would I set it up to ping each individually and then based on result go on to the next $comp in the array? Would I use a "For Each" statement? Just kinda lost within my growing list of If/Else statements that are in my current test script.
Top
#137871 - 2005-04-18 08:53 PM Re: Need help with EnumProcess
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ja, a simple IF Ping($PC) inside your FOR loop.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137872 - 2005-04-18 09:07 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Good! Does this look right?
Code:
$arraycomputers='@wksta','other computers'
$processes='long list of procs'
For Each $computer in $ArrayComputers
For Each $proc in $processes
If Ping($Computer,0,1)
EnumProcess($proc, , $Computer)
$=SendMessage(@wksta,$computer +' is running '+ $proc)

Else

$=SendMessage(@WKSTA,$computer +' was not able to be pinged. It is unavailable.')
EndIf
Next
Next
Exit


^After running, there's definitely something hosed with this code!!


Edited by Brockett (2005-04-18 09:11 PM)

Top
#137873 - 2005-04-18 09:50 PM Re: Need help with EnumProcess
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
This is not correct

If Ping($Computer,0,1)

You would need to either have a UDF named PING or create one that gave you those results to check against.

Top
#137874 - 2005-04-18 09:51 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
I am using the ping UDF.
Top
#137875 - 2005-04-18 10:07 PM Re: Need help with EnumProcess
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Obviously then, not my Ping() UDF I posted in this thread since it takes only one parm.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137876 - 2005-04-18 10:10 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Nope. Sorry, I'll try that now.
Top
#137877 - 2005-04-18 10:21 PM Re: Need help with EnumProcess
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Les,

Need to remove this line in the UDF example
Dim $PC

That name is being supplied as a parameter.

Top
#137878 - 2005-04-18 10:24 PM Re: Need help with EnumProcess
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Code:
Dim $Status
$Status = Ping('some_computer')
If $Status
; pc appears to be online
; run other code
EndIf
 
Function Ping($PC)
Shell'%comspec% /c ping -n 1 '+$PC+' >nul'
$Ping = NOT @error
EndFunction


Top
#137879 - 2005-04-18 10:48 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Sorry...not following that last one. Could you explain it a bit?
Top
#137880 - 2005-04-18 11:21 PM Re: Need help with EnumProcess
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Here, not tested at all, but put together the code you have already how I think it should run. Quite possible something is not correct and I don't have the enum UDF listed here either which you will need in your script or a call to it.

Code:
$ArrayComputers=@wksta,'other computers'
$Processes='long list of procs'
For Each $Computer in $ArrayComputers
If Ping($Computer)
For Each $proc in $processes
EnumProcess($proc, , $Computer)
$=SendMessage(@wksta,$computer +' is running '+ $proc)
Next
Else
$=SendMessage(@WKSTA,$computer +' was not able to be pinged. It is unavailable.')
EndIf
Next
Exit 1
 
Function Ping($PC)
Shell'%comspec% /c ping -n 1 '+$PC+' >nul'
$Ping = NOT @error
EndFunction


Top
#137881 - 2005-04-18 11:46 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Unfortunately, it seems that it sends the "$computer +' is running '+ $proc" message regardless of whether the proc is actually running or not. Instead it sends it if it gets a ping from that $computer. It informed me that each computer that it pinged was running every one of the processes listed and that is an impossibility. These procs can't run simultaneously. Any thoughts?
Top
#137882 - 2005-04-18 11:57 PM Re: Need help with EnumProcess
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Yes, please post your actual code you are currently using and I'll review and test it for you.

Using quasi coding apparently is not working for you

Top
#137883 - 2005-04-19 12:07 AM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Haha...here it is:
Code:
$arraycomputers='computers'
$processes='processes'
For Each $computer in $ArrayComputers
If Ping($Computer)
For Each $proc in $processes
EnumProcess($proc, , $Computer)
$=SendMessage(@wksta,$computer +' is running '+ $proc)
Next
Else
$=SendMessage(@WKSTA,$computer +' was not able to be pinged. It is unavailable.')
EndIf
Next
Exit 1


I did not include the UDF's in this but I assure you they are there.

Top
#137884 - 2005-04-19 12:26 AM Re: Need help with EnumProcess
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Please supply the real values for this just so I'm sure we're talking about the same things.

$processes='processes'

Top
#137885 - 2005-04-19 01:11 AM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Sure:
Code:
$arraycomputers='@wksta','OFF-JHUFF','OFF-RLOCKWOOD','OFF-SGONZALEZ','OFF-HOYT','OFF-SBERGER','OFF-TSINGERY','OFF-FRONTDESK'
$processes='School.exe','SMinder.exe','SMAdmin.exe','SMReport.exe','SMBill.exe','Admission.exe'
For Each $computer in $ArrayComputers
If Ping($Computer)
For Each $proc in $processes
EnumProcess($proc, , $Computer)
$=SendMessage(@wksta,$computer +' is running '+ $proc)
Next
Else
$=SendMessage(@WKSTA,$computer +' was not able to be pinged. It is unavailable.')
EndIf
Next
Exit 1


Just so as we're clear, the script works great with the exception of when the ping function is added. So I'm sure that the string values are working correctly.

Top
#137886 - 2005-04-19 02:05 AM Re: Need help with EnumProcess
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Okay, here is script that should be run from the DOS console which should allow you to see what is returned. Then depending on what you see or get returned you can decide if you want to place that into a NET SEND message or not. The EnumProcess UDF shown here is a modified version to fully support the NoVarInStrings option.
 
Code:
Break On
Dim $SO,$Pause
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')
 
Dim $ArrayComputers, $sComputer, $Process, $Processes, $List, $Item
$ArrayComputers = 'OFF-JHUFF','OFF-RLOCKWOOD','OFF-SGONZALEZ','OFF-HOYT','OFF-SBERGER','OFF-TSINGERY','OFF-FRONTDESK'
$Processes = 'School.exe','SMinder.exe','SMAdmin.exe','SMReport.exe','SMBill.exe','Admission.exe''
For Each $sComputer In $ArrayComputers
If $sComputer
If Ping($sComputer)
? 'The computer ' + $sComputer + ' responds to ping'
For Each $Process In $Processes
If $Process
$List = EnumProcess($Process,,$sComputer)
If $List
? $sComputer + ' is running ' + $Process + ' with a PID of: ' + $List
EndIf
EndIf
Next
EndIf
EndIf
Next
 
Function Ping($PC)
Shell'%comspec% /c ping -n 1 '+$PC+' >nul'
$Ping = NOT @error
EndFunction
 
Function EnumProcess($Exe, optional $Terminate, optional $sComputer)
Dim $Winmgmts, $ExecQuery, $GetObject, $Process, $Id, $Msg, $T,$Index
If Not $Exe Exit 1 EndIf
If Not $sComputer $sComputer=@WKSTA EndIf
If InStr($sComputer,'\') $sComputer = Join(Split($sComputer, '\'),'',3) EndIf
$Winmgmts="winmgmts:{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2"
Select
Case VarType($Exe) = 3
$ExecQuery="Select * from Win32_Process Where ProcessID = " +"'"+$Exe+"'"
$GetObject=GetObject($Winmgmts).ExecQuery($ExecQuery)
For Each $Process In $GetObject
If $Terminate $T=$Process.Terminate
$EnumProcess=@ERROR
Else
$EnumProcess=$Process.Name
EndIf
Next
Case VarType($Exe)=8
$Index=0
$ExecQuery="Select * from Win32_Process Where Name = " +"'"+$Exe+"'"
$GetObject=GetObject($Winmgmts).ExecQuery($ExecQuery)
For Each $Process In $GetObject
If $Terminate $T=$Process.Terminate
$EnumProcess=@ERROR
Else
$Id=$Process.ProcessId
If $Id $Index=$Index+1 EndIf
If $Index>1
$EnumProcess=""+$EnumProcess+"|"+$Id
Else
$EnumProcess=$Id
EndIf
EndIf
Next
Case 1
Exit 1
EndSelect
EndFunction


Top
#137887 - 2005-04-19 04:10 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
OMG!!! Thanks for doing all of that. I appreciate all the work. Since I am completely green when it comes to scripting I don't understand that first section (Break On, etc.), but I am doing my best.
This is what is returned:
Code:
ERROR : unknown command [The]!
Script: X:\Software Installs\SMChecks\SMinderwithpingtest.kix
Line : 84


This is line 84 in the script since I prefer UDF's at the top:
Code:
?'The computer ' + $sComputer + ' responds to ping'



(Not surprisingly...)I am at a loss for why it would be giving that error.

Top
#137888 - 2005-04-19 04:23 PM Re: Need help with EnumProcess
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
There's an extra quote (') at the end of this line, just remove it and the error should go away.

$Processes = 'School.exe','SMinder.exe','SMAdmin.exe','SMReport.exe','SMBill.exe','Admission.exe''

Top
#137889 - 2005-04-19 05:36 PM Re: Need help with EnumProcess
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Bah! I must be blind!
{EDIT}
Alrighty, here's the output from the script, as is:
Code:

The computer OFF-SGONZALEZ responds to ping
OFF-SGONZALEZ is running SMBill.exe with a PID of: 2880
The computer OFF-SBERGER responds to pingSelect * from Win32_Process Where Name
= 'School.exe'Select * from Win32_Process Where Name = 'SMinder.exe'Select * fro
m Win32_Process Where Name = 'SMAdmin.exe'Select * from Win32_Process Where Name
= 'SMReport.exe'Select * from Win32_Process Where Name = 'SMBill.exe'Select * f
rom Win32_Process Where Name = 'Admission.exe'
The computer OFF-TSINGERY responds to ping
The computer OFF-FRONTDESK responds to ping
OFF-FRONTDESK is running School.exe with a PID of: 872


Soooooo, more or less, we're getting there. It may be that a great deal of the left out info would be displayed if I added some NET SEND messages. What do you guys think?

Top
Page 2 of 4 <1234>


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
2 registered (Allen, ShaneEP) and 158 anonymous users online.
Newest Members
Sjaak, Biybucket, Markus1961, Ian231, kixnewbie12
17480 Registered Users

Generated in 0.046 seconds in which 0.014 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