- NSIS Discussion
- variable as shortcut...howto
Archive: variable as shortcut...howto
razor_x
26th May 2004 17:34 UTC
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.
zimsms
26th May 2004 17:40 UTC
Use the CreateShortcut command. For example:
CreateShortCut "$DESKTOP\Shortcut Name.lnk" "$INSTDIR\My.exe"
razor_x
26th May 2004 17:44 UTC
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....
zimsms
26th May 2004 17:59 UTC
Var "MyVar"
in .OnInit
StrCpy $MyVar ""
in a section/function/macro
StrCpy $MyVar "Shortcut Name"
CreateShortCut "$DESKTOP\$MyVar.lnk" "$INSTDIR\My.exe"
razor_x
27th May 2004 16:19 UTC
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?
zimsms
27th May 2004 16:44 UTC
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.
evilO
27th May 2004 16:58 UTC
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
zimsms
27th May 2004 17:12 UTC
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.
razor_x
27th May 2004 17:15 UTC
thxz alot guys! got it working and learned a few things in the process...
evilO
27th May 2004 17:35 UTC
Cool, so we all made our day ;) !
evilO/Olive
razor_x
27th May 2004 17:44 UTC
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?
zimsms
27th May 2004 18:15 UTC
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
razor_x
27th May 2004 18:19 UTC
thxz again :)
zimsms
27th May 2004 18:20 UTC
Your Welcome!
razor_x
27th May 2004 18:56 UTC
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.
razor_x
28th May 2004 06:30 UTC
nvm...
found this function in the archive and works great.
get last directory part
please excuse my newbness.
zimsms
28th May 2004 13:45 UTC
Not a problem, learning something new is always a challenge; especially under deadlines!