0

I want to make changes to a registry key through this command:

REG ADD "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp\IPAll" /v TcpDynamicPorts /t REG_SZ /d 6363 /f

This has to happen in a cmd, which i ran as administrator through powershell with this command in a batch file:

powershell.exe Start-Process cmd.exe -Verb runAs

I need a UAC Prompt for the user to input his admin credentials to make it as user friendly as possible. Now my question: How do i pass the reg add command to the console which i started as administrator?

6
  • Why not just run the whole thing in the powershell console ? why do you need to use the cmd console ? Commented Jun 28, 2018 at 8:54
  • Why dont u just directly set the Regkey using Powershell? Why would you take the extra step with the cmd? Commented Jun 28, 2018 at 8:54
  • I want to setup a silent install for SQLServer 2014 with a configuration file. To finish the setup, i need to change the dynamic TCP/IP port. This is not possible without administrative rights. And since we have multiple servers with probably different admin accounts, i need the user to input the creds. We want to keep the user input to a minimum to avoid any errors caused by the user. I could just start the powershell as admin, but then i wouldn't know how to pass the regedit command to the powershell either. Commented Jun 28, 2018 at 9:04
  • You should take a look at blogs.technet.microsoft.com/heyscriptingguy/2015/04/02/… . Powershell also offers easy Credential-Parsing with a prompt using Get-Credential. Commented Jun 28, 2018 at 9:13
  • I could just start the powershell as admin, but then i wouldn't know how to pass the regedit command to the powershell either - Just use powershell to perform the task that reg is doing. Either use reg like you would from cmd or use powershell commands to do it Commented Jun 28, 2018 at 9:25

1 Answer 1

2

You need to pass your command in -ArgumentList parameter like this:

powershell.exe "Start-Process powershell -ArgumentList 'REG ADD "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp\IPAll" /v TcpDynamicPorts /t REG_SZ /d 6363 /f' -Verb RunAs"

This will execute PowerShell which tries to execute another PowerShell window asking you for credentials and then execute REG ADD command and close PowerShell at the end.

Keep in mind that you don't have error handling or anything like this so you may want to add them later as they might be very useful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.