Skip to content
⌘ NSIS Forum Archive

Launch a program by accessing it's link from STARTUP

17 posts

Chilli24#

Launch a program by accessing it's link from STARTUP

I want to launch a program by accessing it's link from STARTUP. I have tried this code, but it doesn' work. Anybody now what's the solution?

ClearErrors

ReadRegStr $startup HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Startup"

nsExec::Exec '$startup\launchthis.lnk'
Afrow UK#
Yes you need to use ExecShell

Exec is for exe files.
nsExec::Exec is for command-line applications (mostly).

-Stu
Chilli24#
OK. I tried this:
ExecShell "open" '$SMSTARTUP\merge.lnk'
And it didn't work.
What's the scenario: I have a text document named merge.txt that has a shortcut into the STARTUP folder. How do I execute that shortcut ?
flizebogen#
If you made the shortcut within your installer why would you execute the shortcut to open a text file? There a different ways to open it. Try one of these:

- ExecShell "open" "Path\to\Textfile"
- Exec "Notepad.exe" "Path\to\Textfile"
Chilli24#
I've not made the shortcut within my installer. The shortcut exists on the user's computer. Any ideas now?
flizebogen#
perhaps this helps:

SetShellVarContext All/current

; you should set the above to the correct value. If not it can happen that it starts in the wrong location

ExecShell "" '$SMSTARTUP\merge.lnk'

; if open is not the default action
Chilli24#
I've tried both SetShellVarContext current and SetShellVarContext All with
ExecShell "" '$SMSTARTUP\merge.lnk' and ExecShell "open" '$SMSTARTUP\merge.lnk'
It still doesn't anything. I'm very confused.
flizebogen#
The question is does your open command point to the correct location or has nsis a problem to start link files.

Perhaps you should ensure that you point to the correct location using the command "IfFileExists"
Chilli24#
The $SMSTARTUP points to the right location because I've read the path to Startup directly from the registry and it's the same as $SMSTARTUP. So this is not the problem.
flizebogen#
I tested it now and for me it works.


OutFile "test.exe"

Section ""
SetShellVarContext current
IfFileExists "$SMPROGRAMS\7-Zip\7-Zip File Manager.lnk" file_exists
MessageBox MB_OK "File not found"
Goto Ende

file_exists:
ExecShell "open" "$SMPROGRAMS\7-Zip\7-Zip File Manager.lnk"
ende:
SectionEnd
In my test it worked with ExecShell open and ExecShell ""
Chilli24#
OK. I've tried this and it doesn't work.
SetShellVarContext current
IfFileExists "$SMPROGRAMS\NSIS\NSIS Menu.lnk" file_exists
MessageBox MB_OK "File not found"
Goto Ende
file_exists:
ExecShell "open" "$SMPROGRAMS\NSIS\NSIS Menu.lnk"
ende:

I've also tried:
ExecShell "" "$SMPROGRAMS\NSIS\NSIS Menu.lnk"

It doesn't say that the file does not exist but it doesn't do anything.
Chilli24#
On XP SP2 it didn't work. On 2000 server it works. I'll have to see it works on 2003 server too. Everybody, thanks for your help.