[英]How can i stop and start windows services using subprocess with admin permissions?
[英]How can I start and stop services on a remote machine?
我在項目中有一個要求,即我們必須在遠程計算機(位於同一LAN上)中停止特定服務“x”,遠程更改注冊表項並再次啟動服務。
我嘗試了sc \\server stop service
命令,但是我得到了錯誤:
[SC] GetServiceKeyName FAILED 1060:
指定的服務不作為已安裝的服務存在。
我使用的是Windows 2003 SP1。 Windows上是否有可用的內置命令或API?
我需要在命令提示符下運行命令。
還要記住,“sc”命令行工具所期望的“服務名稱”參數並不總是等同於您在服務控制面板小程序中看到的名稱(即服務“顯示名稱”)。
例如,我的服務控制面板小程序中顯示為“Adobe Acrobat Update Service”的服務的實際名稱為“AdobeARMservice”。 在通過“sc”實用程序管理服務時,您必須使用后者,而不是前者。
例:
sc Stop "AdobeARMservice" (works)
sc Stop "Adobe Acrobat Update Service" (doesn't work)
要獲取服務的“真實”名稱,請在服務控制面板小程序中雙擊其條目,然后在“常規”選項卡上查看“服務名稱”字段。
當然,在某些情況下,顯示名稱和服務名稱是相同的。
你可能想看看PSTools從Sysinternals的 。 這些工具是免費提供的,可以幫助您管理遠程Windows機器上的進程。
PsTools套件中包含的工具可以作為包下載,它們是:
PsExec - execute processes remotely PsFile - shows files opened remotely PsGetSid - display the SID of a computer or a user PsInfo - list information about a system PsKill - kill processes by name or process ID PsList - list detailed information about processes PsLoggedOn - see who's logged on locally and via resource sharing PsLogList - dump event log records PsPasswd - changes account passwords PsService - view and control services PsShutdown - shuts down and optionally reboots a computer PsSuspend - suspends processes PsUptime - shows you how long a system has been running since its last reboot
從這個URL :
To stop a service remotely you can use the command sc.
Example:
> sc \\computer stop "Service Name"
> sc \\computer start "Service Name"
也許你錯過了一個“\\”字符?
使用OpenCSManager,然后使用OpenService,然后使用StartService。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.