Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Support for UAC


  • Please log in to reply
9 replies to this topic
Tekl
  • Members
  • 814 posts
  • Last active: May 03 2009 03:28 PM
  • Joined: 24 Sep 2004
Hi,

AutoIt now has support for Vista's User Access Control (UAC). Will this come to AutoHotkey too?

Or is there a way to use it with DllCall?
Tekl

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
If you want a script to run with admin privileges, the following methods may work:

1) Display the properties dialog for AutoHotkey.exe and change it to run as administrator. However, this has the drawback of running all scripts as administrator.

2) According to Wikipedia's entry about Vista's User Account Control, you can have the script re-execute itself via the "RunAs verb". The following might work:
if not A_IsAdmin
{
	DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath
		, str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1)  ; Last parameter: SW_SHOWNORMAL = 1
	ExitApp
}
If you want to pass parameters to the new instance (such as %1%, %2%, etc.), I think they can be appended to the A_ScriptFullPath parameter (with delimiting spaces and quotes, as needed).

This will probably become a built-in feature eventually; but until then, I hope this method will be adequate.

Roussi Nikolov
  • Guests
  • Last active:
  • Joined: --
I am using that to reload, by means of a hotkey, my compiled ahk program as administrator. Is there any way to define another similar function reloading an "administrator" program NOT as administrator.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Other than RunAs (which I think you already tried), I don't know -- but maybe someone else knows. If not, some research at MSDN or general web searching is probably needed.

Tekl
  • Members
  • 814 posts
  • Last active: May 03 2009 03:28 PM
  • Joined: 24 Sep 2004
Hi,

I had the same problem. Beside RunAs, where the logged in user has to enter its password again there's another solution.

I use two scripts. The launcher script has #noicon and just uses the DllCall to run the main script with admin rights. If the main script wants intself startet not as admin it uses SendMessage to tell the launcher script to run the main script normally with the command line parameter /r. The launcher script uses OnMessage to catch those special messages. In the main script I use OnExit to determine if the script will be quitted. While quitting the main script sends a different SendMessage which let the launcher script quit itself.
Tekl

Roussi Nikolov
  • Guests
  • Last active:
  • Joined: --
I thought about using a loader, but when it's a matter of compiled programs without AutoHotkey installed on the machine, this solution doesn't seem elegant since it requires two separate programs running at the same time.

Here is another working, compromise solution, allowing to toggle between two modes:

#a:: ; Adjust Privileges
	If A_IsAdmin
	{
		Send, #r
		WinWait, Run ahk_class #32770,, 2
		If ErrorLevel
			Exit
		ControlSetText, Edit1, %A_ScriptFullPath%, Run ahk_class #32770
		Send, {ENTER}
		ExitApp
	}
	Else
	{
		PARAM1 = %1%
		DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_ScriptFullPath, str, """" . PARAM1 . """", str, A_WorkingDir, int, 1)
	}
Return

Is there any way, please, of calling an invisible Run box?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Is there any way, please, of calling an invisible Run box?

Why not use the Run command instead?

RunAs works the same either way:
; (in an .ahk script)
Run, RunAs /user:Administrator cmd
This first pops up a command prompt asking for the admin password, then closes that and pops up another command prompt running as Administrator.

rousni
  • Members
  • 133 posts
  • Last active: Jul 17 2018 01:36 PM
  • Joined: 23 Mar 2006

Why not use the Run command instead?


When my autohotkey program runs as administrator, I can't reload it without administrative privileges using the run command.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
There's something about "Run RunAs" that I think won't work on Vista for this purpose. Perhaps it's the fact that "Run RunAs" is a program (RunAs.exe), not a verb; Vista might require that the verb be used for this purpose.

ladiko
  • Members
  • 290 posts
  • Last active: Jan 16 2012 11:46 PM
  • Joined: 13 Jul 2006
now you can compile your script with Compile_AHK and the compiled exe will ask for higher rights if UAC is enabled. look here --> <!-- m -->http://www.autohotke...ic.php?p=146598<!-- m -->