"FileMoveDir" with Admin-Rights

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

"FileMoveDir" with Admin-Rights

25 Feb 2016, 15:54

I use "FileMoveDir" to rename a folder. Sometimes I got an error message, and as I tried to rename it with Explorer, I got the wellknown message
"You need Admin-Rights to rename this folder. Do you want to continue?
Continue / Skip / Cancel"
Continue did the job, without asking for username and password.

How to "FileMoveDir" with Admin-Rights" in AHK?
Is is possible to change: "If first try creates an error, then try with Admin-Rights"?

Thanks.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: "FileMoveDir" with Admin-Rights

25 Feb 2016, 16:51

No. "Retrying with admin rights" would require launching a new process with admin rights and then retrying. AutoHotkey can't detect the dialog, and doesn't even know which files are being copied. When the source and destination are on the same volume, the move is handled by a single call to SHFileOperation(&FileOp).

If you run the script as admin, the first try will be "with admin rights".

If it's even possible that FileMoveDir is causing that dialog, I suppose that it is a bug in Windows (or its documentation).
FOF_NO_UI
Windows Vista. Perform the operation silently, presenting no UI to the user. This is equivalent to FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR.
Source: SHFILEOPSTRUCT structure (Windows)
AutoHotkey doesn't use the FOF_NO_UI constant, but it uses flags which combine to exactly the same value.
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: "FileMoveDir" with Admin-Rights

26 Feb 2016, 02:11

Thanks lexikos

I "solved" it with a simple message to the user.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
CodeKiller
Posts: 42
Joined: 02 Sep 2014, 04:14

Re: "FileMoveDir" with Admin-Rights

26 Feb 2016, 07:36

Why don't you use Run command ? So that the script will run normaly and only this command

Code: Select all

RunAs Administrator
Run %command%
RunAs
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: "FileMoveDir" with Admin-Rights

26 Feb 2016, 08:48

CodeKiller wrote:Why don't you use Run command ? ...[/code]
This is what I thought too, but I didn't try it because I understood the help-file in that way that a password is obligatory.
But I should try ...

(BTW: I either understand the background of the Windows behaviour that
- sometimes it asks only "Continue as Admn?" and
- sometimes it asks for Admin-loginname and admin-password)
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, gsxr1300, mikeyww, PsysimSV and 290 guests