0

I'm currently in the process of attempting to script (powershell) the automatic installation of Visual Studio 2017 on a VM hosted in an Azure DevTest Lab. The script itself is very simple, i.e.,

try
{
    Invoke-WebRequest -Uri $vs2017Url -OutFile $vs2017Exe;
}
catch
{
    Write-Error "Failed to download VS 2017";
}

try
{
    Start-Process -FilePath $vs2017Exe -ArgumentList "--add Microsoft.VisualStudio.Workload.NetCoreTools;includeRecommended --passive";
}
catch
{
    Write-Error "Failed to install VS 2017";
}

where $vs2017Url is the url of the VS install exe. The problem is that the VS 2017 exe has UAC enabled, which makes it difficult to automate as it throws up the UAC dialog "Do you want to allow this app to make changes to your device?" thereby requiring user intervantion. Is there anyway around this? (The VMs will be deployed using Azure's Artifacts functionality in Azure )

3
  • There is a trick you can do with task scheduler, raymond.cc/blog/task-scheduler-bypass-uac-prompt the tricky part is to create it from powershell and enable the "Allow task to be run on demand" , I think powershell impleentation of task scheduler is the only one that supports setting that option from command line , as explained here:blogs.technet.microsoft.com/heyscriptingguy/2015/01/13/…
    – arana
    Commented Mar 3, 2017 at 16:55
  • 1
    No, you cannot bypass the UAC prompt, and this is by design. (Otherwise, all malware would do it!) Commented Mar 3, 2017 at 17:04
  • Invoke the script in a way that allows it to run with administrative privileges. Also checkout whenever there are any unattended installation switches available.
    – Seth
    Commented Mar 3, 2017 at 18:13

1 Answer 1

0

UAC is a true nightmare when it comes to scripting and remote installation. I believe it is related to the way UAC reacts to processed spawned by other processes. UAC might cause trouble even if the parent process is an approved administrator.

Just to state the obvious: Your PowerShell process needs to run as an administrator :)

Depending on configuration one of the following might work:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .