Archive: variable as shortcut...howto


variable as shortcut...howto
i have an unstaller with several sections all but one are optional.I know i can use getsectionflags to create a specified shortcut,by the section selected.But how would i create a variable named shortcut,based on $INSTDIR?...for example they install to c:\blahblah...i want to make a short cut on the desktop to c:\blahblah c:\whatever.exe.


Use the CreateShortcut command. For example:

CreateShortCut "$DESKTOP\Shortcut Name.lnk" "$INSTDIR\My.exe"


thanks for the reply..but i cant use...

CreateShortCut "$DESKTOP\Shortcut Name.lnk" "$INSTDIR\My.exe"
as "shortcut name" would have to be a variable defined at run time not compile time.

hence my question....

Var "MyVar"

in .OnInit
StrCpy $MyVar ""

in a section/function/macro
StrCpy $MyVar "Shortcut Name"
CreateShortCut "$DESKTOP\$MyVar.lnk" "$INSTDIR\My.exe"


thxz for the reply again.But that wont help me I cant define "shortcut name" i want that to be defined by the user.Somehow have the shortcut be linked to the $INSTDIR by a variable...the exe is always the same but i would like the shortcut named after the folder..anyway to do this?


In my previous post you can specify what the name of the shortcut is by populating the variable; for example:

StrCpy $MyVar "Shortcut Name"

The value within the quotes could be any value specified at runtime or compile time. All you need to do is populate it.

For example; if you wanted to make the shortcut name equal $INSTDIR, then do this:

StrCpy $MyVar "$INSTDIR"

If you want it to hold some value from the registry then do this:

ReadRegStr $0 "HKLM" "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "ProductName"
StrCpy $MyVar "$0"

If you want to get the value from the user, you will need to use the InstallOptions to define a custom page that populates $MyVar with the value you are trying to obtain.


Hi :)

@zimsms: right, except that a shortcut can't contain special characters, as ':' and '\'.

@razor_x: Assuming your installation directory is at the drive's root, this will remove the first 3 characters and create the shortcut:

StrLen $R0 $INSTDIR
StrCpy $R1 $INSTDIR $R0 3

CreateShortCut "$DESKTOP\$R1.lnk" "$INSTDIR\My.exe"


For instance, if the installation directory is "c:\blahblah", the shortcut will be named "blahblah"

Will that do ??

evilO/Olive


True enough evilO! I didn't want to confuse razor_x with string functions. But that is a valid point. All illegal characters will have to be stripped out of the string.


thxz alot guys! got it working and learned a few things in the process...


Cool, so we all made our day ;) !

evilO/Olive


just one more question if i had to install to other than the root..could it be done some way?

for example c:\blah works well but what about...c:\program files\blah?


Yes you could do that, use the reverse string search for "\" or "/" depending on the platform, the resulting value would be the very last folder name. See the string functions in the NSIS Archive.

I believe it was the "Advanced Search in String" function

Archive:String Functions


thxz again :)


Your Welcome!


well i tried advancedstrstr and doesnt work well for me and i'll tell you why...

Push 0 ;Loops Quantity (0 for one code execution, only accept positive numbers)
the amount of "\" must be known for this code to work...

If push
Push 1 ;Loops Quantity
then C:\blah works fine...

but if c:\program files\blah

does not work.

so again how too define this shortcut as a true variable...with as MANY or FEW backslashes as is inputed...or is there even a way?i'm thinking there is not a way but there should be.

nvm...

found this function in the archive and works great.

get last directory part

please excuse my newbness.


Not a problem, learning something new is always a challenge; especially under deadlines!