如何从.msi执行.bat而不在.msi本身中包含.bat?

时间:2012-08-02 11:13:46

标签: wix windows-installer

我的目标是创建一个简单的msi包,除了运行与.msi位于同一文件夹中的.bat脚本之外什么都不做。我不需要复制目标计算机上的任何文件或创建文件夹等。我尝试使用Wix 3.5和vb-script,它将运行我需要的.bat。 vb代码本身运行得很好,但在.msi内部以奇怪的方式运行 - 我可以看到一个带有“路径”的消息框,我没有错误,但脚本没有执行。蝙蝠。

 <Property Id="Launch">
  <![CDATA[
  Function Main()
    Set shell = CreateObject("WSCript.shell") 
    path = Session.Property("SourceDir") 
    MsgBox path
    shell.Run path & "sample.bat", 0, False
    Set shell = Nothing
    Main = 1
  End Function
  ]]>
</Property> 
<CustomAction Id="Die"
              VBScriptCall="Main"
              Property="Launch"                   
              Return="check"              
              Impersonate="yes"/>

  <InstallExecuteSequence>
     <Custom Action='Die' Before='RegisterProduct'> NOT Installed </Custom>  
  </InstallExecuteSequence> 

我还尝试了另一种方式:

<Property Id='CMD'>cmd.exe</Property>
  <CustomAction Id='LaunchFile' Property='CMD' ExeCommand='[SourceDir]sample.bat' Return='check' Impersonate='yes'/> 

但是如果我把&#39; notepad.exe&#39;在财产 - 当我使用&cmd.exe&#39;控制台打开和关闭,而不执行我的sample.bat。对于&#39; notepad.exe&#39;,它会显示&#39; sample.bat&#39;的内容。你能帮助我吗?

2 个答案:

答案 0 :(得分:2)

尝试将/C添加到ExeCommand

<CustomAction Id='LaunchFile' Property='CMD' ExeCommand='/C [SourceDir]sample.bat' Return='check' Impersonate='yes'/>

答案 1 :(得分:1)

嗯,这很容易......实际上,一切都还可以,但.bat本身正在计算%WinDir%\System32\的相对路径我只是将CD %~dp0作为我的.bat的第一行并且它开始了工作正常。