Page 1 of 1

AHK close Onedrive

Posted: 06 Dec 2021, 09:00
by TrebleTA
Hi all so my problem is this, If I start a command prompt from windows and enter taskkill /f /im OneDrive.exe, it kills the running onedrive.exe
If I enter this in AHK

Code: Select all

RunWait, taskkill.exe /f /im OneDrive.exe

It will not close onedrive, if i put it in a loot it's like its trying to close yet failing, Ive tried the runwait task as a admin too same thing.
I have also tried

Code: Select all

Process, Close, OneDrive.exe
Also fails. were am i going wrong?

Re: AHK close Onedrive

Posted: 06 Dec 2021, 09:06
by mikeyww
It worked here. Is that your entire script?

Re: AHK close Onedrive

Posted: 06 Dec 2021, 09:14
by TrebleTA
my testing script is 2 types 1 with admin added 2nd with out so very basic i will link

Code: Select all

loop
{
	RunWait, taskkill.exe /f /im OneDrive.exe
}
I'm running windows 11 pro
its like i get a pop up windows just spamming on my screen were its trying to close

Re: AHK close Onedrive

Posted: 06 Dec 2021, 09:17
by mikeyww
You can exit that script and try this one instead, with no other code in the script.

Code: Select all

F3::Process, Close, OneDrive.exe ; Press F3 to close

Re: AHK close Onedrive

Posted: 06 Dec 2021, 09:19
by TrebleTA
Same its not closing one drive, i press f3 and get this in the ahk log yet its not closing the program
  • 001: Return (2.44)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.73)
    001: Process,Close,OneDrive.exe (0.03)
    001: Return (0.22)
    001: Process,Close,OneDrive.exe (0.08)
    001: Return (0.11)
    001: Process,Close,OneDrive.exe (0.05)
    001: Return (0.13)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.08)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.08)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.13)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (1.19)
    001: Process,Close,OneDrive.exe (0.08)
    001: Return (0.13)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (1.47)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.17)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.41)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.17)
    001: Process,Close,OneDrive.exe (0.08)
    001: Return (0.34)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.19)
    001: Process,Close,OneDrive.exe (0.09)
    001: Return (0.09)

Re: AHK close Onedrive

Posted: 06 Dec 2021, 09:26
by mikeyww
Try with admin.

Code: Select all

If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
}

F3::Process, Close, OneDrive.exe ; Press F3 to close
In some cases, a tray icon is a ghost. If you hover over it, it disappears.

If you see OneDrive.exe in your Windows Task Manager after running this script alone, then I am not sure why it would not be working.

Here is another test.

Code: Select all

If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
}
DetectHiddenWindows, On
Process, Close, OneDrive.exe
Sleep, 200
MsgBox, 64, OneDrive, % WinExist("ahk_exe OneDrive.exe")
ExitApp
image006-20211206_cr-75.png
Output
image006-20211206_cr-75.png (7.87 KiB) Viewed 895 times

Re: AHK close Onedrive

Posted: 06 Dec 2021, 09:53
by TrebleTA
I have tried the above and had no luck so have made a quick video showing me using the command prompt to kill the task, then I restarted OneDrive and as you see its not closing when I use AHK, yes I checked the try icon. yet AHK seems to be trying to close it but failing. So I guess that this could be a new bug with AHK being detected by the system or something. I am on the latest version of Windows 11 pro insider build.
[youtube]
https://youtu.be/j1WytRD-9Og
[/youtube]

I will making a batch file and call that in AHK to see if that can kill the task.

P.S i tried the above and i got this output.
Image

Re: AHK close Onedrive

Posted: 06 Dec 2021, 09:58
by mikeyww
OK. I am on Win10, so sorry I do not have a way to test on Win11. Are you able to use a similar approach to close other running processes?

Re: AHK close Onedrive

Posted: 06 Dec 2021, 10:01
by TrebleTA
making a kill.bat file with

Code: Select all

taskkill.exe /f /im OneDrive.exe
then doing this in AHK works

Code: Select all

If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
}
F3::RunWait, Kill.bat

Re: AHK close Onedrive

Posted: 06 Dec 2021, 10:03
by mikeyww
OK. Strange. Perhaps it is some kind of an admin rights issue.

Re: AHK close Onedrive

Posted: 06 Dec 2021, 10:03
by TrebleTA
Yes closing notepad.exe and other process its just Onedrive being a :problem:

Re: AHK close Onedrive

Posted: 06 Dec 2021, 10:09
by mikeyww
I think you proved that it's not an AHK bug, but probably something with how Windows manages that process.

Re: AHK close Onedrive

Posted: 06 Dec 2021, 14:59
by TrebleTA
Yes I was thinking that but why a batch file still work, anyways very strange. Thank you for helping me check