Search code examples
windowsbatch-filelnk

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?


Solution

  • 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