Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 14th December 2004, 16:51   #1
EricVogl
Junior Member
 
Join Date: Dec 2004
Posts: 2
Send a message via AIM to EricVogl
Creating a Shortcut using an Environment Variable in the Target field - possible bug?

Hi all,

I'm using an environment variable in the CreateShortCut function's second argument (target.file) as the path for the target file. The function succeeds; however, when I examine the shortcut it appends "C:\" to the beginning of the target field string.

For example, define the environment variable FOO to be "C:\some_path"

Create a script:
CreateShortCut "$DESKTOP\foo.lnk" "%FOO%\some_exe.exe"

This will create a shortcut on the desktop with a target field defined as
"C:\%FOO%\some_exe.exe"

which resolves to "C:\C:\some_path\some_exe.exe"

If I were to remove the extra "C:\", the shortcut will work fine.

To create the environment variables, I'm using the sample code found on the NSIS website. This code is working fine. The environment variables are properly being created and deleted on uninstall. I've also tried this with manually created environment variables.

I've tried to work around this problem by setting the "Start In" folder (ie. the working directory) to the directory defined in %FOO%.

SetOutPath "%FOO%"
CreateShortCut "$DESKTOP\foo.lnk" "some_exe.exe"

However, the shortcut fails to create at run time, presumably because it is not a fully qualified path name (even though the working directory is defined to the directory where the program resides).

Any idea why the extra "C:\" is being appended? I looked quickly through the NSIS source code and I can't see where NSIS is possibly appending this. I assume it must be Windows doing this when the ShellLink object is passed parameters in exec.c line 990 (NSIS v2.01). Maybe the code should be setting the working directory before it is setting the path (then maybe the workaround would work)?

Thanks for any help,
Eric
EricVogl is offline   Reply With Quote
Old 14th December 2004, 18:37   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
It seems to do it when it the environment variable can't be found. Make sure you set the variable for the current process too. There is an Archive page with such an example.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 14th December 2004, 18:55   #3
EricVogl
Junior Member
 
Join Date: Dec 2004
Posts: 2
Send a message via AIM to EricVogl
Thanks kichik. That did the trick. Strange behavior for the failure case though.
EricVogl is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump