好的,我是一名 C# 程序员,正在尝试简化我继承的自定义 Windows 窗体应用程序的部署,并使用 WiX 为其构建了一个安装程序(由于我正在对其进行更改,因此需要定期重新安装此应用程序)。我并不习惯管理类型的东西(或 vbs、WMI、终端服务器、Citrix,甚至 WiX 和 MSI 也不是我通常处理的东西),但到目前为止,我整理了一些 vbs,并有一个最终目标。msi 确实有效,我已经从开发机器上的映射 O: 驱动器安装了它,同时通过 RDP 连接到 citrix 机器。
最终目标:将在我的开发机器上编写并编译成 MSI 的代码(我可以在 WiX 的范围内以及 Windows 安装程序引擎允许的任何范围内对其进行改进)部署到我的用户可以访问的 Citrix 机器集群中。
我的脚本中缺少什么来让 MSI 在远程机器上执行?
布局:
- 机器 A 是我的开发机器,并且有 vbs 脚本和 msi 文件(XP SP3)
- 机器 C1 - C6 是 Citrix 服务器,需要通过 msi (Server 2003 R2 SP2) 安装应用程序
- 还可以选择所有机器都可以访问的共享网络资源。
脚本:
'Set WMI Constants
Const wbemImpersonationLevelImpersonate = 3
Const wbemAuthenticationLevelPktPrivacy = 6
'Set whether this is installing to the debug Citrix Servers
Const isDebug = true
'Set MSI location
'Network location yields error 1619 (This installation package could not be opened.)
msiLocation = "\\255.255.255.255\odrive\Citrix Deployment\Setup.msi"
'Directory on machine A yields error 3 (file not found)
'msiLocation = "C:\Temp\Deploy\Setup.msi"
'Mapped network drive (on both machines) yield error 3 (file not found)
'msiLocation = "O:\Citrix Deployment\Setup.msi"
'Set login information
strDomain = "MyDomain"
Wscript.StdOut.Write "user name:"
strUser = Wscript.StdIn.ReadLine
Set objPassword = CreateObject("ScriptPW.Password")
Wscript.StdOut.Write "password:"
strPassword = objPassword.GetPassword()
'Names of Citrix Servers
Dim citrixServerArray
If isDebug Then
citrixServerArray = array("C4")
Else
'citrixServerArray = array("C1","C2","C3","C5","C6")
End If
'Loop through each Citrix Server
For Each citrixServer in citrixServerArray
'Login to remote computer
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(citrixServer, _
"root\cimv2", _
strUser, _
strPassword, _
"MS_409", _
"ntlmdomain:" + strDomain)
'Set Remote Impersonation level
objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
'Reference to a process on the machine
Dim objProcess : Set objProcess = objWMIService.Get("Win32_Process")
'Change user to install for terminal services
errReturn = objProcess.Create _
("cmd.exe /c change user /install", Null, Null, intProcessID)
WScript.Echo errReturn
'Install MSI here
'Reference to a product on the machine
Set objSoftware = objWMIService.Get("Win32_Product")
'All users set in option parameter, I'm led to believe that the third parameter is actually ignored
'http://www.webmasterkb.com/Uwe/Forum.aspx/vbscript/2433/Installing-programs-with-VbScript
errReturn = objSoftware.Install(msiLocation,"ALLUSERS=2 REBOOT=ReallySuppress",True)
Wscript.Echo errReturn
'Change user back to execute
errReturn = objProcess.Create _
("cmd.exe /c change user /execute", Null, Null, intProcessID)
WScript.Echo errReturn
Next
我也尝试使用它来安装,它没有返回错误代码,但也没有安装 msi,这让我怀疑更改用户/安装命令是否真的有效。
errReturn = objProcess.Create _
("cmd.exe /c msiexec /i ""O:\Citrix Deployment\Setup.msi"" /quiet")
Wscript.Echo errReturn
@tony 文件复制得很好,但是我得到了这个:
ERROR:
Code = 0x80070005
Description = Access is denied.
Facility = Win32
我需要为 Citrix 机器使用另一个用户帐户(尽管是同一个域),这就是我使用的原因:
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer( .....
我最终根据 tony 的意见和建议使用了 powershell 脚本,它看起来和运行起来更加简洁。
尽管获取 Win32_Product 类安装方法仍然看起来有点复杂(与 WMIC 命令相比),但它是 Technet 建议的:
关联 http://technet.microsoft.com/en-us/library/dd347651.aspx
#$servers = 'C1' , 'C2', 'C3' , 'C5', 'C6'
$servers = , 'C4'
$MyCredential = Get-Credential MyDomain\otherusername
foreach($server in $servers)
{
Copy-Item -LiteralPath C:\Temp\Deploy\Setup.msi -Destination \\$server\c$\Temp\Setup.msi -Force
(Get-WmiObject -ComputerName $server -Credential $MyCredential -List | `
Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install("C:\TEMP\Setup.msi")
}
答案1
一方面,Citrix 有自己的部署技术,其次,您是说您的部署方法在某种程度上失败了吗?如果是这样,我预计这是一个模拟问题。但从您的解释中我真的看不出来。
以下是您拥有的所有代码的快捷方式
1st
复制 file.msi \citrixservername\c$\pathtoyourfile
wmic /node:citrixservername 产品调用安装 true,“”,“c:\PathToYour\File.msi”
请注意,安装文件首先被复制到本地服务器,如果不这样做,您将遇到模拟问题!