#137870 - 2005-04-18 08:26 PM
Re: Need help with EnumProcess
|
Broxoth
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
|
|
|
|
#137872 - 2005-04-18 09:07 PM
Re: Need help with EnumProcess
|
Broxoth
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
|
|
|
|
#137878 - 2005-04-18 10:24 PM
Re: Need help with EnumProcess
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
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
|
|
|
|
#137880 - 2005-04-18 11:21 PM
Re: Need help with EnumProcess
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
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
|
|
|
|
#137882 - 2005-04-18 11:57 PM
Re: Need help with EnumProcess
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
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
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
|
|
|
|
#137885 - 2005-04-19 01:11 AM
Re: Need help with EnumProcess
|
Broxoth
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
Registered: 2000-07-28
Posts: 11624
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
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
|
|
|
|
#137889 - 2005-04-19 05:36 PM
Re: Need help with EnumProcess
|
Broxoth
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 761 anonymous users online.
|
|
|