2
votes

I have VS2015 set up so that it always runs as administrator (a la something like this https://superuser.com/a/468056/48346).

Now I want to create an AHK script to launch Visual Studio and run a few UI / Keyboard commands to get it ready for me - I want this script to run at login but that's a later problem.

The Null solution is obviously to turn UAC off, but I don't want to do that.

So far I'm stuck on the way the UAC prompt always grabs the whole screen and I can't use AHK to click the "yes" button or send any keyboard commands to press enter or something like that. I guess this is the whole point of the UAC prompt, not to allow anything to do it for me.

Is there no way to open VS without the UAC prompt showing? I'd need to open a specific solution file, so if it's possible from the command line, the solution file would need to be included in the command so that it opens.

So far I've tried the AHK command RunAs, but I couldn't get that to work - my personal user is a domain user that's a member of the admin group on my local machine. I tried creating a specific runner account with admin privileges and use the RunAs command with that, but that didn't work. I get an access is denied when I run this AHK code:

RunAs, runner, password, LocalComputer-Name
Run, %comspec% /k "start c:\Users\myacc\Documents\path\solution.sln"

The runner account is in the Administrators group on my local machine, which has full access to the folder where the solution file is stored including the file itself - so I don't understand why access is denied.

Is this not possible?

Ps. I'd ask this question on the AHK forum, but registering there seems to not send any confirmation email at all (no, it's not in my spam folder), so I can't post it there.

1
Turning UAC off is the only way to do it. If there was a programmatic or scriptable way to get around UAC, then there would be no point in even having UAC.aphoria
I've seen some posts here and there suggesting this-and-that (including the RunAs command) for previous versions of Windows with UAC, is this hard limit something new?gakera
Could it be possible to create a script that just waits until I press Yes and then continues execution?gakera
Also, isn't there some way of setting a Scheduled Task to run at logon that runs as admin without needing the UAC? I seem to remember something like that, I'm going to investingategakera

1 Answers

3
votes

The answer is to schedule a task that runs with the highest privileges to run the script at logon. The problem I was really having was to construct and debug the script - running a task each time was cumbersome. So to debug the script, just right-click the script and select "Run as administrator". Then the UAC prompt will pop up before the script starts running but not during the script. Then when the script is ready, just schedule a task to run at logon and check the "Run with highest privileges" option for the task. Then you can try the task by right-clicking the newly created task and selecting run, then you will see it run without the UAC prompt.

My final version of the script just opens the solution file using Run, no RunAs required - the scheduled task is set to run as my user, with the highest privileges.

Run, %comspec% /c "start c:\Users\myacc\path\solution.sln"