Broxoth
(Getting the hang of it)
2005-04-13 05:30 PM
Need help with EnumProcess

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.


Radimus
(KiX Supporter)
2005-04-13 05:54 PM
Re: Need help with EnumProcess

$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


Broxoth
(Getting the hang of it)
2005-04-13 06:13 PM
Re: Need help with EnumProcess

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?


Radimus
(KiX Supporter)
2005-04-13 06:15 PM
Re: Need help with EnumProcess

1) that is the "? $computer" statement

2) anywhere before the "for each" statement


Broxoth
(Getting the hang of it)
2005-04-13 06:46 PM
Re: Need help with EnumProcess

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?


Radimus
(KiX Supporter)
2005-04-13 07:57 PM
Re: Need help with EnumProcess

yes, you need admin on the remote PCs

$arraycomputers='computer1','computer2','computer3'

for each (element of array) in (array of elements)


Broxoth
(Getting the hang of it)
2005-04-13 08:57 PM
Re: Need help with EnumProcess

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.


Howard Bullock
(KiX Supporter)
2005-04-13 09:45 PM
Re: Need help with EnumProcess

You seem to be missing a "NEXT" to close your loop.

Broxoth
(Getting the hang of it)
2005-04-13 09:57 PM
Re: Need help with EnumProcess

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?


Radimus
(KiX Supporter)
2005-04-13 10:09 PM
Re: Need help with EnumProcess

$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


Broxoth
(Getting the hang of it)
2005-04-13 10:25 PM
Re: Need help with EnumProcess

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.


Broxoth
(Getting the hang of it)
2005-04-14 02:04 AM
Re: Need help with EnumProcess

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!!

Radimus
(KiX Supporter)
2005-04-14 02:56 AM
Re: Need help with EnumProcess

$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


Broxoth
(Getting the hang of it)
2005-04-14 06:43 PM
Re: Need help with EnumProcess

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...

Radimus
(KiX Supporter)
2005-04-14 07:19 PM
Re: Need help with EnumProcess

change
? $computer
into
$=sendmessage(@wksta,$computer +' is running '+ $proc)


Broxoth
(Getting the hang of it)
2005-04-15 12:03 AM
Re: Need help with EnumProcess

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.


Broxoth
(Getting the hang of it)
2005-04-18 04:19 PM
Re: Need help with EnumProcess

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!

ShawnAdministrator
(KiX Supporter)
2005-04-18 04:21 PM
Re: Need help with EnumProcess

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


Mart
(KiX Supporter)
2005-04-18 04:30 PM
Re: Need help with EnumProcess

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]


Les
(KiX Master)
2005-04-18 05:30 PM
Re: Need help with EnumProcess

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



Broxoth
(Getting the hang of it)
2005-04-18 08:26 PM
Re: Need help with EnumProcess

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.

Les
(KiX Master)
2005-04-18 08:53 PM
Re: Need help with EnumProcess

Ja, a simple IF Ping($PC) inside your FOR loop.

Broxoth
(Getting the hang of it)
2005-04-18 09:07 PM
Re: Need help with EnumProcess

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!!


NTDOCAdministrator
(KiX Master)
2005-04-18 09:50 PM
Re: Need help with EnumProcess

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.


Broxoth
(Getting the hang of it)
2005-04-18 09:51 PM
Re: Need help with EnumProcess

I am using the ping UDF.

Les
(KiX Master)
2005-04-18 10:07 PM
Re: Need help with EnumProcess

Obviously then, not my Ping() UDF I posted in this thread since it takes only one parm.

Broxoth
(Getting the hang of it)
2005-04-18 10:10 PM
Re: Need help with EnumProcess

Nope. Sorry, I'll try that now.

NTDOCAdministrator
(KiX Master)
2005-04-18 10:21 PM
Re: Need help with EnumProcess

Les,

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

That name is being supplied as a parameter.


NTDOCAdministrator
(KiX Master)
2005-04-18 10:24 PM
Re: Need help with EnumProcess

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



Broxoth
(Getting the hang of it)
2005-04-18 10:48 PM
Re: Need help with EnumProcess

Sorry...not following that last one. Could you explain it a bit?

NTDOCAdministrator
(KiX Master)
2005-04-18 11:21 PM
Re: Need help with EnumProcess

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



Broxoth
(Getting the hang of it)
2005-04-18 11:46 PM
Re: Need help with EnumProcess

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?

NTDOCAdministrator
(KiX Master)
2005-04-18 11:57 PM
Re: Need help with EnumProcess

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


