AHK close Onedrive

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

AHK close Onedrive

06 Dec 2021, 09:00

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?
User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: AHK close Onedrive

06 Dec 2021, 09:06

It worked here. Is that your entire script?
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AHK close Onedrive

06 Dec 2021, 09:14

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
User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: AHK close Onedrive

06 Dec 2021, 09:17

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
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AHK close Onedrive

06 Dec 2021, 09:19

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)
User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: AHK close Onedrive

06 Dec 2021, 09:26

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 816 times
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AHK close Onedrive

06 Dec 2021, 09:53

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
Attachments
Screenshot 2021-12-06 145523.png
Screenshot 2021-12-06 145523.png (9.73 KiB) Viewed 778 times
User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: AHK close Onedrive

06 Dec 2021, 09:58

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?
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AHK close Onedrive

06 Dec 2021, 10:01

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
User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: AHK close Onedrive

06 Dec 2021, 10:03

OK. Strange. Perhaps it is some kind of an admin rights issue.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AHK close Onedrive

06 Dec 2021, 10:03

Yes closing notepad.exe and other process its just Onedrive being a :problem:
User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: AHK close Onedrive

06 Dec 2021, 10:09

I think you proved that it's not an AHK bug, but probably something with how Windows manages that process.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AHK close Onedrive

06 Dec 2021, 14:59

Yes I was thinking that but why a batch file still work, anyways very strange. Thank you for helping me check

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 139 guests