我有一个脚本,使用sc.exe在我们的开发服务器(所有Windows 2008 64位)上创build各种服务。
该脚本包括设置用户帐户运行服务,但我永远不能得到正确的密码设置。 它设置帐户名称正常,但每当我尝试启动服务时,我得到一个login失败。 如果我手动更改服务pipe理单元中的密码,它工作正常…什么给?
我已经尝试过和没有引号周围的密码,没有成功。
我使用的命令示例:sc create PackageProcessing5 binPath =“c:\ Program Files(x86)…. exe”obj = na \ sys-WSPackager password =“password”
就像我说的,服务创build成功,当我检查pipe理单元时,用户帐户也是正确的。 只是密码不知何故被忽视。 我注意到,如果我把一个不正确的密码在命令行中,它不会抱怨,所以我想这是不是在创build过程中validation它?
这里有什么想法?
我认为这个问题实际上并没有涉及到密码:可能你忽略了给帐户SeServiceLogonRight位(通常是GUI中的“作为服务login”)。 我在TechNet的Windows XP资源工具包帮助页面find了该名称。请参阅知识库文章kb259733(Windows 2000)或kb327545(Windows Server 2003) ,了解如何从GUI执行此操作,但是我假设您确实想要这样做从命令行,你应该看看ntrights。
这是基于我实际上试图用我自己的用户帐户和先前创build的现有服务帐户创build相同的简单服务。 用我自己的帐户,我得到了我认为是从“sc开始”得到的同样的错误:
由于login失败,服务没有启动。
有了服务帐户,我得到了这个错误:
该服务没有及时响应启动或控制请求。
我认为后一个错误是因为我试图启动的程序没有准备好作为一个NT服务。 (如果有帮助的话,那个工作的sc命令没有在密码周围使用引号。)
仅供参考,两个命令的forms是:
sc create xemacs-beta-repo binPath= "C:\Program Files\TortoiseHg\hg.exe serve -d -RC:\code\xemacs-beta -EC:\code\xemacs-beta.hg-serve.log" obj= Sam10\ foo password= bar
Sam10是我的(Windows XP Pro SP3)系统的名称。
我真的不能说,为什么在GUI中重新input密码将修复任何东西,除了build议它可以将SeServiceLogonRight添加到问题的帐户 – 每次你尝试使用这个账户时你是否使用过新的账户?还尝试使用手动制作的帐户?
将“sc config password = <password>”添加到您的脚本中,以在“sc create”之后设置runas帐户的密码。
我遇到了同样的问题,并通过使用“sc config”来修复它。
它需要分解成几个命令,请尝试使用下面的Powershell脚本。
基本上,它添加一个域帐户SeServiceLogonRight然后创build并启动一个域帐户的服务。
注意:Powershell需要以pipe理员身份运行。
下面的Powershell示例是创build一个Windows服务(在这种情况下,TeamCity代理),并运行它作为一个域帐户:
$accountToAdd = "mydomain\account" $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 ""Log on 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 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 ""Log on as a service""" -ForegroundColor DarkCyan } Write-Host "Done." -ForegroundColor DarkCyan #Create Service and set Credentials cmd /c sc create TCAgent5 binPath= "C:\BuildAgent5\launcher\bin\TeamCityAgentService-windows-x86-32.exe -s C:\BuildAgent5\launcher\conf\wrapper.conf" DisplayName= "Team City Agent5" auto obj= account@mydomain Password= mypassword