
我正在 Windows Server 2008(Team City)上執行建置伺服器。建置由 Team city 代理程式運行,該代理程式在 LocalService 帳戶下作為 Windows 服務運行。
其中一個建置需要將其創建的 zip 檔案複製到遠端共享,為此,我有一個 powershell 腳本,該腳本嘗試使用具有寫入共享的適當權限的使用者的憑證來 shell 一個新進程。問題是腳本無法建立進程。我可以從我的管理員用戶那裡很好地運行腳本(因此腳本本身似乎很好),這讓我認為 LocalSystem 帳戶沒有某些權限來使用不同的憑證或類似的東西來 shell 新進程?
知道這個錯誤的真正意義嗎?注意:我在安全事件日誌中看不到任何錯誤,這看起來很奇怪(?)
$userName = "domain\user"
$password = "password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $secstr
$command = "Copy-Item d:\file.zip \\remote\share\file.zip"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
Start-Process powershell -NoNewWindow -ArgumentList "-encodedCommand", $encodedCommand -credential $credentials -wait
在 Start-Process 行拋出錯誤
System.InvalidOperationException: This command cannot be executed due to the error: Access is denied.
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
答案1
看我的答案到透過本機系統帳戶使用 powershell 提升積分在 StackOverflow 上:
當腳本運行時,某些命令似乎受到限制本地系統。這在安全性方面是有意義的,因為本地系統:
可以完全不受限制地存取本地資源。這也是 LocalSystem 的缺點,因為 LocalSystem 服務可能會執行導致整個系統癱瘓的操作。
參考:MSDN,本機系統帳戶