Windows-Server-2008-R2

cscript 在由 winrm via 執行時失敗,但在本地執行時有效

  • May 12, 2015

我正在執行以下內容作為 Windows 伺服器廚師部署的一部分。

cscript /nologo C:\chef\wget.vbs /url:http://www.opscode.com/chef/install.msi /path:C:\Users\ADMINI~1\AppData\Local\Temp\chef-client-latest.msi 

我得到的錯誤是:

CScript Error: Execution of the Windows Script Host failed. (0x800A0007)

vbs 文件由以下命令創建:

C:\Users\Administrator>(
echo.url = WScript.Arguments.Named("url")  
echo.path = WScript.Arguments.Named("path")  
echo.proxy = null  
echo.Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")  
echo.Set wshShell = CreateObject( "WScript.Shell" )  
echo.Set objUserVariables = wshShell.Environment("USER")  
echo. 
echo.'http proxy is optional  
echo.'attempt to read from HTTP_PROXY env var first  
echo.On Error Resume Next  
echo. 
echo.If NOT (objUserVariables("HTTP_PROXY") = "") Then   
echo.proxy = objUserVariables("HTTP_PROXY")  
echo. 
echo.'fall back to named arg  
echo.ElseIf NOT (WScript.Arguments.Named("proxy") = "") Then   
echo.proxy = WScript.Arguments.Named("proxy")  
echo.End If  
echo. 
echo.If NOT isNull(proxy) Then  
echo.'setProxy method is only available on ServerXMLHTTP 6.0+  
echo.Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")  
echo.objXMLHTTP.setProxy 2, proxy  
echo.End If  
echo. 
echo.On Error Goto 0  
echo. 
echo.objXMLHTTP.open "GET", url, false   
echo.objXMLHTTP.send() 
echo.If objXMLHTTP.Status = 200 Then   
echo.Set objADOStream = CreateObject("ADODB.Stream")  
echo.objADOStream.Open 
echo.objADOStream.Type = 1  
echo.objADOStream.Write objXMLHTTP.ResponseBody  
echo.objADOStream.Position = 0  
echo.Set objFSO = Createobject("Scripting.FileSystemObject")  
echo.If objFSO.Fileexists(path) Then objFSO.DeleteFile path  
echo.Set objFSO = Nothing  
echo.objADOStream.SaveToFile path  
echo.objADOStream.Close 
echo.Set objADOStream = Nothing  
echo.End if  
echo.Set objXMLHTTP = Nothing                                                                                                                                       
) 1>C:\chef\wget.vb

如果我 rdp 進入伺服器並執行相同的第一個命令,它會成功執行。

我發現對此的拉取請求已合併到刀窗 gem 中,但尚未在已發布的 gem 中。我通過安裝 specific_install gem 並使用它從 github 上的源安裝來解決我的問題。

gem install specific_install
gem specific_install -l https://github.com/opscode/knife-windows.git

引用自:https://serverfault.com/questions/470129