為 SCCM 建立腳本包裝器

為 SCCM 建立腳本包裝器

假設我已將文件保存在桌面上,如何建立腳本包裝器來卸載以下字串uninst_setup.iss

C:\Program Files\InstallShield Installation Information\{4D9CA1B8-5FF5-47A7-8BDF-C37D1F9F55A5}\setup.exe" -l0x9 -removeonly -uninst /s /f1"c:\temp\uninst_setup.iss" /f2"c:\temp\setuppec.log

如果我將文件複製uninst_setup.issc:\temp然後在cmd.

我只需要創建一個包裝器的幫助,以便透過 SCCM 一次卸載它。

答案1

您不應該使用硬編碼的臨時目錄。下面的程式碼可以幫助你。請注意使用 SCCM(系統帳戶)執行此命令,臨時目錄將解析為 %windir%\temp。

將包含以下程式碼的腳本(例如 uninstaller.vbs)和 iss 檔案加入 SCCM 套件中。使用以下命令建立程式:cscript.exe uninstaller.vbs

set wsh_shell = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")

dq = chr(34)
source_path = fso.getparentfoldername(wscript.scriptfullname)
tmp_folder = fso.getSpecialFolder(2)
iss_file = "uninst_setup.iss"
log_file = "setuppec.log"

' Copy the iss file to the temp folder.
fso.copyFile fso.buildPath(source_path, iss_file), tmp_folder, true

' Build the command line
cmd = dq &"C:\Program Files\InstallShield Installation Information\{4D9CA1B8-5FF5-47A7-8BDF-C37D1F9F55A5}\setup.exe" &dq
cmd = cmd &" -l0x9 -removeonly -uninst /s /f1" &dq &fso.buildpath(tmp_folder, iss_file) &dq
cmd = cmd &" /f2" &dq &fso.buildpath(tmp_folder, log_file) &dq

' Run commandline and return exit code to sccm.
wscript.quit wsh_shell.run(cmd, 0, true)

相關內容