sc.exe config“服务名称”obj =“DOMAIN \ User”密码=“密码”无法正常工作

时间:2013-09-27 14:00:49

标签: windows batch-file com windows-services cmd

我想从cmd为服务设置密码。我有选择

sc.exe config“服务名称”obj =“DOMAIN \ User”密码=“密码”

执行时,显示“[SC] ChangeServiceConfig SUCCESS” 如果我开始服务 我正在

“Windows无法在本地计算机上启动service1服务。 错误1069:由于登录失败,服务未启动。“

我搜索并获得以下链接 Using SC.exe to set service credentials password fails

我的密码不包含特殊字符。

这样做有什么选择?

4 个答案:

答案 0 :(得分:5)

要检查的第一件事是该用户是否有权在该计算机中登录为服务。如果他这样做(并且您可以执行以下步骤来检查),只需转到服务(开始菜单 - 键入"服务",不带引号)。在列表中找到您的服务,然后右键单击它。选择"属性",然后转到"登录"标签。重新输入"密码"和"确认密码"。单击确定。如果您的用户具有“作为服务登录”的权限,则会显示一条消息" 帐户YourDomain \ YourUser已被授予“登录即服务”权限"。只是尝试再次启动服务,它将起作用。

如果您的用户没有此类权限,您可以使用以下两种方法之一:

1)开始菜单 - 键入"本地安全策略"没有引号。打开"本地政策",然后左键单击"用户权利分配"。在右侧面板上,右键单击"作为服务登录",然后选择"属性"。点击"添加用户或组"并添加您的用户。单击确定。您可能需要重新启动计算机。

2)下载并安装" Windows Server 2003资源工具包工具" (http://www.microsoft.com/en-us/download/confirmation.aspx?id=17657)。打开命令提示符并键入:

ntrights + r SeServiceLogonRight -u MyDomain \ MyUser -m \\%COMPUTERNAME%

重新启动计算机并尝试重新启动该服务。

在您的用户被授予“作为服务登录”权限后,您可以通过命令行创建和启动服务。

答案 1 :(得分:2)

如果您面对帐户YourDomain \ YourUser已被授予“登录即服务”权限,则应执行powershell脚本链接 AddLogonasaService这与您的密码无关。它是用户运行服务的权利/许可。

嵌入代码供您参考。您也可以引用该URL。

param($accountToAdd)
 #written by Ingo Karstein, http://blog.karstein-consulting.com
 #  v1.0, 01/03/2014

 ## <--- Configure here

 if( [string]::IsNullOrEmpty($accountToAdd) ) {
    Write-Host "no account specified"
    exit
 }

 ## ---> End of Config

 $sidstr = $null
 try {
    $ntprincipal = new-object System.Security.Principal.NTAccount "$accountToAdd"
    $sid = $ntprincipal.Translate([System.Security.Principal.SecurityIdentifier])
    $sidstr = $sid.Value.ToString()
 } catch {
    $sidstr = $null
 }

 Write-Host "Account: $($accountToAdd)" -ForegroundColor DarkCyan

 if( [string]::IsNullOrEmpty($sidstr) ) {
    Write-Host "Account not found!" -ForegroundColor Red
    exit -1
 }

 Write-Host "Account SID: $($sidstr)" -ForegroundColor DarkCyan

 $tmp = [System.IO.Path]::GetTempFileName()

 Write-Host "Export current Local Security Policy" -ForegroundColor DarkCyan
 secedit.exe /export /cfg "$($tmp)" 

 $c = Get-Content -Path $tmp 

 $currentSetting = ""

 foreach($s in $c) {
    if( $s -like "SeServiceLogonRight*") {
        $x = $s.split("=",[System.StringSplitOptions]::RemoveEmptyEntries)
        $currentSetting = $x[1].Trim()
    }
 }

 if( $currentSetting -notlike "*$($sidstr)*" ) {
    Write-Host "Modify Setting ""Logon as a Service""" -ForegroundColor DarkCyan

    if( [string]::IsNullOrEmpty($currentSetting) ) {
        $currentSetting = "*$($sidstr)"
    } else {
        $currentSetting = "*$($sidstr),$($currentSetting)"
    }

    Write-Host "$currentSetting"

    $outfile = @"
 [Unicode]
 Unicode=yes
 [Version]
 signature="`$CHICAGO`$"
 Revision=1
 [Privilege Rights]
 SeServiceLogonRight = $($currentSetting)
 "@

    $tmp2 = [System.IO.Path]::GetTempFileName()


    Write-Host "Import new settings to Local Security Policy" -ForegroundColor DarkCyan
    $outfile | Set-Content -Path $tmp2 -Encoding Unicode -Force

    #notepad.exe $tmp2
    Push-Location (Split-Path $tmp2)

    try {
        secedit.exe /configure /db "secedit.sdb" /cfg "$($tmp2)" /areas USER_RIGHTS 
        #write-host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS "
    } finally { 
        Pop-Location
    }
 } else {
    Write-Host "NO ACTIONS REQUIRED! Account already in ""Logon as a Service""" -ForegroundColor DarkCyan
 }

 Write-Host "Done." -ForegroundColor DarkCyan

要设置服务的标识,我使用了vbscript

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = 'Servicename'")
For Each objservice in colServiceList   
errReturn = objService.Change( , , , , , ,WScript.Arguments.Item(0),   WScript.Arguments.Item(1)) 
objService.StartService()   
Next

其中WScript.Arguments.Item(0)是用户名arg,WScript.Arguments.Item(1)是密码。

答案 2 :(得分:1)

可能问题是它不需要密码周围的引号。用户名也一样。

或许无法判断引号是否是密码的一部分。

或者可能是因为给定帐户未被授予“作为服务登录”权限。

通常,您应该检查安全事件日志,该日志将说明登录失败的原因。

答案 3 :(得分:0)

这对我有用:

sc.exe stop "<my_service>" 4:4:3
sc.exe config "<my_service>" obj= "\.<local_acc_name>" password= "<local_acc_pass>"
sc.exe start "<my_service>"

简而言之: 在配置密码之前停止服务,开始将正常工作。

相关问题