 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Tekl
Joined: 24 Sep 2004 Posts: 814 Location: Germany
|
Posted: Wed Apr 04, 2007 2:47 pm Post subject: Support for UAC |
|
|
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 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Thu Apr 05, 2007 2:18 am Post subject: |
|
|
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:
| Code: | 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. |
|
| Back to top |
|
 |
Roussi Nikolov Guest
|
Posted: Wed May 09, 2007 11:52 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Thu May 10, 2007 2:47 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Tekl
Joined: 24 Sep 2004 Posts: 814 Location: Germany
|
Posted: Thu May 10, 2007 6:09 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Roussi Nikolov Guest
|
Posted: Thu May 10, 2007 2:16 pm Post subject: |
|
|
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:
| Code: | #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? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4470 Location: Qld, Australia
|
Posted: Sun May 13, 2007 6:31 am Post subject: |
|
|
| Roussi Nikolov wrote: | | Is there any way, please, of calling an invisible Run box? | Why not use the Run command instead?
RunAs works the same either way: | Code: | ; (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. |
|
| Back to top |
|
 |
rousni
Joined: 23 Mar 2006 Posts: 87
|
Posted: Tue Jun 19, 2007 10:34 am Post subject: |
|
|
| Quote: | | 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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Tue Jun 19, 2007 12:54 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
ladiko
Joined: 14 Jul 2006 Posts: 281 Location: Berlin
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|