On the different methods of calling wapi_ShellExecute()

782 views
Skip to first unread message

Davaoz Best

unread,
Jan 13, 2015, 9:35:16 PM1/13/15
to harbou...@googlegroups.com
Hi All,

I want to share what I just discovered regarding the various ways of calling wapi_ShellExecute(). The following worked for me. I'm using Windows 8.1:

     1. To open Notepad:  wapi_ShellExecute( 0, "Open", "notepad.exe", cPath+Filename, "C:\" )

     2. To open Microsoft Word:  wapi_ShellExecute( 0, "Open", cPath+"try.docx" ) 

     3. To open PDF file:  wapi_ShellExecute( 0, "Open", cPath+"try.pdf" )   

     4. To go to Google:  wapi_ShellExecute( 0,"Open","https://www.google.com")

     5. To go to Windows Explorer:  wapi_ShellExecute( 0, "open", "explorer.exe",  , 0, 0 )

     6. To open WordPad:  wapi_ShellExecute(0, "Open", "write.exe",cPath+Filename_openedbyWordPad, "C:\") // e.g. .doc,txt

     7. To open CMD.EXE I used hb_processRun():  hb_processRun( "cmd /c CMD.exe" ) // no need to avoid the "black box" anyway.

Sorry, pure Windows only, don't know Linux. Hope these help.

Regards,

Jun

fdaniele

unread,
Jun 26, 2019, 4:37:17 PM6/26/19
to Harbour Users
thanks very much mr Jun
i need it

:)

Antonino Perricone

unread,
Jun 27, 2019, 3:40:01 AM6/27/19
to Harbour Users
If your program need administrator rights, you can use:
         if !wapi_IsUserAnAdmin()
            wapi_ShellExecute_Wait( Nil, "runas",  HB_ARGV(0), cParams)
            return 0
        endif

 

Pete

unread,
Jun 27, 2019, 6:04:44 AM6/27/19
to Harbour Users
wapi_ShellExecute_Wait() ?

perhaps a UDF that you have implemented for that purpose?

[I don't believe it is a hidden "Easter egg" of our good Harbour we ignore? ;-)]

regrads,
Pete
 

Antonino Perricone

unread,
Jun 27, 2019, 8:04:14 AM6/27/19
to Harbour Users
Well, it is a my version, I forgot I did it :) It is like ShellExecute, but does not return until the executed process finish:

HB_FUNC( WAPI_SHELLEXECUTE_WAIT )
{
  void * hOperation;
  void * hFile;
  void * hParameters;
  void * hDirectory;
  BOOL retVal;
  SHELLEXECUTEINFO ShExecInfo = {0};
  ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  ShExecInfo.hwnd = ( HWND ) hb_parptr( 1 );
  ShExecInfo.lpVerb = HB_PARSTR( 2, &hOperation, NULL );
  ShExecInfo.lpFile = HB_PARSTRDEF( 3, &hFile, NULL );
  ShExecInfo.lpParameters =  HB_PARSTR( 4, &hParameters, NULL );
  ShExecInfo.lpDirectory = HB_PARSTR( 5, &hDirectory, NULL );
  ShExecInfo.nShow = hb_parnidef( 6, SW_SHOWNORMAL );
  ShExecInfo.hInstApp = NULL;
  retVal = ShellExecuteEx(&ShExecInfo);
  hb_retl( retVal );
  while( WaitForSingleObject(ShExecInfo.hProcess,1000) != WAIT_OBJECT_0 )
   {
     SysRefresh();
  }
  hb_strfree( hOperation  );
   hb_strfree( hFile       );
  hb_strfree( hParameters );
  hb_strfree( hDirectory  );
}


anyway my sample works with wapi_ShellExecute too :)

Hazael

unread,
Jun 27, 2019, 12:58:09 PM6/27/19
to Harbour Users
Hi Antonio,

How do you use it to open a .PDF file (as an example), please?
Thanks

Antonino Perricone

unread,
Jun 28, 2019, 3:09:35 AM6/28/19
to Harbour Users
Hello, Open a PDF is written at point 3 of Jun's post...

Jayadev Urath

unread,
Jun 29, 2019, 9:25:55 AM6/29/19
to Harbour Users
Hi Antonino,

Your function WAPI_SHELLEXECUTE_WAIT does not compile and throws a lot of error.  Could you please have a look.

