D
D
Dmi3ii2020-02-14 11:21:57
PowerShell
Dmi3ii, 2020-02-14 11:21:57

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:

  • I press WinX
  • Windows PowerShell (Administrator)
  • enter user/password
  • Restart-Service wampapache64

I want to make an alias in PS on behalf of the user with the command to restart the service on behalf of the admin. Typed an alias in the user console - entered the admin password - the service restarted. It seems that the runas command suits me, but no:

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

3 answer(s)
M
MaxKozlov, 2020-02-14
@Dmi3ii

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'"

R
res2001, 2020-02-14
@res2001

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...

K
Konstantin Tsvetkov, 2020-02-14
@tsklab

Use Adjusting Token Privileges in Powershell .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question