AutoHotkey Community

It is currently May 25th, 2012, 4:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Support for UAC
PostPosted: April 4th, 2007, 2:47 pm 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2007, 2:18 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2007, 11:52 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2007, 2:47 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2007, 6:09 am 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2007, 2:16 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2007, 6:31 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2007, 10:34 am 
Offline

Joined: March 23rd, 2006, 2:20 pm
Posts: 128
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2007, 12:54 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2007, 7:00 pm 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group