Broxoth
(Getting the hang of it)
2005-04-19 12:07 AM
Re: Need help with EnumProcess

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.


NTDOCAdministrator
(KiX Master)
2005-04-19 12:26 AM
Re: Need help with EnumProcess

Please supply the real values for this just so I'm sure we're talking about the same things.

$processes='processes'


Broxoth
(Getting the hang of it)
2005-04-19 01:11 AM
Re: Need help with EnumProcess

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.


NTDOCAdministrator
(KiX Master)
2005-04-19 02:05 AM
Re: Need help with EnumProcess

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



Broxoth
(Getting the hang of it)
2005-04-19 04:10 PM
Re: Need help with EnumProcess

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.


maciep
(Korg Regular)
2005-04-19 04:23 PM
Re: Need help with EnumProcess

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''


Broxoth
(Getting the hang of it)
2005-04-19 05:36 PM
Re: Need help with EnumProcess

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?


NTDOCAdministrator
(KiX Master)
2005-04-19 07:06 PM
Re: Need help with EnumProcess

It appears that WMI is not functioning correctly on a couple of the systems. I would look at testing them individually and repairing WMI if needed.

I'm not sure what you're trying to accomplish by sending a NET SEND to the computer for. What would that mean to the user? Most users would either ignore it, or call the Helpdesk to complain about some message that keeps showing up on their computer.


Broxoth
(Getting the hang of it)
2005-04-19 08:38 PM
Re: Need help with EnumProcess

Two things.
1) Once tested and I know where the WMI problem lies, how would I go about repairing it? I'd be more than happy to read up on doing such if someone could tell me where to find that info.
2) The whole idea behind the NET SEND was discussed earlier in the thread. The original code had a line:
Code:
$=SendMessage(@wksta,$computer +' is running '+ $proc)


I was looking to put together some pseudo-front end to the script that would just put the info I was after into a message box plainly with no more than a couple of lines. As it stands, what I'd like to see, is a messagebox that states that either, Yes, the $computer was pinged and that this $process was found to be running....or, No, this $computer was not pinged, we're moving on to the next $computer.
That's the general idea. Now, as much as I appreciate the enormous amount of help that I've received, (honestly, I have never seen so many people be so generous with their help!) I always intended on putting this thing together myself. Just saying that to make it clear that it's not like I'm expecting anyone else to do my dirty work. Thank you, everyone!


NTDOCAdministrator
(KiX Master)
2005-04-19 08:50 PM
Re: Need help with EnumProcess

Reinstalling WMI
If you experience behavior when using WMI, such as application errors or scripts that used to work are no longer working, you may have a corrupted WMI repository. To fix a corrupted WMI repository, you have to reinstall WMI.

Windows Management Instrumentation - Repair

As for the NET SEND I'm still not sure why you would send that to a user. What purpose does it serve either to you or the user? It is not logged, when the user clicks okay the message is now gone, etc..

We can setup a MessageBox command that would alert YOU as the Administrator about a system if you want which I'm guessing is more of what you're really wanting.


Broxoth
(Getting the hang of it)
2005-04-19 09:25 PM
Re: Need help with EnumProcess

Well, two more things:
1) You were dead on about the WMI. I restarted WMI on two machines that were giving me problems and they're running great now. I didn't need to delete the directories. Thanks a ton for the help there.
2) If you notice that's where the SendMessage went to, @WKSTA and I will only be running this script locally so that should never be a problem. However, I am looking at tweaking on how this script displays. A console window is ok but I'd like a nice front end eventually for this. Thanks yet again!


Kdyer
(KiX Supporter)
2005-04-19 09:51 PM
Re: Need help with EnumProcess

Couple of things to ponder..

Does the following directory exist?
%windir%\system32\wbem

or..
Code:

$check=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$scomputer+'\root\cimv2')
IF @error<>0
?'WMI Appears to be having trouble'
ENDIF



HTH,

Kent


Broxoth
(Getting the hang of it)
2005-04-19 10:07 PM
Re: Need help with EnumProcess

Good thought, kdyer. I'll consider adding that.
Here's the final code with the MessageBox implemented:
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-FRONTDESK','OFF-TSINGERY','OFF-JHUFF','OFF-SGONZALEZ','OFF-HOYT','OFF-SBERGER','OFF-RLOCKWOOD'
$Processes = 'School.exe','SMinder.exe','SMAdmin.exe','SMReport.exe','SMBill.exe','Admission.exe'
For Each $sComputer in $ArrayComputers
If $sComputer
If Ping($sComputer) Goto "EnumDisplay"

