2014年7月18日 星期五

[WMI] 詭異的Bug ,虎爛的Best practice - Put install package at tmep folder

圖片來源:Mud Day


太久沒發文,來篇技術抱怨文(咦?),話說最近在跟非常不熟悉的微軟系統奮戰,不熟悉就算了,又必須透過跟他很不合的Java 來透過WMI介面來控制HyperV,一整個就是災難....我的心情就跟上面那張圖一樣....

雖說網路上也有許多強者有嘗試開發Java 透過WMI來控制HyperV的Lib,不過很多都是年代久遠缺乏維護,因此只能抓他的source code 重新來改寫和加功能,有興趣的我把他放在github - JWbem


這幾天遇到一個奇怪的Bug就是透過WMI的Win32_Product來遠端安裝軟體,如果Host 沒有登入(沒有任何登入Session),然後WMI安裝就會發生錯誤,然後錯誤訊息讓然摸不著頭緒,只有return code: 1603 A fatal error occurred during the installation.

上網研究半天只有看到一個類似的討論:MSI Remote Installation Question!

The best way to do a remote msi installation is as follows:
1. Set the access to the remote location if the MSI is stored at a remote location
C:\Windows\System32\net.exe use $RemotePath password /user:username
2. Copy the MSI file to the system you want to install it to.
Create the C:\Temp folder if it doesnot exist
if(!(Test-Path "C:\Temp"))
    {
        New-Item -Path "C:\Temp" -ItemType directory
    }
Copy-Item "$RemotePath" "C:\Temp"
3. Use the WIN32_Product Class in the following way
$product= [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"
4. Now use the install method which otherwise is not shown up when we just use Get-WMIObject cmdlet
$ret = $product.Install("C:\Temp\MyProduct.msi","ADDLOCAL=ALL",$true)

5. If you want you can delete the msi file which you copied to the C:\Temp folder.

程式邏輯全部一樣,唯一的差別就是他建議要安裝在Temp的目錄下.....這..死馬當活馬醫...
我就把安裝檔放在c:\windows\temp\

這樣就可以了...這樣就可以了....囧rz...


[Update]

後來發現我以為這個Best Practice work...但事實上還是不行!! 只是前一個Seesion可能還在?

無奈啊...繼續找解法...



沒有留言 :