cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Whiteway
Level 3

Can I run DOS commands during installation?

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 127.0.0.1 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.
Labels (1)
0 Kudos
(7) Replies
Kelter
Level 10

basic msi or installscript project type?
0 Kudos
Whiteway
Level 3

Basic MSI project.
0 Kudos
Kelter
Level 10

launch the custom action wizard.

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

that should do it!
0 Kudos
Whiteway
Level 3

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 127.0.0.1 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?
0 Kudos
Kelter
Level 10

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.
0 Kudos
Whiteway
Level 3

That was just an error when I copied it over to the post, sorry about that. It is correct in my project.
0 Kudos
Whiteway
Level 3

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?
0 Kudos