:EnumDisplay
For Each $Process in $Processes
If $Process
$List = EnumProcess($Process,,$sComputer)
If $List
MessageBox($sComputer + " was pinged and is running " + $Process + " with a PID of" + $List + ".","SMChecks",0)
EndIf
EndIf
Next
EndIf
EndIf
Next



Kind of nasty with the goto statement but it gets the job done.


NTDOCAdministrator
(KiX Master)
2005-04-19 11:19 PM
Re: Need help with EnumProcess

Well if you really want a GOOD LOOKING GUI then take a look at implementing this with KiXforms written by our very own Admin/Moderator Shawn Tassie.

KiXforms Home Page


Broxoth
(Getting the hang of it)
2005-04-20 12:03 AM
Re: Need help with EnumProcess

I just bought ASE. I thought I saw something about KiXforms when I installed. Maybe it comes with it now.

NTDOCAdministrator
(KiX Master)
2005-04-20 02:24 AM
Re: Need help with EnumProcess

KiXforms is completely FREE to use. Not sure if it was included as part of the ASE install, but I think you're correct that it does install it.

Just need to visit the KiXforms site and start learning how to use it.


ShawnAdministrator
(KiX Supporter)
2005-04-20 03:12 AM
Re: Need help with EnumProcess

Someone say Kixforms ?

Les
(KiX Master)
2005-04-20 04:05 AM
Re: Need help with EnumProcess

You would want ot go with the latest dev build anyway and not the latest gold.

Broxoth
(Getting the hang of it)
2005-04-20 03:44 PM
Re: Need help with EnumProcess

Why's that, Les?

Les
(KiX Master)
2005-04-20 04:05 PM
Re: Need help with EnumProcess

Cuz the latest Gold is buggy but Shawn refused to pull it, and since then he added soo much good stuff since but he can't decide when to cutoff dev and release it as Gold.

Broxoth
(Getting the hang of it)
2005-04-20 11:09 PM
Re: Need help with EnumProcess

