Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close application whose process is just a command window 1

Status
Not open for further replies.

RoMa68

Technical User
Feb 7, 2006
27
DE
I need to check if an application is running on a remote computer. This application is running in a command window (process.name = cmd.exe). There are more than one cmd.exe running so only the application name is the key!

How can i do this?
 
You can usually get the command line that was executed to create the cmd.exe process through WMI.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
..that's what I'm looking for! I want to get the application which runs this cmd.exe..

Maybe you got an example...

Thanks in advance RoMa68
 
This is a very generic example but it should point you in the right direction:

Option Explicit

WScript.Echo ListAllProps(".", "WIN32_Process")

Function ListAllProps(strComputer, strClass)
Dim oWMISvc
Dim colInstances
Dim oInstance
Dim oProp
Dim strVal
Dim strReturn

Set oWMISvc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstances = oWMISvc.ExecQuery("Select * from " & strClass,,48)
For Each oInstance in colInstances
For Each oProp In oInstance.Properties_
If IsNull(oProp.Value) Then
strVal = "NULL"
Elseif oProp.IsArray Then
strVal = "ARRAY: " & Join(oProp.Value, ";")
Else
strVal = oProp.Value
End If
strReturn = strReturn & oProp.Name & ": " & strVal & VbCrLf
Next
strReturn = strReturn & "**************************************" & VbCrLf & VbCrLf
Next
ListAllProps = strReturn
End Function


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
...don't kick me out of this thread - maybe it's just the quality of my description:

open two 'command-windows' and give them different names (e.g. title window1 and title window2)

If you have a look at the task manager the 'application panel' shows the two applications 'window1' and 'window2' - on the 'process-panel' there are just two processes named 'cmd.exe'

these two applications do NOT run locally, the are running on a server. My job is to get a notification if application 'window1' is not running!

on my local machine this is very easy done by

-------------------------------------------
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "notepad"
-------------------------------------------

any idea?
 
hi, if you want to look into what has happened (i.e. you have let control go) then TTKP has provided you with the place to start you look.
the Win32_Process class properties will lead you down an investigation path.
have you run TTKP's code? do any of the properties give you what you want? i dont think you have answered this...
will .Description, .ExecuteablePath not help? or you might find you have to look further...i.e. a Win32_Process class property will reference another WMI Class which will hold the info you want,,,see the thread about the use of USB class and PnP classes for USB printer manips...

if you have not let go of the control then you will be able to attack it differently. if your script starts the actual threads then will be able to get a .ProcessID if you start the thread with Win32_Proccess.Create for instance(or such like, this will be unique and not rely on a text reference to window names etc' number which you can reference and check against
 
Hi all,

I tried all of your hints (some of them before you all gave them) - I'm 'going round in circles' at the moment.

I can't find the missing link between the 'appactivate' which is availlable within this shell and doing the things i need (but only on my local machine) and the processes i can see on a remote machine. See my example (dated: 17 Feb 06 5:26) which shows the problem.

@mrmovie: my script is not starting this process (but maybe it is an idea to start this process with a defined process.id - how can i do this?)

RoMa68
 
[1] If the process is on the remote, what would appactivate enter the picture? It would be useless.

[2] As noted, you can even get command line from the properties exposed through win32_process for finer distinction among processes with command prompt. After you make the identification, closing the application is done by the method of the process instance itself. But the command line property is avail only for winxp up (not even avail to win2k).
 
..seems nobody knows an answer?

How do you check if an application is running on a remote machine? This application is a service running in a command window. I can see that four 'cmd.exe' are running on this remote machine, but which one belongs to the application I need to keep running?

Thanks RoMa68
 
..seems nobody knows an answer?

How do you check if an application is running on a remote machine? This application is a service running in a command window. I can see that four 'cmd.exe' are running on this remote machine, but which one belongs to the application I need to keep running?

Or - how can I assign a process id to a process on starting the process? If this is possible I would know the process id I have to check for!

Thanks RoMa68
 
you say you can see 4 cmd.exe processes running on the machine...as described by users posts....check the .CommandLine property of each cmd.exe process....

i think the solution has already been given to you
 
...the CommandLine property is not supported :eek:(!
 
.ExecutablePath or .Caption...are they any good to you??
 
look the result:

Proc >>PID >>ExecutablePath >>Caption
...
CMD.EXE>>2420>>C:\WINNT\system32\cmd.exe>>CMD.EXE
CMD.EXE>>2504>>C:\WINNT\system32\cmd.exe>>CMD.EXE
CMD.EXE>>1720>>C:\WINNT\system32\cmd.exe>>CMD.EXE
CMD.EXE>>2904>>C:\WINNT\system32\cmd.exe>>CMD.EXE
...
 
...after reading many posts i think the problem is that Win2000 does not support the same informtation as WinXP :eek:)

I think VBscript cannot give me the needed information - but maybe you guys habe another idea!

Thanks MR
 
What kind of control do you have over the service? You can copy CMD.EXE somewhere and rename it to MYAPP.EXE. It is then easily identifiable. We do this for wscript.exe when we have multiple scripts running at once on the same box so we can tell them apart.
 
try this one:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'cmd.exe'")

For Each objProcess in colProcessList
objProcess.Terminate()
next
 
Hi all,

@Jerz:
technically this would be possible - but all machines are qualified and this would be a change within the operating system which is not allowed.

@jessicatechy:
this works but I don't want to close alle cmd-processes, I need to check if a special process is running (sorry the header of the thread does not exactly describe my problem).

What I need is the link between application and process in a remote session from a WinXP-Client to a Win2000-Server...

MR
 
Then it sounds like you need to paint a wall red but all you have is blue paint.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top