Answer the question
In order to leave comments, you need to log in
How to restart a service as administrator?
I'm running as a normal user. The service is running on behalf of the administrator. To restart it, I'm taking the following steps:
PS C:\>runas /user:domain\admin "powershell -NoExit -Command Restart-Service wampapache64"
Restart-Service : Не удается остановить службу "wampapache64 (wampapache64)" из-за следующей ошибки: Не удалось открыть службу wampapache64 на компьютере '.'.
строка:1 знак:1
+ Restart-Service wampapache64
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (System.ServiceProcess.ServiceController:ServiceController) [Restart-Service], ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.RestartServiceCommand
Answer the question
In order to leave comments, you need to log in
It didn't work because the new process started under a different user, but not with admin rights
. You can run it in a chain. type
$credential = Get-Credential domain\Admin
#Сначала другим пользователем, а потом им же, но с повышенными правами
Start-Process -Credential $credential -FilePath powershell -ArgumentList "Start-Process -Verb runAs -FilePath powershell -ArgumentList 'Get-Service winrm; read-host'"
There is no easy way to elevate privileges.
There are options from the category of "tricks" that use the vbs / js script embedded in the batch file: https://safezone.cc/threads/kak-zapustit-programmu...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question