Jason Nicholson
Jason Nicholson

Reputation: 178

Execute a batch file before executing in a shortcut (.lnk)

I have multiple versions of a program called Siemens NX. NX uses environmental variables for configuration. I need NX 10.0 to use a different set of environmental variables than my NX 7.5 which uses the system environmental variables. Therefore, I have written a batch file that setups the environmental variables that I need. However, There is a lot of different programs that go with NX 10.0. I don't want to have to create a batch file for each program. Instead, I just want to ammend the shortcuts (.lnk) to execute a batch file before starting. For instance, this is easily done by

C:\Siemens\NX10\UGII\setup_NX10_environment.bat && C:\Siemens\NX10\UGII\ugraf.exe -nx

However, the command window is left open. How can I call the batch script and it closes and then calls my program?

Upvotes: 1

Views: 2398

Answers (2)

Zenadix
Zenadix

Reputation: 16279

The console window may remain open if you call the executable like this:

executable.exe

However, prepending start to the executable will detach it from the console. Thus the console will not remain open if you call the executable like this:

start executable.exe

In conclusion, rewrite your command as follows:

C:\Siemens\NX10\UGII\setup_NX10_environment.bat && start C:\Siemens\NX10\UGII\ugraf.exe -nx

Upvotes: 2

JosefZ
JosefZ

Reputation: 30153

Supply program with parameters to your batch script as follows

C:\Siemens\NX10\UGII\setup_NX10_environment.bat "C:\Siemens\NX10\UGII\ugraf.exe" -nx

and improve that batch as follows:

rem all the original setup_NX10_environment.bat stuff here
%*
exit

or

rem all the original setup_NX10_environment.bat stuff here
call %*
exit

or

rem all the original setup_NX10_environment.bat stuff here
start "" %*
exit

Upvotes: 2

Related Questions