如何在 Powershell 中为“网络服务"创建 Windows 服务帐户? [英] How to create a Windows Service in Powershell for "Network Service" account?

查看:102
本文介绍了如何在 Powershell 中为“网络服务"创建 Windows 服务帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Powershell 创建一个 Windows 服务.为给定用户创建它是小菜一碟.我使用了改编自此处的此功能.

I want to create a Windows Service using Powershell. Creating it for a given user is piece of cake. I used this function adapted from here.

function ReinstallService1 ($serviceName, $binaryPath, $login, $pass)
{  
    Write-Host "installing service"
    # creating credentials which can be used to run my windows service
    $secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential ($login, $secpasswd)

    # creating widnows service using all provided parameters
    New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic -credential $mycreds
    Write-Host "installation completed"
}

我的问题是:如何创建网络服务"帐户?

如果我修改 New-Service 行并删除凭据参数,将为 本地系统" 帐户创建服务.差点错过.

If I modify New-Service line and remove credential parameter, the service is created for "Local System" account. Nearly miss.

New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic 

我在谷歌上搜索了很多,但没有看到表明服务帐户的方法.如果我尝试为用户 "NETWORK SSERVICE" 使用 Credential 参数,我不知道要输入什么密码,如果我发明了一个密码(以防 cmdlet 忽略它),它就不起作用.错误是:

I googled a lot and saw no way of indicating service account. If I try to use Credential parameter for user "NETWORK SSERVICE", I don't know what password to put and if I invent one (just in case cmdlet ignores it) it doesn't work. The error is:

新服务:服务'XXXX (XXXX)'由于以下错误,无法创建:帐户名称是无效或不存在,或该帐户的密码无效指定名称

New-Service : Service 'XXXX (XXXX)' cannot be created due to the following error: The account name is invalid or does not exist, or the password is invalid for the account name specified

推荐答案

正确的帐号名称是NT AUTHORITY\NETWORK SERVICE.

这篇关于如何在 Powershell 中为“网络服务"创建 Windows 服务帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