Page 1 of 1

ShellExecute in PB, open files as well as programs.

Posted: Mon Jun 11, 2007 2:09 pm
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.

Posted: Mon Jun 11, 2007 2:24 pm
by ts-soft
Is the same as RunProgram :wink:

Posted: Mon Jun 11, 2007 2:36 pm
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.

Posted: Mon Jun 11, 2007 2:49 pm
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

Posted: Mon Jun 11, 2007 3:06 pm
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.

Posted: Mon Jun 11, 2007 3:12 pm
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.

Posted: Mon Jun 11, 2007 6:40 pm
by Kale
IIRC, RunProgram wraps ShellExecute, so its the same.

Posted: Mon Jun 11, 2007 6:56 pm
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

Posted: Mon Jun 11, 2007 6:58 pm
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().

Posted: Mon Jun 11, 2007 7:01 pm
by ts-soft
>> Are you sure?
No. But wraps the shellexecute-api the create-process-api? :wink:

Posted: Mon Jun 11, 2007 7:30 pm
by eJan
@vanbeck a shorter way:

Code: Select all

ShellExecute_(#Null, #Null, "C:\Backup Job.bms", #Null, #Null, #SW_SHOWNORMAL)

Posted: Tue Jun 12, 2007 7:28 am
by vanbeck
Ahh, cool, I was wondering how to represent null in PB.

Thanks for all the input, sorry for the pointless post!

Posted: Tue Jun 12, 2007 10:28 am
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.