shortcut links not taking the %cd% parameter in the target field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi:

First off before jumping into my problem, I apologize for the
cross-posting of this message. Cross-posting is not my norm. For
this case, I wasn't really sure who to ask, so I cross-posted. (For
those of you in the DotNet Framework newsgroup, you've provided so
much help to me so far with this project, that I figured the odds that
some of you probably have come up with this issue and found a
workaround. I haven't dived into the .NET installer classes, so if
they deal with providing programmable shortcuts, that information
would also solve my problem. I do apologize though, for this topic
that really is off the .NET path.)

I'm designing an application that relies on resources in a
subdirectory of the actual executable ("Pictures" subdirectory for
example).

Originally I just used relative paths. However, when using a
FileOpenDialog (.NET 1.1 SDK)to get a picture, it seemed to change my
directory to the directory of the file to open. Relative directories
were not working when the current directory was switched. It looked
like I needed to use absolute directories. However, I didn't want to
hardcode absolute directories because I couldn't be sure of the actual
path my application would be installed into.

To solve this, I setup directories at the beginning of the
application, prepending the string received from
Directory.GetCurrentDirectory() to the actual path string. This has
worked fine to solve that problem.

Now, however, I'm trying to create shortcuts to my application which
can be either put on the desktop or in the start menu. The problem
that is arising now is that the directory string returned from
Directory.GetCurrentDirectory() is actually the directory of the
shortcut instead of the application.

At the moment, I'm putting the shortcut in a higher directory than the
executable. To change this dynamically, i've set the target location
in the shortcut to %cd%\IFTApp\bin\Debug\IFTApp.exe and the start in
location to %cd%\IFTApp\bin\Debug.

I've echoed the start in location from the command line inside the
directory where the shortcut is in, and it prints out the exact
position of the directory holding my executable. However, when I try
to add the line above to the target location, I get an error that the
string '%cd%\IFTApp\bin\Debug\IFTApp.exe' is not valid. (It should be
noted that if I leave the absolute paths in here, as the shortcut
allows for, the program starts fine and finds the link to the
"Pictures" subdirectory).

I've used the %cd% in the start in field of a shortcut successfully to
start a command prompt with the current directory location on the
command line. It works fine. And, I've noted that all the shortcuts
to the cmd.exe file all use the %windir%\System32\cmd.exe string (XP
pro) and it reads it fine. So, why won't it read the %cd% parameter?

If this is not within the scope of a shortcut, what options are there
to set a shortcut to dynamically start in a relative directory in a
way that if you move the exe and shortcut to another location, the
relative path information stays the same.

I probably could write a routine that progammatically modifies the lnk
file to replace the startup string with the new startup location, but
I'd rather not have to go that deep if there is a more logical
alternative.
 
%CD% is not an environment variable. It's a special feature of
cmd.exe. See the end of

cmd /?

for a discussion.
 
I'm designing an application that relies on resources in a
subdirectory of the actual executable ("Pictures" subdirectory for
example).
[...]

Am I missing something or you just didn't know about
GetModuleFileName() function? At any point in your code you can
determine path of executable module, then calculate path for any
relative subdirectory from that. I don't know about .NET counterpart
for GetModuleFileName, but I'm sure it exists.

HTH
Alex
 
Back
Top