1

I am having below line of code which is part of my build process. Below code take SectionName and dotnet framework path for aspnet_regiis and encryption flag -pef to encrypt my web.config.

So when build happens i need to run the below code "Run as administrator" for that i used start-process with powershell and -Verb runas option. But when run this script i get a prompt in windows 10 with yes or no option.

How to avoid this.

$args="-pef '${SectionName}' '${configfilepath}'"


Start-process powershell -Verb runas "$(join-path ${frameworkPath} 'aspnet_regiis.exe') ${args}"
mkrana
  • 422
  • 4
  • 10
Vipin
  • 938
  • 5
  • 18
  • 36

1 Answers1

0

Though not the best option, you can have a shortcut to a script that runs the powershell script. Give that shortcut administrative permission and double click it / run it though CMD or something to have it run as administrator.

EDIT: As suggested here:

PowerShell: Running a command as Administrator

You can add an if statement to ensure the -Verb runAs works.

Omer Tal
  • 366
  • 2
  • 8
  • Thanks for replying. The above powershell is written inside a windows service or it is trigger from it. I might not be able to right click and run as administrator there. So i need to programmically allow it. – Vipin May 06 '19 at 13:37
  • 1
    Try to make the service run the shorcut that has the administrator permission. – Omer Tal May 06 '19 at 13:42
  • @Vipin Hi, once it is as windows service, if its scheduled by scheduler, I can remember there was an option to run it as administrator user, maybe that helps? – xxxvodnikxxx May 06 '19 at 13:42
  • Xxxvodnikxxx we cant change it a scheduler because, we are using this code inside a deployment script which is triggered from a told called octopus. Which is a deployment tool – Vipin May 06 '19 at 13:53