8

I have alot of clients on my network and I want my script to do the following:

[1] Open an elevated command prompt using the local admin details. Note: I do not want to have to enter a username and password for each user.

[2] Uninstall java using the following command: "wmic product where "name like 'java%'" call uninstall"

[3] I then want to install another version of Java once the PC reboots.

I'm not too worried about steps 2 and 3 at the moment, however step 1 is causing me some problems. I have tried the methods below:

runas command
NirSoft programs
PowerShell

I'm really just wondering if this is possible without going around to every PC on the network and entering the local admin password.

https://stackoverflow.com/questions/19098101/how-to-open-an-elevated-cmd-using-command-line-for-windows

Thanks in advance. Timbo

  • http://www.urtech.ca/2011/05/how-to-deploy-oraclesun-java-silently-in-a-corporate-environment-with-group-policy-in-active-directory-or-using-a-script/ – yagmoth555 Dec 01 '16 at 19:09
  • If you are asking if you can bypass the UAC prompt from script, the answer is of course "no." (If it were possible, all malware would do it.) – Bill_Stewart Feb 16 '17 at 19:29

1 Answers1

11

Start your batch:

powershell.exe -Command "Start-Process cmd -Verb RunAs"
...
rest of script
...

This will open an elevated command prompt

Keep in mind for this to work the user would need to have admin privilege on the box.

If the user is not a local admin you will have the use the /savecred switch, this is a big security hole as then the user and can use the /savecred switch on anything else they want.

If you have AD you can always do this through GPO.

Anthony Fornito
  • 9,526
  • 1
  • 33
  • 122
  • Thanks for the response what I'm really looking for is a way to enter in the admin details in a script without having to manually enter them on each PC. – timboslice101 Dec 03 '16 at 17:31