hbwinfunctions.prg: In function 'HB_FUN_WAPI_SHELLEXECUTE_WAIT':
hbwinfunctions.prg:29:4: error: unknown type name 'BOOL'; did you mean 'HB_BOOL'?
hbwinfunctions.prg:30:4: error: unknown type name 'SHELLEXECUTEINFO'
hbwinfunctions.prg:31:14: error: request for member 'cbSize' in something not a structure or union
hbwinfunctions.prg:31:31: error: 'SHELLEXECUTEINFO' undeclared (first use in this function)
hbwinfunctions.prg:31:31: note: each undeclared identifier is reported only once for each function it appears in
hbwinfunctions.prg:32:14: error: request for member 'fMask' in something not a structure or union
hbwinfunctions.prg:32:23: error: 'SEE_MASK_NOCLOSEPROCESS' undeclared (first use in this function)
hbwinfunctions.prg:33:14: error: request for member 'hwnd' in something not a structure or union
hbwinfunctions.prg:33:24: error: 'HWND' undeclared (first use in this function)
hbwinfunctions.prg:33:30: error: expected ';' before 'hb_parptr'
hbwinfunctions.prg:34:14: error: request for member 'lpVerb' in something not a structure or union
hbwinfunctions.prg:34:24: warning: implicit declaration of function 'HB_PARSTR'; did you mean 'HB_PARAMNO'? [-Wimplicit-function-declaration]
hbwinfunctions.prg:35:14: error: request for member 'lpFile' in something not a structure or union
hbwinfunctions.prg:35:24: warning: implicit declaration of function 'HB_PARSTRDEF'; did you mean 'HB_CAST_INT'? [-Wimplicit-function-declaration]
hbwinfunctions.prg:36:14: error: request for member 'lpParameters' in something not a structure or union
hbwinfunctions.prg:37:14: error: request for member 'lpDirectory' in something not a structure or union
hbwinfunctions.prg:38:14: error: request for member 'nShow' in something not a structure or union
hbwinfunctions.prg:38:23: warning: implicit declaration of function 'hb_parnidef' [-Wimplicit-function-declaration]
hbwinfunctions.prg:38:39: error: 'SW_SHOWNORMAL' undeclared (first use in this function)
hbwinfunctions.prg:39:14: error: request for member 'hInstApp' in something not a structure or union
hbwinfunctions.prg:40:13: warning: implicit declaration of function 'ShellExecuteEx'; did you mean 'hb_vmExecute'? [-Wimplicit-function-declaration]
hbwinfunctions.prg:41:4: warning: implicit declaration of function 'hb_retl'; did you mean '_rotl'? [-Wimplicit-function-declaration]
hbwinfunctions.prg:42:11: warning: implicit declaration of function 'WaitForSingleObject' [-Wimplicit-function-declaration]
hbwinfunctions.prg:42:41: error: request for member 'hProcess' in something not a structure or union
hbwinfunctions.prg:42:60: error: 'WAIT_OBJECT_0' undeclared (first use in this function)
hbwinfunctions.prg:44:7: warning: implicit declaration of function 'SysRefresh' [-Wimplicit-function-declaration]
hbwinfunctions.prg:46:4: warning: implicit declaration of function 'hb_strfree'; did you mean '_strrev'? [-Wimplicit-function-declaration

Is some header missing ?

Warm regards,

Jayadev


--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/4edbe0b2-d732-45a1-80e6-96bd5c471238%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonino Perricone

unread,
Jul 1, 2019, 3:13:30 AM7/1/19
to Harbour Users
You can use msdn to find the missing header, for example: ShellExecuteEx needs shellapi.h
BOOL is inside windows.h,  hbapi.h is inside hbapi.h... and so on...

Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbou...@googlegroups.com.

rajesh nandwani

unread,
Feb 26, 2020, 7:30:13 AM2/26/20
to Harbour Users
Thanks for sharing the function. Though it is working fine, but I had to comment SysRefresh Line. "hbmk2 prgname -lhbwin" gives error
undefined reference to `SysRefresh'.
I have included header files
#include <windows.h>
#include <shellapi.h>
#include "hbwinuni.h"
& using harbour 3.0
Thanks!!
Rajesh
Reply all
Reply to author
Forward
0 new messages