RunProgram() with a shortcut .lnk

Just starting out? Need help? Post your questions and find answers here.
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

RunProgram() with a shortcut .lnk

Post 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
Image Image
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post 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.
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post 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.
Image Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Code: Select all

RunProgram(GetEnvironmentVariable("COMSPEC"),"/c C:\myprogram.exe.lnk","c:\") 
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Vista or XP Straker ?

ts-soft's solution works fine here on Vista.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

For info, i tried the line of TS-SOFT on W2000 8)
I tried this on a shortcut Visual basic :oops:

At the beginning, it don't works :cry:
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

Code: Select all

vb6.lnk = VB6.lnk 
ImageThe happiness is a road...
Not a destination
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

why bother to run it by activating a shortcut to begin with? Why not just run the application file directly?
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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 :wink:
Decidedly, i don't know if a day, i feel all the delicacy of the programming :oops:
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:
ImageThe happiness is a road...
Not a destination
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post 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.
Image Image
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Re: RunProgram() with a shortcut .lnk

Post 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))
LSI
Post Reply