FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Register a .dll
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Register a .dll
Posted: Tue May 05, 2009 11:32 PM

I need to register a .dll for my application.

From a command propmpt I would type REGSRV32 abcde.dll
In Vista, I must start the command prompt using Run As Administrator
I would like to create a call from my program that will do this process for me from within the application.

Is there a way to do this using commands inside FWH / xHarbour that will work with Vista .

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Register a .dll
Posted: Wed May 06, 2009 12:02 AM
Hello Tim,

There are some examples in the Internet, using VBScript's, to run applications as administrator.
You can execute VBSript's inside Your application with WSH ( Windows-Scripting-Host )

Save these 2 lines as : REGISTER.VBS

Set objSh = CreateObject("Shell.Application")
objSh.ShellExecute "REGSVR32.exe Application.dll", "" , "", "runas", 1


Execute the VBSCRIPT inside Your Application : Winexec('WSCRIPT.exe REGISTER.VBS')


A C-Function
---------------

SHELLEXECUTEINFO shExecInfo;

shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = _T("runas");
shExecInfo.lpFile = _T("MyAppl.exe");
shExecInfo.lpParameters = _T("-u");
shExecInfo.lpDirectory = strAppPath.text ();
shExecInfo.nShow = SW_SHOW;
shExecInfo.hInstApp = NULL;

ShellExecuteEx (&shExecInfo);


There is a post of mine in the Forum for another solution, how to use WSH.
viewtopic.php?f=3&t=14833&p=76680&hilit=scripting+host#p76680

I think it also can work, using SHELLEXECUTE directly from inside FWH.
Have a look at this link, maybe it will give You some informations.

http://forums.techarena.in/vista-admini ... 977482.htm

Best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: Register a .dll
Posted: Wed May 06, 2009 04:13 AM
Hello Mr.Tim

Look at the following thread. May be this is useful to you.

http://forums.fivetechsupport.com/viewtopic.php?f=3&t=15102&start=45

Code (fw): Select all Collapse
RegisterServer( "Codejock.CommandBars.v12.1.1.ocx" ) 

or, if using the new version:

RegisterServer( "Codejock.CommandBars.v13.0.0.ocx" ) 


Code: Select all  Expand view

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

typedef LONG ( * PDLLREGISTERSERVER ) ( void ); 

HB_FUNC( REGISTERSERVER )
{
   HMODULE hDll = LoadLibrary( hb_parc( 1 ) );
   LONG lReturn = 0;
   
   if( hDll )
   {
      FARPROC pRegisterServer = GetProcAddress( hDll, "DllRegisterServer" );
      
      if( pRegisterServer )
         lReturn = ( ( PDLLREGISTERSERVER ) pRegisterServer )();

      FreeLibrary( hDll ); 
   }
   
   hb_retnl( lReturn );
}         

#pragma ENDDUMP
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Register a .dll
Posted: Wed May 06, 2009 06:33 AM

Dear Mr.Tim,

RegisterServer() is equivalent to RegSrv32 and for me it is working fine, but in Vista you need to use the option "Run as Administrator" for the RegisterServer() to work successfully. In Vista, FWH Application will get struck at the RegisterServer(), if the "Run as Administrator" is not used.

I am also waiting for a solution to this problem.

Regards

Anser

Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Register a .dll
Posted: Wed May 06, 2009 04:08 PM
the question is

How elevate the user to admin level in the program?????

I search in MSDN and not found a function, only a function for validate if user is admin. :-)

the ideal situation is:

Code (fw): Select all Collapse
#include "fivewin.ch"
function main()

   if Up2Admin( "USERADMINNAME", "OTHERDATA" )  /*this function NOT exist :-(, but ....*/
      if IsAdministrator()
         RegisterServer( "Codejock.CommandBars.v12.1.1.ocx" )
      else
         MsgInfo("User is not Administrator!")
      endif
   endif

return

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>
#include <shlobj.h>

/*BOOL IsUserAnAdmin(VOID);*/

HB_FUNC( ISADMINISTRATOR)
{
 retni( IsUserAnAdmin() );
}

HB_FUNC( REGISTERSERVER )
{
   HMODULE hDll = LoadLibrary( hb_parc( 1 ) );
   LONG lReturn = 0;
   
   if( hDll )
   {
      FARPROC pRegisterServer = GetProcAddress( hDll, "DllRegisterServer" );
      
      if( pRegisterServer )
         lReturn = ( ( PDLLREGISTERSERVER ) pRegisterServer )();

      FreeLibrary( hDll ); 
   }
   
   hb_retnl( lReturn );
} 

#pragma ENDDUMP
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Register a .dll
Posted: Wed May 06, 2009 04:53 PM
Carlos,

It seems as we have to use the Windows API functions for SIDs:

http://msdn.microsoft.com/en-us/library/aa379594(VS.85).aspx
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Register a .dll
Posted: Wed May 06, 2009 04:57 PM
Carlos,

Here there are some functions examples to review:

http://msdn.microsoft.com/en-us/library/aa379620(VS.85).aspx
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Register a .dll
Posted: Wed May 06, 2009 09:04 PM

Antonio, Thanks you.
I Review.

Sorry for my bad english.

salu2

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)

Continue the discussion