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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When can you not terminate a running task via VBS?

Status
Not open for further replies.

cmwoodman

IS-IT--Management
Sep 20, 2000
32
0
0
US
I have a script where i need to terminate running tasks, run somethings on another server, then restart the tasks on the first server. The problem is i am not able to terminate these specific tasks. I can terminate other tasks using the code below (just changing the .exe) but not the one specified. I can end task in Task Monitor but not via script. Does anyone have any ideas why this would not work on all tasks?

CODE SNIPET

Function ctBroker

WScript.Echo "killing CtBroker"
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'CtBroker.exe'")
'Set objsrv2 = GetObject("winmgmts:" _
' & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
For Each objProcess in colProcesses
objProcess.Terminate(0)
WScript.Echo "Is CTbroker Dead?"

Next

End Function
 
I take it the script is running in the same user context as when you try and do it via the GUI???
 
Yes, and i am a domain Admin. I thought that there might be a priority issue or something of that nature that i could downgrade then i would be able to stop the task via script but i cannot find anything
 
i had an issue with a service which couldnt be stopped. I assume people can code exe's so that they will only stop via preferred methods, not sure if the author can specify to only allow the thread to be terminated via the GUI, sounds strange.
have you tried the kill command??? not that i would recommend it but it might help in this case. i think it is part of the OS resource kit.

silly question but is it a service?
 
It is called a service but it is not one that you will see in the Service Control Panel. It is essentially a background task, in 3 parts(ctBroker, ctServer, ctWebApp) and all are exe's. I can terminate the Server and WebApp, but not the Broker.

I am not familiar with the kill command, which OS resource kit is it part of?
 
Hello cmwoodman,

It is in fact an issue still hanging clouded by mystery. As to the kill, you can also get the free tool pskill from sysinternals:

If it is possible, could you look into each of the three's output of .getobjecttext_ and posted here. I am interested in documenting it for future reference.

regards - tsuji
 
tsuji,

I have looked at your last post, and i have looked up .getobjecttext_ but i am not sure what you mean by 'three outputs' are you saying there are three specific outputs that this property returns?

FYI, I recieved a detailed list of the API calls specifically for the three executables that i was attempting to kill via vbs and was able to come up with the solution i was looking for, it kills the apps locally, restarts services on another server, then starts the apps again.

Thanks for all your help.
 
Hello cmwoodman,

I come to the conclusion that it might after all asking too much, but I appreciate your show of will. I'm glad you have the problem sort out though I had offered no help at all. The info I would like to know is not critical, so I am just content with that another case has been reported in the net.

For information sake, the .getobjecttext_ operates like the demo below if you do not aware of and it might be of some use for the future.
Code:
set svc = getobject ("winmgmts:root\cimv2")
set objEnum = svc.execQuery ("select * from win32_process")
wscript.echo typename(objEnum)
for each obj in objEnum
    wscript.echo obj.GetObjectText_
next
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top