View Full Version : Can I run DOS commands during installation?

11-04-2009, 11:43 AM
I am trying to streamline my product installation as much as possible. One of the things I cannot figure out how to do is run DOS commands during the install process.

One of the tasks that I need to automate is adding a new entry to the Windows hosts file. Here is the command I currently run post-installation:

echo SportsServer >> c:\windows\system32\drivers\etc\hosts

Is there is a way to script this command to run during the installation? That would save me a step each time I setup a customer computer.

Thanks very much for any assistance.

11-04-2009, 04:26 PM
basic msi or installscript project type?

11-04-2009, 04:30 PM
Basic MSI project.

11-04-2009, 04:48 PM
launch the custom action wizard.

Type: launch an Executable
Location: directory table
source: SystemFolder
target: cmd.exe /c echo SportsServer >> %systemroot%\system32\drivers\etc\hosts

that should do it!

11-05-2009, 12:28 PM
That definitely looked like it would work, but I must have missed a step somewhere along the line. I experimented with the Custom Actions a bit more based upon the above information and here is what I have come up with:

If I create a batch file with the script from above, and run it from anywhere on the target computer, it works exactly as expected. So I know that the script is solid.

I monitored the Windows Task Manager during my installation and it doesn't seem like cmd.exe is called because it never shows up in the processes list as I thought it would. I tried changing the script to have the cmd.exe do other menial tasks (copy a file) and none of them completed.

Here are all the settings that I configured for this action:

Working Directory - SystemFolder
Filename & Command Line - cmd.exe /c SportsServer >> %systemroot%\system32\drivers\etc\hosts
Return Processing - Synchronous (Check Exit Code)
In-Script Execution - Immediate Execution
Execution Scheduling - Always Execute

Do I have to add something else to my setup design in order for this to work?

11-05-2009, 05:31 PM
probably need to run "deferred in system context." if a CA needs admin privs to run, it must run deferred in system context.

okay, upon closer inspection, it looks like you forgot to type "echo" immediately following the /c...unless that's just a transcription typo, and you've actually got it right in the project.

11-06-2009, 09:26 AM
That was just an error when I copied it over to the post, sorry about that. It is correct in my project.

11-06-2009, 09:56 AM
No luck with the "deferred in system context".

What if I approached this a different way and instead of running a command line operation I called a .bat file which I included in the project?

I noticed there is a straight-forward way of running an executable that is installed. Can something similar be done with a batch file?