OK. I'm working on that front-end as we speak. However, I think I may be in over my head. I'm not a coder by trade (as if it doesn't show) and I'm at a complete loss. I suppose I'll just post on the KiXforms board and try to get some help there. Thanks everyone.

ShawnAdministrator
(KiX Supporter)
2005-04-20 11:18 PM
Re: Need help with EnumProcess

Here, there, doesn't matter - we're all one big happy Kixtart community.

Les
(KiX Master)
2005-04-20 11:38 PM
Re: Need help with EnumProcess

They are a snooty bunch over there... always getting their knickers in a twist. The ones that really matter hang here as well.

Broxoth
(Getting the hang of it)
2005-04-21 12:05 AM
Re: Need help with EnumProcess

Would it be ok then to repost what I posted there, here?

Les
(KiX Master)
2005-04-21 12:15 AM
Re: Need help with EnumProcess

No, I think once you pick your venue, you should stick to it. Some people get annoyed if you cross post between boards.

You could post a link though in this thread to help guide people to your topic there.


Broxoth
(Getting the hang of it)
2005-04-21 12:22 AM
Re: Need help with EnumProcess

As a board moderator elsewhere, I fully understand. Wish I'd asked before I posted. Would've made more sense to keep the conversation rolling on this thread. Oh well, here's the link.

ShawnAdministrator
(KiX Supporter)
2005-04-21 01:45 AM
Re: Need help with EnumProcess

Here is some thoughts ... might want to use the ListBox instead of Textboxes - idk - its your call, here is some code based on Listboxes though ...

Code:

Break On
;SetConsole("hide")

$System = CreateObject("Kixtart.System")

;KD START

$Form = $System.Form()
$Form.BackColor = 224,223,227
$Form.Height = 477
$Form.Left = 209
$Form.MaximizeBox = "False"
$Form.Text = "SM Process Checker"
$Form.Top = 89
$Form.Width = 532
$UI_COMPNAMES = $Form.Controls.ListBox()
$UI_COMPNAMES.Height = 150
$UI_COMPNAMES.Left = 15
$UI_COMPNAMES.Text = ""
$UI_COMPNAMES.Top = 45
$UI_COMPNAMES.Width = 150
$UI_COMPNAMES.Sorted = 1

$COMPNAME_LABEL = $Form.Controls.Label()
$COMPNAME_LABEL.BackColor = 224,223,227
$COMPNAME_LABEL.FontBold = "True"
$COMPNAME_LABEL.FontUnderline = "True"
$COMPNAME_LABEL.Height = 20
$COMPNAME_LABEL.Left = 15
$COMPNAME_LABEL.Text = "Computer Name(s)"
$COMPNAME_LABEL.Top = 30
$COMPNAME_LABEL.Width = 114

$PROCGROUP = $Form.Controls.GroupBox()
$PROCGROUP.BackColor = 224,223,227
$PROCGROUP.Height = 141
$PROCGROUP.Left = 15
$PROCGROUP.Text = "Processes to Search For:"
$PROCGROUP.Top = 202
$PROCGROUP.Width = 268

$UI_SCHOOL = $PROCGROUP.Controls.CheckBox()
$UI_SCHOOL.BackColor = 224,223,227
$UI_SCHOOL.CheckAlign = 16
$UI_SCHOOL.Height = 24
$UI_SCHOOL.Left = 15
$UI_SCHOOL.Text = "School.exe"
$UI_SCHOOL.Top = 15
$UI_SCHOOL.Width = 104

$UI_SMINDER = $PROCGROUP.Controls.CheckBox()
$UI_SMINDER.BackColor = 224,223,227
$UI_SMINDER.CheckAlign = 16
$UI_SMINDER.Height = 24
$UI_SMINDER.Left = 15
$UI_SMINDER.Text = "SMinder.exe"
$UI_SMINDER.Top = 45
$UI_SMINDER.Width = 104

$UI_SMADMIN = $PROCGROUP.Controls.CheckBox()
$UI_SMADMIN.BackColor = 224,223,227
$UI_SMADMIN.CheckAlign = 16
$UI_SMADMIN.Height = 24
$UI_SMADMIN.Left = 15
$UI_SMADMIN.Text = "SMAdmin.exe"
$UI_SMADMIN.Top = 75
$UI_SMADMIN.Width = 104

$UI_SMREPORT = $PROCGROUP.Controls.CheckBox()
$UI_SMREPORT.BackColor = 224,223,227
$UI_SMREPORT.CheckAlign = 16
$UI_SMREPORT.Height = 24
$UI_SMREPORT.Left = 135
$UI_SMREPORT.Text = "SMReport.exe"
$UI_SMREPORT.Top = 15
$UI_SMREPORT.Width = 104

$UI_SMBILL = $PROCGROUP.Controls.CheckBox()
$UI_SMBILL.BackColor = 224,223,227
$UI_SMBILL.CheckAlign = 16
$UI_SMBILL.Height = 24
$UI_SMBILL.Left = 135
$UI_SMBILL.Text = "SMBill.exe"
$UI_SMBILL.Top = 45
$UI_SMBILL.Width = 104

$UI_ADMISSION = $PROCGROUP.Controls.CheckBox()
$UI_ADMISSION.BackColor = 224,223,227
$UI_ADMISSION.CheckAlign = 16
$UI_ADMISSION.Height = 24
$UI_ADMISSION.Left = 135
$UI_ADMISSION.Text = "Admission.exe"
$UI_ADMISSION.Top = 75
$UI_ADMISSION.Width = 104

$UI_ALLPROCS = $PROCGROUP.Controls.CheckBox()
$UI_ALLPROCS.BackColor = 224,223,227
$UI_ALLPROCS.CheckAlign = 16
$UI_ALLPROCS.FontItalic = "True"
$UI_ALLPROCS.Height = 21
$UI_ALLPROCS.Left = 75
$UI_ALLPROCS.Text = "Search for ALL"
$UI_ALLPROCS.Top = 105
$UI_ALLPROCS.Width = 105

$COMPLIST_LABEL = $Form.Controls.Label()
$COMPLIST_LABEL.BackColor = 224,223,227
$COMPLIST_LABEL.FontBold = "True"
$COMPLIST_LABEL.FontUnderline = "True"
$COMPLIST_LABEL.Height = 17
$COMPLIST_LABEL.Left = 270
$COMPLIST_LABEL.Text = "Search these computers:"
$COMPLIST_LABEL.Top = 30
$COMPLIST_LABEL.Width = 144

$UI_MOVETOLIST = $Form.Controls.Button()
$UI_MOVETOLIST.FontBold = "True"
$UI_MOVETOLIST.Height = 28
$UI_MOVETOLIST.Left = 205
$UI_MOVETOLIST.Text = ">>"
$UI_MOVETOLIST.Top = 60
$UI_MOVETOLIST.Width = 30
$UI_MOVETOLIST.OnClick = "MoveToListClick()"

$UI_MOVEFROMLIST = $Form.Controls.Button()
$UI_MOVEFROMLIST.FontBold = "True"
$UI_MOVEFROMLIST.Height = 28
$UI_MOVEFROMLIST.Left = 205
$UI_MOVEFROMLIST.Text = "<<"
$UI_MOVEFROMLIST.Top = 120
$UI_MOVEFROMLIST.Width = 30
$UI_MOVEFROMLIST.OnClick = "MoveFromListClick()"

$UI_SEARCHBUTTON = $Form.Controls.Button()
$UI_SEARCHBUTTON.FontBold = "True"
$UI_SEARCHBUTTON.Height = 23
$UI_SEARCHBUTTON.Left = 315
$UI_SEARCHBUTTON.Text = "Search"
$UI_SEARCHBUTTON.Top = 210
$UI_SEARCHBUTTON.Width = 75

$UI_CLEARLISTBUTTON = $Form.Controls.Button()
$UI_CLEARLISTBUTTON.Height = 23
$UI_CLEARLISTBUTTON.Left = 180
$UI_CLEARLISTBUTTON.Text = "Clear list"
$UI_CLEARLISTBUTTON.Top = 165
$UI_CLEARLISTBUTTON.Width = 75
$UI_CLEARLISTBUTTON.OnClick = "ClearListClick()"

$UI_CLEARALLBUTTON = $Form.Controls.Button()
$UI_CLEARALLBUTTON.Height = 23
$UI_CLEARALLBUTTON.Left = 315
$UI_CLEARALLBUTTON.Text = "Clear ALL"
$UI_CLEARALLBUTTON.Top = 255
$UI_CLEARALLBUTTON.Width = 75

$UI_CLOSEBUTTON = $Form.Controls.Button()
$UI_CLOSEBUTTON.Height = 23
$UI_CLOSEBUTTON.Left = 315
$UI_CLOSEBUTTON.Text = "Close"
$UI_CLOSEBUTTON.Top = 300
$UI_CLOSEBUTTON.Width = 75

$UI_COMPLIST = $Form.Controls.ListBox()
$UI_COMPLIST.Height = 150
$UI_COMPLIST.Left = 270
$UI_COMPLIST.ReadOnly = "True"
$UI_COMPLIST.Top = 45
$UI_COMPLIST.Width = 150
$UI_COMPLIST.Sorted = 1

;KD END

For $i = 0 To 100
$UI_COMPNAMES.AddItem("HOST#$i")
Next

$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1

Function MoveToListClick()

If $UI_COMPNAMES.ListIndex <> -1
$UI_COMPLIST.AddItem($UI_COMPNAMES.Text)
$UI_COMPNAMES.RemoveItem($UI_COMPNAMES.ListIndex)
Endif

EndFunction

Function MoveFromListClick()

If $UI_COMPLIST.ListIndex <> -1
$UI_COMPNAMES.AddItem($UI_COMPLIST.Text)
$UI_COMPLIST.RemoveItem($UI_COMPLIST.ListIndex)
Endif

EndFunction

Function ClearListClick()

$UI_COMPLIST.Clear

EndFunction



Broxoth
(Getting the hang of it)
2005-04-21 07:04 PM
Re: Need help with EnumProcess

The only problem is that what I need to be able to do here is allow the user to enter any computer name in $UI_COMPNAMES and then move them to $UI_COMPLIST to be used in the same old script. I also need them to be able to choose from any of the processes or all of them. Here's link to explain what I'm working on.
Just as a side question, on a scale of 1 to 10, how complicated do you think this script will have to be?


NTDOCAdministrator
(KiX Master)
2005-04-21 07:37 PM
Re: Need help with EnumProcess

What do you want to do with the process or with the computer if you do find it running a given process?

Broxoth
(Getting the hang of it)
2005-04-21 07:46 PM
Re: Need help with EnumProcess

Here's the end goals that I've been given: The option to Kill process, Send message to computer running process to close the program, or just inform @wksta which procs are running where.
Sorry, am I not being clear enough?


NTDOCAdministrator
(KiX Master)
2005-04-21 09:14 PM
Re: Need help with EnumProcess

Okay that should be enough information.

If you don't get it figured out, or if no one else steps in, I'll try to take a look at it within the next couple of days and see if I can help you get it completed.


ShawnAdministrator
(KiX Supporter)
2005-04-21 09:56 PM
Re: Need help with EnumProcess

Me want to help too, me want to help to.

Just have a question though - not really understanding the requirement to be able to type-in server names (multiple names) into a multiline textbox, then move the individually selected ones into a listbox. Not really following the "why" of this. Wouldn't you want to user to just simply type in a hostname, then move it into the listbox - and if they didn't want it in the listbox, they wouldn't type it anyways ?

-Shawn


Broxoth
(Getting the hang of it)
2005-04-21 10:01 PM
Re: Need help with EnumProcess

Thanks! I'll post what I have so far by tomorrow morning.

Broxoth
(Getting the hang of it)
2005-04-22 04:52 PM
Re: Need help with EnumProcess

Shawn, you make a good point. I can see how that would be....stupid. I guess what I'm thinking is coming up with a way that once a user entered a computer name then that can be saved somehow (.ini file?) for future use. But something just struck me. I'll just have a "Search for computers" button. That'll be easier than having someone type a computer name in. Granted, I won't have it search the entire subnet for computers running these procs. I'll just have it list available computers. Since this is an admin thing anyway, odds are that whoever uses this will know which computers might be running these processes. Whadd'ya think?

Les
(KiX Master)
2005-04-22 05:51 PM
Re: Need help with EnumProcess

How many computers you talking about?
Are they all well connected?
Are they all in one site or OU?

You could query ADODB with the LDAP path and then simply check all of them for the running process and return them in the list. I do queries like that all the time.


Broxoth
(Getting the hang of it)
2005-04-22 07:35 PM
Re: Need help with EnumProcess

Well, I would like to leave this open-ended when it comes to amount of computers but I'll limit it in regards to either a subnet or a single domain. (A domain would probably suffice in most circumstances.)

Radimus
(KiX Supporter)
2005-04-22 08:11 PM
Re: Need help with EnumProcess

do a search for McAfeeManager2 or Remote Execution Manager

find my code and pick it apart :-)


