KillProcess function

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

KillProcess function

Post by newuser » Sat Jun 15, 2013 6:33 pm

This is my code below doesnt work. :(

ProcessExists>PrintCtrl.exe,bNotepadExists
If>bNotepadExists=True
KillProcess>PrintCtrl.exe
Endif

ProcessExists>PrintDisp.exe,bNotepadExists
If>bNotepadExists=True
KillProcess>PrintDisp.exe
Endif

It seem the killprocess function can kill a notepad.exe process but not system process.

I didnt want to use a vbscript method or taskkill method.

Can the killprocess function be enhanced(more powerful) for killing process?

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Jun 15, 2013 8:32 pm

Maybe admin privs are required to kill this process. Try running Macro Scheduler as admin and then see if the script is able to kill the process.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Sun Jun 16, 2013 8:59 am

Let>RP_ADMIN=1

This method above also doesnt work.
Tested on windows xp platform where Im the only user admin. :cry:

I can kill the both process manually using taskkill or taskmanager but not with macro script.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: KillProcess function

Post by armsys » Sun Jun 16, 2013 1:18 pm

newuser wrote:ProcessExists>PrintCtrl.exe,bNotepadExists
If>bNotepadExists=True
KillProcess>PrintCtrl.exe
Endif
PrintCtrl.exe is likely a Windows service.
Not sure why you wish to terminate the printer control service.
Try:

Code: Select all

Run>NET STOP PrintCtrl

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Sun Jun 16, 2013 5:47 pm

Its a pdf printer process not a service, I install a software from giveawayoftheday sometime ago which is from http://www.all2pdf.com. Although I could kill it using taskmanager,vbscript, taskkill but I cant kill it using macro scheduler killprocess function. It cross my mind whynot write a macro to kill it on startup for the fun of it.

But the problem is the killprocess function can kill a notepad, even a calculator process but not those 2 process. Why? :?:

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sun Jun 16, 2013 9:14 pm

newuser wrote:Its a pdf printer process not a service, I install a software from giveawayoftheday sometime ago which is from http://www.all2pdf.com. Although I could kill it using taskmanager,vbscript, taskkill but I cant kill it using macro scheduler killprocess function. It cross my mind whynot write a macro to kill it on startup for the fun of it.
But the problem is the killprocess function can kill a notepad, even a calculator process but not those 2 process. Why? :?:
KillProcess is a perfect killer, you're rest assured.
It seems to me both PrintCtrl.exe and PrintDisp.exe aren't processes.
If you actually watch the Windows Task Manager, PrintCtrl.exe and PrintDisp.exe are successfully killed by KillProcess, but restored seconds later.
Have you actually and successfully killed the both with taskmanager,vbscript, taskkill,...and other killers? Show us your script.
PrintCtrl.exe and PrintDisp.exe are installed as a Windows Service/Driver. Why do you want to kill them? I'm confounded.

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Mon Jun 17, 2013 10:31 am

Batch file

Code: Select all

taskkill /F /IM PrintCtrl.exe
taskkill /F /IM PrintDisp.exe
Wmic batch file

Code: Select all

wmic process where name="PrintCtrl.exe" call terminate
wmic process where name="PrintDisp.exe" call terminate
Vbscript file

Code: Select all

Dim oShell : Set oShell = CreateObject("WScript.Shell")

oShell.Run "taskkill /f /im PrintCtrl.exe", , True
oShell.Run "taskkill /f /im PrintDisp.exe", , True
Vbscript second version file

Code: Select all

Const strComputer = "." 
Set WshShell = CreateObject("WScript.Shell")
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'PrintCtrl.exe'")
For Each objProcess in colProcessList 
  WshShell.Exec "taskkill /F /IM " & objProcess.ProcessId 
Next


Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'PrintDisp.exe'")
For Each objProcess in colProcessList 
  WshShell.Exec "taskkill /F /IM " & objProcess.ProcessId 
Next
Autoit file

Code: Select all

ProcessClose("PrintCtrl.exe")
ProcessClose("PrintDisp.exe")

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Jun 17, 2013 10:41 am

newuser wrote:Batch file

Code: Select all

taskkill /F /IM PrintCtrl.exe
taskkill /F /IM PrintDisp.exe
Wmic batch file

Code: Select all

wmic process where name="PrintCtrl.exe" call terminate
wmic process where name="PrintDisp.exe" call terminate
Vbscript file

Code: Select all

Dim oShell : Set oShell = CreateObject("WScript.Shell")

oShell.Run "taskkill /f /im PrintCtrl.exe", , True
oShell.Run "taskkill /f /im PrintDisp.exe", , True
Vbscript second version file

Code: Select all

Const strComputer = "." 
Set WshShell = CreateObject("WScript.Shell")
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'PrintCtrl.exe'")
For Each objProcess in colProcessList 
  WshShell.Exec "taskkill /F /IM " & objProcess.ProcessId 
Next


Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'PrintDisp.exe'")
For Each objProcess in colProcessList 
  WshShell.Exec "taskkill /F /IM " & objProcess.ProcessId 
Next
Autoit file

Code: Select all

ProcessClose("PrintCtrl.exe")
ProcessClose("PrintDisp.exe")
Thanks for your magnificent demo of process killers in multi-languages.
I'm speechless.
I don't know why KillProcess fails.
I'm sorry.

Just one more shot: Would there be any invisible trailing space(s)?

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Mon Jun 17, 2013 10:51 am

armsys wrote:Thanks for your magnificent demo of process killers in multi-languages.
I'm speechless.
I don't know why KillProcess fails.
I'm sorry.

Just one more shot: Would there be any invisible trailing space(s)?
Nope, its not the trailing space(s), problem.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Jun 17, 2013 12:11 pm

Try:

Code: Select all

VBStart
Sub Kill(Process)
 Dim oShell : Set oShell = CreateObject("WScript.Shell")
 oShell.Run "taskkill /f /im " & Process, , True
End Sub
VBEND
VBRun>Kill,"PrintCtrl.exe"
VBRun>Kill,"PrintDisp.exe"

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Mon Jun 17, 2013 3:22 pm

I think you misunderstood my problem/question, I wanted MS killfunction to work as it should on those 2 process, not integrate vbscript and taskkill into ms.

Reason, simple, I intend to write a macro process killer app to be deploy on computers that have windows xp onwards to 7 or even 8, including
windows xp home which dont have taskkill or wmic features.

If MS native killfunction work properly on my 2 test subject, that means I can begin writing my macro process killer app, but if it isnt, that means I have to put the project on hold.

If you ask me, why not use autoit, reason simple, the autoit app can be decode using decompiler or decompile by autoit experts.

But not MS, from what I read in the forum, the ms compiled exe can only be decompile by Marcus under request, and Marcus already stated in some post(from what I read), unless the request is made by the compiled exe owner him/herself, and also the owner have to had some prove that compiled exe is his/her, then only will Marcus decompile the compiled exe.

Please correct me if the information I read from previous posts are wrong or anything. :shock:

Thank you.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Jun 17, 2013 3:31 pm

newuser wrote:I think you misunderstood my problem/question, I wanted MS killfunction to work as it should on those 2 process, not integrate vbscript and taskkill into ms.
Thanks for now revealing your security concern.
I have never come across the KillProcess failure.
I'm sorry I run out of all ideas.
I'm sorry I don't know the answer.

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Mon Jun 17, 2013 4:39 pm

armsys wrote: Thanks for now revealing your security concern.
I have never come across the KillProcess failure.
I'm sorry I run out of all ideas.
I'm sorry I don't know the answer.
Its ok, my fault too for not clarifying the reason I wanted killprocess function to work in the first place. Sorry. :wink:

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jun 17, 2013 5:11 pm

Macro Scheduler's KillProcess command simply calls the Microsoft TerminateProcess function:

http://msdn.microsoft.com/en-us/library ... s.85).aspx

If it can't be terminated then maybe you (i.e. an ordinary user / the user level that Macro Scheduler is running at) do not have PROCESS_TERMINATE access rights.

That's why I asked if it made any difference launching Macro Scheduler as admin.

I DO NOT mean setting RP_ADMIN=1 - that won't make any difference whatsoever - that is for subsequent Run commands.

What I mean is to start *Macro Scheduler* (or your .exe) as admin.

Try exiting Macro Scheduler. Then right click on Macro Scheduler and select Run as Admin. Then run your script. Does the process now terminate correctly?

It is normal to require admin rights to kill a process.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Jun 17, 2013 10:15 pm

Marcus,
Newuser did afore-mention the overarching OS platforms support:
newuser wrote:Reason, simple, I intend to write a macro process killer app to be deploy on computers that have windows xp onwards to 7 or even 8, including windows xp home which dont have taskkill or wmic features.
Does Admin privilege setting also apply to XP?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts