sc.exe配置“服务名称"; obj ="DOMAIN \ User";密码=“密码";不工作 [英] sc.exe config "Service Name" obj= "DOMAIN\User" password= "password" not working

查看:264
本文介绍了sc.exe配置“服务名称"; obj ="DOMAIN \ User";密码=“密码";不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to set password for a service from the cmd. I got the option

sc.exe配置服务名称" obj ="DOMAIN \ User"密码=密码"

执行时,其显示为"[SC] ChangeServiceConfig成功" 如果我启动服务 我正在

When I execute, its showing "[SC] ChangeServiceConfig SUCCESS" and if I start the service I am getting

" Windows无法在本地计算机上启动service1服务. 错误1069:服务由于登录失败而无法启动."

"Windows could not start the service1 service on Local Computer. Error 1069: The service did not start due to a logon failure."

我搜索并获得了以下链接 使用SC.exe设置服务凭据密码失败

I searched and got the below link Using SC.exe to set service credentials password fails

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

My password doesn't consist of special character.

有什么选择呢?

推荐答案

如果您遇到帐户YourDomain \ YourUser已被授予登录即服务"权限,则应执行powershell脚本链接 AddLogonasaService ,这与您的操作无关密码.这是用户运行服务的权利/许可.

If you face The account YourDomain\YourUser has been granted the Log On As a Service right, you should execute powershell script link AddLogonasaService and this is nothing to do with your password. It's a right/permission for an user to run the service.

将代码嵌入其中以供参考.您也可以引用该URL.

Am embedding the code for your reference. You can refer that URL as well.

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

To set the identity for services, I have used a 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)是密码.

Where WScript.Arguments.Item(0) is the username arg and WScript.Arguments.Item(1) is password.

这篇关于sc.exe配置“服务名称"; obj ="DOMAIN \ User";密码=“密码";不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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