0

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?

0

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:\Windows\System32\cmd.exe /c ""C:\Users\\Path To Exe\myProgram.exe" -ldir "%cd%""

See: https://ss64.com/nt/cmd.html

  • C:\Windows\System32\cmd.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 '18 at 15:34
  • Solved. C:\Windows\System32\cmd.exe /c ""C:\Users\<USER>\<PathToExe>\myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html – Joseph Kreifels II Nov 21 '18 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.