topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 3:36 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Work-around to run as admin on logon if you run with UAC notifiy disabled  (Read 2565 times)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Since Vista with UAC and other protections, I'm finding that each Major Windows release requires more utilities to be Run As Administrator.  This is even for stuff like moving windows on the screen or detecting things about the active window etc..

Windows isn't keen about programs with lesser privilege launching those with greater privilege.  This makes it difficult to run a program as administrator at logon without getting the dreaded UAC Prompt.  The conventional wisdom is to create a scheduled task.  For me this is usually more complicated than the program I am trying to run.

So, since AutoHotkey is a marcro program I thought why not make a program with admin privilege to run all the other programs you want at logon, that run as administrator.  This program cannot be run from the users StartUp folder so we make an "ordinary" program and put a shortcut to it in the user's StartUp.  This ordinary program merely double clicks the desktop icon of the privileged program that runs all the other privileged programs.  Got it?  :)

To avoid hard wiring the names of all the programs I want to run as administrator I made a folder in the folder I use for my small utilities(C:\Utils) called StartAdmin.  Any program you wish to run at startup that must be run as Administrator just make a shortcut to the program with Compatibility Tab set to whatever(I often use Windows 7 in W8 as it seems to work better) and at the bottom make sure Run As Administrator is checked.  Put the shortcut in the C:\Utils\StartAdmin folder.

On my system I have the desktop shortcut to the program that will run everything in this folder, at the left of the screen second row from the top.  But you can use the Window Spy that comes with AHK to get the x y coords so that the double click hits the target.

Here's the code to the program that double clicks the desktop icon
btw I am using the AHK just released today AutoHotkey1.1.20.0.1

SendMode Input
CoordMode,Mouse,Screen
Process,Exist,ReRun.exe
If (ErrorLevel) ; quit if ReRun already running
Exit
Sleep 5000
MouseMove,36,130
Click 2
Exit

Note that instead of ReRun.exe in the Process,Exist line, you can use any of the programs you will be running as administrator, just to avoid launching them again if somehow they were already started.

The MouseMove  x,y numbers should be adjusted so the double click(Click 2) hits the icon.
The program below, must be compiled with the directive requiring admin privilege so that it may launch all the shortcuts in the folder we have designated for our Run As Administrator startup programs.

/*
 * * * Compile_AHK SETTINGS BEGIN * * *

[AHK2EXE]
Exe_File=%In_Dir%\AdminStart.exe
No_UPX=1
Execution_Level=4

* * * Compile_AHK SETTINGS END * * *
*/

SendMode Input
SetWorkingDir,%A_ScriptDir%
Loop  C:\Utils\StartAdmin\*.lnk
  Run %A_LoopFileLongPath%

Again, the code is hard-wired to use the folder
C:\Utils\StartAdmin

For something this small it's probably easier to
just edit the script.  Note that it loops through every
file with a .lnk extension, which is that used by
program shortcuts.

The main thing is to have your desktop icon that is the target
of the double click in a location where it is not likely to be
obscured at logon.

Right now I'm using this method to start ReRun, MoveIt and
Transpose, all of which need Run As Administrator to work
well on Windows 8.0, at logon.

A kludge but it's better than remembering to manually start
them all.  And I just don't have any desire to mess with all
that quagmire of detail required to get a scheduled task to
work.

Enjoy.   :)

« Last Edit: March 10, 2015, 11:37 AM by MilesAhead »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Here's a slightly improved ClickAdminStart.  It shows a balloon tip explaining what it is double clicking.

#Persistent
SendMode Input
CoordMode,Mouse,Screen
Process,Exist,ReRun.exe
If (ErrorLevel) ; quit if ReRun already running
Exit
Sleep 3000
TrayTip, AdminStart Clicker,Double Clicking AdminStart,10,17
SetTimer, RemoveTrayTip, 6000
return

RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
MouseMove,36,130
Click 2
ExitApp