Autohotkey script - taskkill.exe error on Windows shutdown

0

I am using lot of portable application locally on my laptop and if i leave some of them opened when i shutdown Windows it doesn't close them properly and some applications don't save their settings. I am trying to use taskkill option in a autohotkey script which will be executed on windows shutdown and will close properly opened portable application.

I am using this script:

#SingleInstance, force 
#Persistent 
DllCall("kernel32.dll\SetProcessShutdownParameters", UInt, 0x4FF, UInt, 0)
OnExit , closepgs 
return 
closepgs: 
If (A_ExitReason="Shutdown" or A_ExitReason="Logoff") 

{
Run, taskkill.exe /F /IM uTorrent.exe
}

ExitApp`

But when i shutdown Windows i receive this taskkill.exe error:

"Application failed to initialize properly (0xc0000142). Click on OK to terminate the application"

If i use the taskkill code outside the script like this it works fine:

^!Home:: 
Run, taskkill.exe /F /IM uTorrent.exe

But if i use it inside the script i receive taskkill.exe error.

Any idea why this error happening?

I have Windows XP Pro SP3.

autohotkey
taskkill
asked on Stack Overflow Jul 12, 2013 by user1800997

1 Answer

1

Use Process, Close instead of taskkill.exe:

Process, Close, uTorrent.exe

It seems that as of Windows Vista and later, processes aren't allowed to spawn new processes during the shutdown phase. The only source a quick web search yielded was this one.
On a different note, using native functionality instead of calling programs is almost always preferable. Especially when using AHK, I recommend always looking for a built-in function to start with.

answered on Stack Overflow Jul 15, 2013 by MCL

User contributions licensed under CC BY-SA 3.0