From 930ee4580e6d47634325d9dab5e450c75abfd68e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 13 Dec 2011 00:15:18 +0000 Subject: [PATCH] 2011-12-13 01:12 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbnetio/utils/hbnetio/netiosrv.prg * contrib/hbnetio/utils/hbnetio/netiosvc.prg + use latest hbwin/wapi capabilities to install service thus allowing to change back the default run mode to interactive + install service as auto-start + added Windows service related option to cmdline help screen + display textual error msg on service related errors ! minor typo in an error msg --- harbour/ChangeLog | 12 ++++++- .../hbnetio/utils/hbnetio/netiosrv.prg | 7 +++- .../hbnetio/utils/hbnetio/netiosvc.prg | 32 ++++++++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b9957cd12d..df5646600a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,10 +16,20 @@ The license applies to all entries newer than 2009-04-28. */ +2011-12-13 01:12 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbnetio/utils/hbnetio/netiosrv.prg + * contrib/hbnetio/utils/hbnetio/netiosvc.prg + + use latest hbwin/wapi capabilities to install service thus + allowing to change back the default run mode to interactive + + install service as auto-start + + added Windows service related option to cmdline help screen + + display textual error msg on service related errors + ! minor typo in an error msg + 2011-12-12 14:01 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/gtwvg/wvgwing.c * Replaced: hbwin specific argument casting to local implementation. - Maybe this fixes compilation error with BCC55, though I feel that + Maybe this fixes compilation error with BCC55, though I feel that could be a result of some local modifications, reported by Jacek. 2011-12-12 21:39 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) diff --git a/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg b/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg index 6d11b2470b..d8a7cf45e7 100644 --- a/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg +++ b/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg @@ -203,7 +203,7 @@ PROCEDURE netiosrv_Main( lUI, ... ) HB_Usage() RETURN OTHERWISE - netiosrv_LogEvent( hb_StrFormat( "Warning: Unkown command line parameter ignored: %1$s", cParam ) ) + netiosrv_LogEvent( hb_StrFormat( "Warning: Unknown command line parameter ignored: %1$s", cParam ) ) ENDCASE NEXT @@ -849,6 +849,11 @@ STATIC PROCEDURE HB_Usage() OutStd( hb_eol() ) OutStd( " -noui don't open interactive console" , hb_eol() ) OutStd( hb_eol() ) + #if defined( __PLATFORM__WINDOWS ) + OutStd( " -i install as service (requires admin rights)" , hb_eol() ) + OutStd( " -u uninstall service (requires admin rights)" , hb_eol() ) + OutStd( hb_eol() ) + #endif OutStd( " --version display version header only" , hb_eol() ) OutStd( " -help|--help this help" , hb_eol() ) diff --git a/harbour/contrib/hbnetio/utils/hbnetio/netiosvc.prg b/harbour/contrib/hbnetio/utils/hbnetio/netiosvc.prg index f9dcbc8d1e..11efd0d527 100644 --- a/harbour/contrib/hbnetio/utils/hbnetio/netiosvc.prg +++ b/harbour/contrib/hbnetio/utils/hbnetio/netiosvc.prg @@ -6,19 +6,24 @@ PROCEDURE WinMain( ... ) LOCAL cMode := hb_PValue( 1 ) + LOCAL cMsg, nError + IF cMode == NIL - cMode := "-s" /* NOTE: Must be the default action */ + cMode := "" ENDIF SWITCH Lower( cMode ) CASE "-i" CASE "-install" - IF win_serviceInstall( _SERVICE_NAME, "Harbour NetIO Service" ) + IF win_serviceInstall( _SERVICE_NAME, "Harbour NetIO Service", Chr( 34 ) + hb_ProgName() + Chr( 34 ) + " -service", WIN_SERVICE_AUTO_START ) OutStd( "Service has been successfully installed" + hb_eol() ) ELSE - OutStd( "Error installing service: " + hb_ntos( wapi_GetLastError() ) + hb_eol() ) - ENDIf + nError := wapi_GetLastError() + cMsg := Space( 128 ) + wapi_FormatMessage( ,,,, @cMsg ) + OutStd( hb_StrFormat( "Error installing service: %1$d %2$s", nError, cMsg ) + hb_eol() ) + ENDIF EXIT CASE "-u" @@ -27,13 +32,11 @@ PROCEDURE WinMain( ... ) IF win_serviceDelete( _SERVICE_NAME ) OutStd( "Service has been deleted" + hb_eol() ) ELSE - OutStd( "Error deleting service: " + hb_ntos( wapi_GetLastError() ) + hb_eol() ) - ENDIf - EXIT - - CASE "-a" - - netiosrv_Main( .T., ... ) /* Interactive */ + nError := wapi_GetLastError() + cMsg := Space( 128 ) + wapi_FormatMessage( ,,,, @cMsg ) + OutStd( hb_StrFormat( "Error uninstalling service: %1$d %2$s", nError, cMsg ) + hb_eol() ) + ENDIF EXIT CASE "-s" @@ -42,10 +45,15 @@ PROCEDURE WinMain( ... ) IF win_serviceStart( _SERVICE_NAME, @hbnetio_WinServiceEntry() ) OutStd( "Service has started OK" + hb_eol() ) ELSE - OutStd( "Service has had some problems: " + hb_ntos( wapi_GetLastError() ) + hb_eol() ) + OutStd( hb_StrFormat( "Service has had some problems: %1$d", wapi_GetLastError() ) + hb_eol() ) ENDIF EXIT + OTHERWISE + + netiosrv_Main( .T., ... ) /* Interactive */ + EXIT + ENDSWITCH RETURN