Stop a service (kill task)

Started by jfrasier, March 13, 2014, 02:03:44 PM

Previous topic - Next topic

jfrasier

I am trying to stop a service or two at the beginning of my script. I saw this in the manual:

wntSvcControl("", "Spooler", 0, 1)

This resulted in a undefined variable or something. Then I changed it to

AddExtender('wwwnt34i.dll',0,'wwwnt64i.dll')
wntSvcControl("", "Spooler", 0, 1)

Now is says the .dll is not found.

I so rarely use this program that I need a little help. Thanks.

td

You need to have an extender available before you can use it.  The WinBatch setup program automatically installs the network extender (wwwnt34i.dll/wwwnt64i.dll) when it installs WinBatch so it should be on your system. 

If you deleted the file, it can be downloaded directly from the download link at the top if this forum.  If your maintenance agreement has lapsed, you may need to download one of the extender archives to find a version that will work with your WinBatch version. 

If you are compiling your script, you will need to make sure the extender is available to the compiled exe.  This is usually done by including the extender in your compiled exe but it is not absolutely necessary to do so.  The extender just needs to be in the same directly as the exe or on the search path of the exe.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jfrasier

I am thinking now that maybe it isn't a service, but it is a process that needs to be stopped. SHould that be the same commands? Doesn't seem to work.

Thanks.

jfrasier

The other wrinkle to this problem is that the program that I am trying to stop is running as shell.


td

Not sure what you mean by 'running as shell' but you can use the WinClose function to kill a process, if it is attached as a top level window.  Otherwise you can use the process extender to do the same.  Click on the 'Tech Database' menu item at the top of the page to go to the tech support site.  Search on 'kill process' to find several examples using the process extender.

In both instance you my need to run your script as an elevated admin, if you are using Windows Vista or newer and have UAC enable.

{edit} Also, WMI using the WinBatch COM subsystem or 'System.Diagnostics.Process' using the WimBatch CLR subsystem provide methods to kill processes. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hdsouza

I had written a similar kill task a little while ago. See if it helps
Here we are killing IE

AddExtender("wwctl44i.dll")
AddExtender("wwprc44i.dll")
ProcName_Kill = "iexplore"
GoSub  Close_Process
Exit

:Close_Process
Proc_List=tListProc()
IE_ProcExist = StrIndexNc (Proc_List, ProcName_Kill, 1, @FWDSCAN)
IF IE_ProcExist == 0 then return
Proc_count = ItemCount (Proc_List, @TAB)
For EE = 1 to Proc_count
    Proc_Details = ItemExtract(EE,Proc_List,@TAB)
    procname=ItemExtract(1,Proc_Details,"|")
    IF procname != ProcName_Kill Then Continue
    procid=ItemExtract(2,Proc_Details,"|")
    Flag_Proc=3
    ErrorMode(@OFF)
    Process_handle=tOpenProc(procid,Flag_Proc)
    ErrorMode(@CANCEL)
    If Process_handle == 0 then Break
    ErrorMode(@OFF)
    Kill_Proc=tKillProc(Process_handle)
    Close_Proc=tCloseProc(Process_handle)
    ErrorMode(@CANCEL)
    Break
Next
Return

td

And using the CLR subsystem:
Code (winbatch) Select
ObjectClrOption("use","System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
objProcess = ObjectClrNew("System.Diagnostics.Process")

strProcName = "iexplore" 
aProcs = objProcess.GetProcessesByName(strProcName)

nProcMax =  ArrInfo(aProcs, 1) - 1
for  i = 0 to  nProcMax
   aProcs[i].Kill
   aProcs[i].Dispose()
next

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade