ShellExecute in PB, open files as well as programs.

Share your advanced PureBasic knowledge/code with the community.
vanbeck
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jun 11, 2007 1:31 pm
Location: The Swan

ShellExecute in PB, open files as well as programs.

Post by vanbeck »

Hi all, my first post!

Total newbie here so forgive me if this is not the right place, or if it's already been posted as a better snippet.

Code: Select all

Procedure shell(file$)
;ShellExecute(hwnd, NullString,FILE,NullString,"",ShowMode)
  If OpenLibrary(0, "shell32.dll")
    shell = GetFunction(0, "ShellExecuteA")
    CallFunctionFast(shell, 0, "", file$,"","",3)
    CloseLibrary(0)     
  EndIf
EndProcedure
Just call the procedure with your filename as the only parameter.
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 »

Is the same as RunProgram :wink:
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
vanbeck
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jun 11, 2007 1:31 pm
Location: The Swan

Post by vanbeck »

Nope :) - RunProgram would not let you run a shortcut, or an excel spreadsheet. Well unless it's changed, I couldn't get RunProgram to execute shortcuts or files.
User avatar
Kiffi
Addict
Addict
Posts: 1504
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

RunProgram would not let you run a shortcut, or an excel spreadsheet.

Code: Select all

RunProgram("c:\test.xml")
... and my texteditor starts

Code: Select all

RunProgram("d:\test.mdb")
... and Access starts

;-)

Greetings ... Kiffi
vanbeck
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jun 11, 2007 1:31 pm
Location: The Swan

Post by vanbeck »

Strange one!

It does work with extensions, but for some reason it RunProgram won't work with shortcuts (.lnk).

Thanks for trying to steer me right though guys, I can be a stubborn git sometimes, soz.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> for some reason it RunProgram won't work with shortcuts (.lnk)

Sure it does:

Code: Select all

RunProgram("c:\test.lnk") ; Works fine for me.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

IIRC, RunProgram wraps ShellExecute, so its the same.
--Kale

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 »

Kale wrote:IIRC, RunProgram wraps ShellExecute, so its the same.
Only if the first parameter not a executable, if the first parameter a executable its wraps the createprocess-api
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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

ts-soft wrote:
Kale wrote:IIRC, RunProgram wraps ShellExecute, so its the same.
Only if the first parameter not a executable, if the first parameter a executable its wraps the createprocess-api
Are you sure? I thought it used CreateProcess() always and then if it failed it used ShellExecute().
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 »

>> Are you sure?
No. But wraps the shellexecute-api the create-process-api? :wink:
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
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

@vanbeck a shorter way:

Code: Select all

ShellExecute_(#Null, #Null, "C:\Backup Job.bms", #Null, #Null, #SW_SHOWNORMAL)
vanbeck
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jun 11, 2007 1:31 pm
Location: The Swan

Post by vanbeck »

Ahh, cool, I was wondering how to represent null in PB.

Thanks for all the input, sorry for the pointless post!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Ahh, cool, I was wondering how to represent null in PB.
Like this: 0. #Null is just a constant that is replaced with 0 when the program is compiled.
Post Reply