Broxoth
(Getting the hang of it)
2005-04-23 01:35 AM
Re: Need help with EnumProcess

Radimus: I'm looking through it now...

On a side note, if in the future, once I'm the demi-KiX-god-gurus that y'all are, what, if any, are the restrictions to selling KiX code to a company? Do you guys know? [That's way off topic and I shall take the ensuing flogging for such an action. ]


NTDOCAdministrator
(KiX Master)
2005-04-23 02:00 AM
Re: Need help with EnumProcess

Well one would more so be selling their services not the actual code which would be difficult at best to copyright.

If you sold someone a solution for $5,000 or $10,000 and it included KiXtart coding, well to me you're selling your knowledge of putting that code together to complete the task, not the actual code.


Broxoth
(Getting the hang of it)
2005-04-23 02:20 AM
Re: Need help with EnumProcess

Yeah, that's what I kept running into about the whole selling the code thing. How can you say that no one else could use already commonly used code?
But as a solution to a problem, as in like a new module to an already existing software, I would see that as a feasible thing. I just wanted to make sure there were no GNU-ish restrictions. I'm obviously a very long way from being able to do something remotely like that. Just thought I'd ask...thanks. Back to the task at hand...


Broxoth
(Getting the hang of it)
2005-04-25 05:17 PM
Re: Need help with EnumProcess

OK, I think I'm making some progress towards my goals but I'm stuck again...how would you query for computer names if the network in question does not have a LDAP server or AD?

NTDOCAdministrator
(KiX Master)
2005-04-25 08:02 PM
Re: Need help with EnumProcess

From a DOS console

NET VIEW >SYSTEMS.TXT

Then place the correct syntax into KiX code to do similar.


Les
(KiX Master)
2005-04-25 08:29 PM
Re: Need help with EnumProcess

or use one of the UDFs

Broxoth
(Getting the hang of it)
2005-04-25 08:44 PM
Re: Need help with EnumProcess

Duh! Thanks. So based on that I could have it do a query where it checks to see if a LDAP server is available and if one is not available it can search using the other NET VIEW/UDF method? Did that question make sense?

NTDOCAdministrator
(KiX Master)
2005-04-25 08:59 PM
Re: Need help with EnumProcess

Yes you can do either or both methods if required.

Broxoth
(Getting the hang of it)
2005-04-27 08:05 PM
Re: Need help with EnumProcess

Ok, after a couple of days of playing with this I'm about halfway there. I'm using the NetView2 UDF but I can't figure out how I get the results to display in my ListBox so users can choose which computer(s) they want to search for the running processes. I searched the board and came up with no hints on how to do this. If you know of a previous post that would point me in the right direction please let me know.