У меня есть служба Windows, которая регулярно запускает скрипт PowerShell на удаленном компьютере через WsManConnectionInfo
/RunspaceFactory
(следуя инструкции из этой статьи: Remotely Executing Commands in PowerShell using C#):PowerShell Remoting из службы Windows,
var connectionInfo = new WSManConnectionInfo(false, server, 5985, "/wsman",
"http://schemas.microsoft.com/powershell/Microsoft.PowerShell",
cred)
{
OperationTimeout = 4*60*1000,
OpenTimeout = 1*60*1000
};
using (var runSpace = RunspaceFactory.CreateRunspace(connectionInfo))
{
runSpace.Open();
using (var p = runSpace.CreatePipeline())
{
p.Commands.AddScript(script);
var output = p.Invoke();
...
}
}
Теперь, если я запустите службу Windows самостоятельно с учетной записью администратора , все хорошо. Но если я запускаю службу с учетной записью LocalSystem, я получаю следующее исключение;
System.Management.Automation.Remoting.PSRemotingTransportException:
Connecting to remote server NOSRVDEV02 failed with the following error message :
WinRM cannot process the request. The following error with
errorcode 0x8009030d occurred while using Negotiate authentication:
A specified logon session does not exist. It may already have been terminated.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does not exist.
-The client and remote computers are in different domains and there is no trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
at System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.EndOpen(IAsyncResult asyncResult)
at System.Management.Automation.RemoteRunspace.Open()
...
Примечание: Это не имеет ничего общего с учетными данными в WSManConnectionInfo
- только настройки учетной записи в свойствах службы «Log On» вкладки.
Я не хочу предоставлять служебные привилегии администратора. Любые идеи, почему пользователь LocalSystem не смог войти в систему?
Дополнительная информация:
- Удаленный компьютер не является членом домена.
- Я попытался подключиться как по IP-адресу, так и по имени хоста (оба указаны на локальном компьютере
TrustedHosts
).
EDIT: Даже больше информации (резюме замечаний):
- Локальный компьютер: Windows 7 Ultimate 64bit (виртуальная машина на коробке Windows 8).
- Удаленный компьютер: Windows Server 2008R2 Datacenter 64bit.
- Основная причина, по которой мы не хотим менять учетные записи пользователей службы, заключается в том, что это обновление старой службы, которая уже развернута на многих клиентах (клиентах).
- Служба также обращается к реестру Windows и файловой системе на локальном компьютере, поэтому установка учетной записи пользователя на что-то более ограничена, как и NetworkService, просто откроет другую банку червей.
Какая версия Windows, вы используете это на? – mjolinor
@mjolinor - Локальный компьютер: Windows 7 Ultimate 64bit (виртуальная машина в окне Windows 8). Удаленный компьютер: Windows Server 2008R2 Datacenter 64bit. – Sphinxxx
Вы пытались использовать учетную запись NetworkService вместо учетной записи LocalSystem? – mjolinor