1
votes

I want to use the name of the computer where the msi is running in a customaction to execute a batch file that is deployed with the msi file in a directory that is the same as the computername.

For example, after installation of the msi on a machine named: 'MyServer' the directory looks like: C:\program files\MyApp\Config\MyServer\Config.bat

I want to run the Config.bat file after installation, so i came up with custom action

<CustomAction
     Id="CONFIGURE"
     Directory="INSTALLFOLDER\Config\[COMPUTERNAME]"
     ExeCommand="Configure.bat"
     Execute="deferred"
     Return="ignore" />

  <InstallExecuteSequence>
     <Custom Action="CONFIGURE"
             After="InstallFiles" />
  </InstallExecuteSequence>

Now i need the real computername instead of the [COMPUTERNAME].

Or something like this:

  <CustomAction
     Id="CONF"
     Directory="INSTALLFOLDER"
     ExeCommand="\Config\[COMPUTERNAME]\Configure.bat"
     Execute="deferred"
     Return="ignore"
     HideTarget="no"
     Impersonate="no" />

The above examples looks better, but at installation the log file tells me:

Action: CONF, location: c:\Program Files (x86)\MyApp\, command: \Config\\Configure.bat 

So the computername is empty...

+++ Finally thanks to the one Dusan Plavak, the solution is:

  <CustomAction
     Id="CONF"
     Directory="INSTALLFOLDER"
     ExeCommand="\Config\[ComputerName]\Configure.bat"
     Execute="deferred"
     Return="ignore"
     HideTarget="no"
     Impersonate="no" />
  <InstallExecuteSequence>
     <Custom Action="CONF"
             After="InstallFiles" />
  </InstallExecuteSequence>
1

1 Answers

2
votes

You should use ComputerName instead of COMPUTERNAME

so for example you can copy ComputerName to COMPUTERNAME name using custom action"

<CustomAction Id="SetMachineName" Property="COMPUTERNAME" Value="[ComputerName]" Execute="immediate"></CustomAction>