Add environment variable as a startup argument (Windows)
up vote
0
down vote
favorite
Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.
Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.
The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?
environment-variables file-shortcut
add a comment |
up vote
0
down vote
favorite
Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.
Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.
The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?
environment-variables file-shortcut
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.
Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.
The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?
environment-variables file-shortcut
Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.
Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.
The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?
environment-variables file-shortcut
environment-variables file-shortcut
asked Nov 21 at 14:50
Joseph Kreifels II
185
185
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
It appears I am already doing things right. If I pass in %windir%, it works fine.
I am assuming the variable CD is never set without the help of command prompt.
I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).
EDIT: Solution
I found that you could just start cmd.exe and pass the exe and arguments there.
In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so
C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""
See: https://ss64.com/nt/cmd.html
C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
– Joseph Kreifels II
Nov 21 at 15:34
Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
– Joseph Kreifels II
Nov 21 at 15:43
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It appears I am already doing things right. If I pass in %windir%, it works fine.
I am assuming the variable CD is never set without the help of command prompt.
I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).
EDIT: Solution
I found that you could just start cmd.exe and pass the exe and arguments there.
In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so
C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""
See: https://ss64.com/nt/cmd.html
C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
– Joseph Kreifels II
Nov 21 at 15:34
Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
– Joseph Kreifels II
Nov 21 at 15:43
add a comment |
up vote
0
down vote
It appears I am already doing things right. If I pass in %windir%, it works fine.
I am assuming the variable CD is never set without the help of command prompt.
I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).
EDIT: Solution
I found that you could just start cmd.exe and pass the exe and arguments there.
In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so
C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""
See: https://ss64.com/nt/cmd.html
C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
– Joseph Kreifels II
Nov 21 at 15:34
Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
– Joseph Kreifels II
Nov 21 at 15:43
add a comment |
up vote
0
down vote
up vote
0
down vote
It appears I am already doing things right. If I pass in %windir%, it works fine.
I am assuming the variable CD is never set without the help of command prompt.
I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).
EDIT: Solution
I found that you could just start cmd.exe and pass the exe and arguments there.
In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so
C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""
See: https://ss64.com/nt/cmd.html
It appears I am already doing things right. If I pass in %windir%, it works fine.
I am assuming the variable CD is never set without the help of command prompt.
I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).
EDIT: Solution
I found that you could just start cmd.exe and pass the exe and arguments there.
In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so
C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""
See: https://ss64.com/nt/cmd.html
edited Nov 21 at 15:47
answered Nov 21 at 15:07
Joseph Kreifels II
185
185
C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
– Joseph Kreifels II
Nov 21 at 15:34
Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
– Joseph Kreifels II
Nov 21 at 15:43
add a comment |
C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
– Joseph Kreifels II
Nov 21 at 15:34
Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
– Joseph Kreifels II
Nov 21 at 15:43
C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
– Joseph Kreifels II
Nov 21 at 15:34
C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
– Joseph Kreifels II
Nov 21 at 15:34
Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
– Joseph Kreifels II
Nov 21 at 15:43
Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
– Joseph Kreifels II
Nov 21 at 15:43
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377308%2fadd-environment-variable-as-a-startup-argument-windows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown