4

I am running powershell script through jenkins. It has one cmdlets which require elevated permission. so i am writing those cmdlet as below

start-process powershell.exe -verb runas -argumentlist "net localgroups administrators domain\user /add" 

But this prompts a UAC where i have to manual click yes. then its moves further. I want to elevate the cmdlet without giving UAC prompt and continue to go ahead....

The account used to run the script has admin permission on that machine.

4
  • I'm not sure this is possible without disabling UAC, which itself requires a prompt. Jul 29, 2016 at 18:13
  • 1
    Does Jenkins has an option to run powershell script as "RunAS Administrator" ?
    – Amit
    Aug 1, 2016 at 6:43
  • If you are asking if you can bypass the UAC prompt when UAC is enabled, the answer is of course "no." (If it were possible, that's exactly what all malware would do.) Aug 3, 2016 at 18:56
  • @Amit You wrote an answer on 4 Aug with the text that my answer worked so pls accept it - thx
    – DAXaholic
    Aug 23, 2016 at 15:42

2 Answers 2

1

Besides disabling UAC - which obviously should be the last resort - you may achieve your goal with creating a 'scheduled' task which is set up to run elevated and trigger that task from Jenkins.
The difficulty here will be probably about how to pass information to and retrieve information from the task - maybe you can achieve that via some files of well-known paths.
See here for how to set up such a task and here for how to trigger it.

As I do not have any Jenkins installation right now I could not test it though - sry.

1
  • 1
    Does Jenkins has an option to run powershell script as "RunAS Administrator" ?
    – Amit
    Aug 1, 2016 at 6:42
-3

The problem is the switich:

-verb runas

That instructs Windows that you need your code to run as an Administrator.

Remove that, and Windows will stop prompting the user for administrator privileges.


Your next question might be:

But i want a standard user to be able to do things that require administrative privileges.

Sorry, that is not allowed on secure operating systems.

  • if I'm a standard user
  • I simply can't just decide to be an administrator

I actually have to be granted those rights.

The 8 year old, or the corporate desktop user, can't just become an administrator because they wrote:

start-process explorer.exe -verb runas

They will need me, or someone from IT, to walk the 6 buildings over to type in my admin credentials - because i actually do have Administrator privileges.

Imagine Life Before UAC

Every developer complaining about UAC, who hates UAC, wants to go back to before UAC. Lets imagine that.

  • It's 2002, you're running Windows XP SP3
  • There's no UAC, so you're always a standard user

And you want to run some code as an Administrator.

You can't do that; you're a standard user.

The only solution is to:

  • Fast User Switch
  • and get an Administrator to login to the machine
  • have them run your script
  • they then logout
  • and you fast-user-switch back to your own account

UAC is much better; since they can just type their credentials into the UAC dialog:

enter image description here

But I Just Don't Want A UAC Prompt

You might be saying:

I don't care about any of that. I just don't want the UAC prompts. I want it to work like it did in Windows XP

If you don't want the UAC prompts, and you want it to behave like it did in Windows XP: then you absolutely can do that. You are perfectly free to turn off UAC.

  • Standard users will always be standard users, with no way to elevate
  • Administrators will always be administrative users, with no need to elevate

And that is your preference, and you can do that.

Many other users don't want to do their day-to-day work as an Administrator. But since you're only running your script on your computer: it's fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.