AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Support for UAC

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Tekl



Joined: 24 Sep 2004
Posts: 814
Location: Germany

PostPosted: Wed Apr 04, 2007 2:47 pm    Post subject: Support for UAC Reply with quote

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
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Thu Apr 05, 2007 2:18 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Roussi Nikolov
Guest





PostPosted: Wed May 09, 2007 11:52 pm    Post subject: Reply with quote

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

PostPosted: Thu May 10, 2007 2:47 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Tekl



Joined: 24 Sep 2004
Posts: 814
Location: Germany

PostPosted: Thu May 10, 2007 6:09 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Roussi Nikolov
Guest





PostPosted: Thu May 10, 2007 2:16 pm    Post subject: Reply with quote

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

PostPosted: Sun May 13, 2007 6:31 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
rousni



Joined: 23 Mar 2006
Posts: 87

PostPosted: Tue Jun 19, 2007 10:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Tue Jun 19, 2007 12:54 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
ladiko



Joined: 14 Jul 2006
Posts: 281
Location: Berlin

PostPosted: Sun Sep 09, 2007 7:00 pm    Post subject: Reply with quote

now you can compile your script with Compile_AHK and the compiled exe will ask for higher rights if UAC is enabled. look here --> http://www.autohotkey.com/forum/viewtopic.php?p=146598
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group