使用 WMI 在 Citrix 伺服器上遠端安裝 msi

使用 WMI 在 Citrix 伺服器上遠端安裝 msi

好的,我是C# 程式設計師,正在嘗試簡化我繼承的自訂Windows 窗體應用程式的部署,並使用WiX 建置了一個安裝程式(當我對其進行更改時,需要定期重新安裝該應用程式程式).我不太習慣管理類型的東西(或者vbs,或者WMI,或者終端伺服器,或者Citrix,甚至WiX和MSI都不是我通常處理的東西),但到目前為止我把一些vbs放在一起並有一個最終目標心裡。 msi 確實可以工作,我已經從我的開發電腦上的映射 O: 驅動器安裝了它,同時透過 RDP 安裝到了 Citrix 電腦。

最終目標:將在我的開發電腦上編寫並編譯為 MSI(我可以在 WiX 和 Windows Installer 引擎允許的範圍內進行改進)的程式碼部署到我的使用者有權存取的 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( .....

我最終根據托尼的輸入和建議使用了一個 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有自己的部署技術,其次你是說你的部署方法在某種程度上失敗了?如果是這樣,我預計這是一個冒充問題。但從你的解釋我實在看不出來。

以下是您擁有
第一個
副本 file.msi \citrixservername\c$\pathtoyourfile的所有程式碼的捷徑

wmic /node:citrixservername 產品呼叫安裝 true,"" , "c:\PathToYour\File.msi"

請注意,安裝檔案首先複製到伺服器本地,如果您不這樣做,您將遇到模擬問題!

相關內容