Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top