Page 1 of 1
RunProgram() with a shortcut .lnk
Posted: Tue Dec 30, 2008 9:12 pm
by Straker
I have a shortcut link "myprogram.exe" which is actually "myprogram.exe.lnk", but RunProgram("myprogram.exe") returns 0, and RunProgram("myprogram.exe.lnk") returns 1 but does not run the shortcut like when I click it from explorer. Instead it launches 7-zip!??
Is there a trick to running shortcuts from RunProgram or am I missing something simple?
Thanks
Posted: Tue Dec 30, 2008 9:35 pm
by Mistrel
That's very strange. I have a hotkey program I wrote which launches .lnk files just fine.
Try this as an alternative:
Code: Select all
%comspec% /c c:\program_name.exe.lnk
You should not have to do this though. Some antivirus programs will also issue an alert if another program tries to launch cmd.exe.
Try launching the program in quotes? I don't think this is the problem either.
Posted: Tue Dec 30, 2008 10:31 pm
by Straker
I tried:
Code: Select all
RunProgram("%comspec%","/c C:\myprogram.exe.lnk","c:\")
But it gave an error that it could not find "%comspec%", so I changed it to "cmd.exe" and it now works fine.
Thanks for the tip.
Posted: Tue Dec 30, 2008 10:36 pm
by ts-soft
Code: Select all
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c C:\myprogram.exe.lnk","c:\")
Posted: Wed Dec 31, 2008 2:02 am
by SFSxOI
Vista or XP Straker ?
ts-soft's solution works fine here on Vista.
Posted: Wed Dec 31, 2008 9:18 am
by Kwai chang caine
For info, i tried the line of TS-SOFT on W2000
I tried this on a shortcut Visual basic
At the beginning, it don't works
Then i say to me, it's the fault at BILL GATES
But no, it's the fault at KCC
Because i learn that this line, don't works, if the shortcut have a point and/or have a space.
Example don't works:
Code: Select all
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c C:\vb 6.lnk","c:\")
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c C:\vb6.0.lnk","c:\")
Example works:
Code: Select all
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c C:\vb6.lnk","c:\")
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c C:\VB6.lnk","c:\")
UpperCase/LowerCase has not sensible
Posted: Wed Dec 31, 2008 1:40 pm
by SFSxOI
why bother to run it by activating a shortcut to begin with? Why not just run the application file directly?
Posted: Wed Dec 31, 2008 1:45 pm
by mback2k
Try the following:
Code: Select all
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c "+Chr('"')+"C:\vb 6.lnk"+Chr('"'),"c:\")
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c "+Chr('"')+"C:\vb6.0.lnk"+Chr('"'),"c:\")
You need to put program parameters with spaces or punctuation into doublequotes.
Posted: Wed Dec 31, 2008 2:07 pm
by Kwai chang caine
mback2k wrote:Try the following:
Code: Select all
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c "+Chr('"')+"C:\vb 6.lnk"+Chr('"'),"c:")
RunProgram(GetEnvironmentVariable("COMSPEC"),"/c "+Chr('"')+"C:\vb6.0.lnk"+Chr('"'),"c:")
You need to put program parameters with spaces or punctuation into doublequotes.
Yes, you are right , thanks for this tips
Decidedly, i don't know if a day, i feel all the delicacy of the programming
SFSxOI wrote:why bother to run it by activating a shortcut to begin with? Why not just run the application file directly?
You are right, i ask me the same question in my little head :roll:
Posted: Fri Jan 02, 2009 12:33 am
by Straker
Thanks for all the feedback.
To answer a couple questions: Windows 2000 for this particular instance.
SFSxOI wrote:why bother to run it by activating a shortcut to begin with? Why not just run the application file directly?
Because the shortcut contains specific parameters. I have several .lnk files which all point to the same main exe but with different INI files specified as parameters. I also have a monitor program which manages those instances and sometimes needs to re-launch the main exe, so I just want the monitor app to relaunch the shortcut.
Re: RunProgram() with a shortcut .lnk
Posted: Sat Oct 24, 2009 10:48 am
by Le Soldat Inconnu
i find solution
it's something totally crazy, viva microsoft !
you have to replace "\" by "\\" in shortcut path
like this, and it's work (on XP)
Code: Select all
File.s = "D:\PureBasic\Développements\Utilitaires\Barre & Menu\Barre & Menu.lnk"
RunProgram(ReplaceString(File, "\", "\\", 0, 3))