假设我已将文件保存在桌面上,我该如何创建脚本包装器来卸载下面的字符串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.iss
如果我将文件复制到c:\temp
然后运行上述字符串,我可以手动卸载该字符串cmd
。
我只需要帮助创建一个包装器,以便通过 SCCM 一次性卸载它。
答案1
您不应该使用硬编码的临时目录。下面的代码可以帮助您。请注意,使用 SCCM(SYSTEM 帐户)运行此程序,临时目录将解析为 %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)