However those stupid ocx files make trouble. It seems like they refuse to work without the proper registry keys.
Any bright ideas how to get them to work? Best without having to write to registry first.
![:yahoo:](http://reboot.pro/public/style_emoticons/default/yahoo.gif)
Posted 25 July 2007 - 11:27 AM
Posted 25 July 2007 - 12:03 PM
RegSvr32.exe calls the following Win32 functions in this order:
• OleInitialize
• LoadLibrary to load the DLL
• DllRegisterServer or DllUnregisterServer
• FreeLibrary
• OleUninitialize
Most often, RegSvr32.exe fails because the LoadLibrary, DllRegisterServer, or DllUnregisterServer function fails. LoadLibrary can fail if the DLL is not in the specified path, or if the specified path is incorrect. LoadLibrary can also fail if one of the dependencies of the DLL that you are trying to load is not met; in other words, if a dependent DLL is not present or is not in the specified path.
NOTE: You can use the Depends.exe tool to check whether or not all of the dependencies of your DLL are met. Depends.exe is included with the Microsoft Platform Software Development Kit (SDK), which ships with Microsoft Visual Studio.
Your DLL must implement DllRegisterServer and DllUnregisterServer, which contain the logic that is necessary to add or delete the required registry entries for the COM component. RegSvr32.exe finds the entry point to these functions, and calls them appropriately.
Edited by Nuno Brito, 25 July 2007 - 12:10 PM.
Added info from MS KB
Posted 25 July 2007 - 12:03 PM
Posted 25 July 2007 - 01:12 PM
Posted 25 July 2007 - 07:05 PM
Control Registration Utility 2.00
RegCtrls (Register Controls) allows you to selectively register and unregister OLE controls with the system registry. RegCtrls is a GUI replacement for Microsoft's REGSVR32 command-line utility. RegCtrls uses its Windows interface to provide easier access to features and also provides functionality not available with Microsoft's command-line utility.
Reggie
an alternative to Microsoft's RegSvr32.exe (and RegTLib.exe)
I wrote some code that would essentially do the following:
- build a list of registry keys to monitor
- run DllUnregisterServer on the DLL
- capture the state of monitored registry keys
- run DllRegisterServer on the DLL
- build a difference list of monitored keys
This is incorporated into izfree, but I don't know how useful that
would be to you. You can look at the vbscript and see how the
izMonitor.exe COM object works and maybe repurpose it to your own
needs. <http://izfree.sourceforge.net>
Posted 25 July 2007 - 07:13 PM
Posted 25 July 2007 - 09:47 PM
Re: Capture Registry Keys from Regsvr32.exe
I did something a while back - it's here:
http://www.installsi...en/msi/tips.htm
scroll down to Capture Self Registration Information. It uses the Windows
2000 API RegOverridePredefKey to cause the registry entries to redirect to
another location.
--
Phil Wilson [MVP Windows Installer]
RegSpy
This program (formerly known as RegIt) captures COM registration entries for DLLs, OCXs and EXE COM servers. In general, it works by using the RegOverridePredefKey on Windows 2000 to redirect registry entries to another registry area.
1. It takes the path to the Dll as a command line argument.
2. Loads the Dll and looks for DllRegisterServer to call.
3. Redirects HKEY_CLASSES_ROOT and HKEY_LOCAL_MACHINE registry entries to
HKEY_CURRENT_USER\Software\Unisys\Registry\<dllname>\HKCR and
HKEY_CURRENT_USER\Software\Unisys\Registry\<dllname>\HKLM.
In contrast to other registry monitor solutions it doesn't need any drivers. Source code is included in the package.
Update: Now can output a .reg file for import in MSI authoring tools. Source code requires Visual Studio .NET 2003.
http://www.installsi...swi/RegSpy2.zip
Original version (source code works with Visual Studio 6.0):
http://www.installsi...iswi/RegSpy.zip
Written by Phil Wilson
Posted 26 July 2007 - 08:20 AM
And Nuno took the right piece out of the jackpot: RegOverridePredefKey.I think Jaclaz hit the jackpot, thanks for the links!
Posted 26 July 2007 - 10:43 AM
unit DLLRegister;interfacefunction DllServer(const ADll: string; const ARegister: boolean = true): boolean;implementationuses Windows, OSVersion, Registry, IsAdministrator;type TDllRegisterServer = function: HResult; stdcall; TRegOverridePredefKey = function(AKey, ANewKey: HKEY): longint; stdcall;function RegOverridePredefKey(AKey, ANewKey: HKEY): longint;var iDll: integer; pROPK: TRegOverridePredefKey;begin Result := ERROR_INVALID_FUNCTION; iDll := LoadLibrary(advapi32); if iDll <> 0 then try pROPK := GetProcAddress(iDll, 'RegOverridePredefKey'); if Assigned(pROPK) then Result := pROPK(AKey, ANewKey); finally FreeLibrary(iDll); end;end;function _DllRegisterServer(const ADll: string; const ARegistering: boolean = true): boolean;var iDll: integer; pDRS: TDllRegisterServer; strRegister: string;begin if ARegistering then strRegister := 'DllRegisterServer' else strRegister := 'DllUnregisterServer'; Result := false; iDll := LoadLibrary(pAnsiChar(ADll)); if iDll <> 0 then try pDRS := GetProcAddress(iDll, PAnsiChar(strRegister)); if Assigned(pDRS) then Result := pDRS = S_OK; finally FreeLibrary(iDll); end;end;function OverrideRegistryKey(const ARegister: boolean): boolean;var hNewHive: HKEY;begin if ARegister then begin RegOpenKeyEx(HKEY_CURRENT_USER, 'Software\Classes', 0, KEY_ALL_ACCESS, hNewHive); try Result := RegOverridePredefKey(HKEY_CLASSES_ROOT, hNewHive) = ERROR_SUCCESS; finally RegCloseKey(hNewHive); end; end else Result := RegOverridePredefKey(HKEY_CLASSES_ROOT, 0) = ERROR_SUCCESS;end;function DllServer(const ADll: string; const ARegister: boolean = true): boolean;var swvVersion: TWindowsVersion; fNT: Boolean;begin swvVersion := GetWindowsVersion; fNT := (swvVersion.KernelType = wktNT) and (swvVersion.MajorVersion >= 5); Result := false; if fNT then begin if ARegister then begin if OverrideRegistryKey(true) then begin try Result := _DllRegisterServer(ADll, ARegister); finally OverrideRegistryKey(false); end; end else if not IsAdmin then exit else Result := _DllRegisterServer(ADll, ARegister); end else begin Result := _DllRegisterServer(ADll, ARegister); try Result := Result or _DllRegisterServer(ADll, ARegister); finally OverrideRegistryKey(false); end; end end else Result := _DllRegisterServer(ADll, ARegister);end;end.http://www.koders.com/delphi/fid0AA937CD01...5DD9F341B0.aspxMore snippets
type // this function maps a predefined key to the argument; used for chrooting a key // to a new hive in the registry. this only affects the calling process! function RegOverridePredefKey(a_hKey: HKEY; // predefined key [HIVE] a_TargethKey: HKEY): Longint; stdcall; // OPEN! key. all calls to HIVE will end up hereimplementation function RegOverridePredefKey(a_hKey: HKEY; a_TargethKey: HKEY): Longint; external 'advapi32.dll' name 'RegOverridePredefKey';http://www.delphipraxis.net/post168989.html (german forum)Maybe this way DLL's and OCX files can directly write the target hives?And a more recent app along with source code to export all registry entries to a .reg file (along with some explanations how it works..)http://vagmi.supersized.org/archives/13-Sp...ry-Entries.html[quote]Spying on Registry EntriesI am probably letting out the best kept secret of installation industry. I always used to wonder and have now discovered how most of the installation tools spy on registry entries that are created during COM registration or similar processes without actually affecting the build system. The spying program creates temporary registry keys for each of the registry hives HKCR, HKLM, HKCU, HKU and it maps the registry hives to these temporary registry keys. It then triggers the registration function which creates registry entries withing the registry keys specified instead of including it in the hives. I came across this revelation while I was wading through the source code for Tallow in the WIX toolset.The core of this spying exercise relies on functions exposed by the advapi32.dll. The actual hive to key mapping is performed by the RegOverridePredefKey() function. The handle to the registry key is passed by using the RegCreateKeyEx() or the RegOpenKeyEx() function. After the mapping is done, you can invoke the DllRegisterServer() function after loading the library using the LoadLibrary() function. This mapping would be active for all the registry entries created by that particular process. So out of process registration for exe files may not directly work with this method. For the sake of simplicity, I am going to extract COM Interop settings from a given assembly. So let us write a simple console app in C# to do this. This app would perform the mapping and write the registry entries to a REG file and wipe out the key after the file is written.Extracting registration information from a DLL file is similar but involve the importing other functions from Kernel32.dll. So I am giving that a raincheck now. You can download the Wix toolset's source package if you are interested.[/quote]
Posted 26 July 2007 - 02:39 PM
Posted 26 July 2007 - 02:47 PM
Posted 26 July 2007 - 09:11 PM
The Regisrty Changer ===================== RegOverridePredefKey (HKEY_CLASSES_ROOT, HKEY_CURRENT_USER\SOFTWARE\MedEvil\HKEY_CLASSES_ROOT) RegOverridePredefKey (HKEY_CURRENT_USER, HKEY_CURRENT_USER\SOFTWARE\MedEvil\HKEY_CURRENT_USER) RegOverridePredefKey (HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER\SOFTWARE\MedEvil\HKEY_LOCAL_MACHINE) RegOverridePredefKey (HKEY_USERS, HKEY_CURRENT_USER\SOFTWARE\MedEvil\HKEY_USERS) RegOverridePredefKey (HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER\SOFTWARE\MedEvil\HKEY_CURRENT_CONFIG) Release a mapping: RegOverridePredefKey (HKEY_CURRENT_CONFIG, NULL)
REM create directory structure in %CD% folder REM------------------------------------------- md "%CD%\Windows\Downloaded Program Files" md "%CD%\Windows\Fonts" md "%CD%\Windows\inf" md "%CD%\Windows\installer" md "%CD%\Windows\Macromed" md "%CD%\Windows\System" md "%CD%\Windows\System32" md "%CD%\Windows\Temp" md "%CD%\ProgramData\CommonFiles" md "%CD%\Users\All Users\Application Data" md "%CD%\Users\All Users\Desktop" md "%CD%\Users\All Users\My Documents\My Pictures" md "%CD%\Users\All Users\My Documents\My Music" md "%CD%\Users\All Users\Favorites" md "%CD%\Users\All Users\Local Settings" md "%CD%\Users\All Users\SendTo" md "%CD%\Users\All Users\Start Menu" md "%CD%\Users\All Users\UserData" md "%CD%\Users\All Users\Templates" md "%CD%\Users\MedEvil\Application Data" md "%CD%\Users\MedEvil\Cookies" md "%CD%\Users\MedEvil\Desktop" md "%CD%\Users\MedEvil\My Documents\My Pictures" md "%CD%\Users\MedEvil\My Documents\My Music" md "%CD%\Users\MedEvil\Favorites" md "%CD%\Users\MedEvil\Local Settings\Application Data\Microsoft" md "%CD%\Users\MedEvil\History" md "%CD%\Users\MedEvil\Temporary Internet Files" md "%CD%\Users\MedEvil\SendTo" md "%CD%\Users\MedEvil\Start Menu\Programs\Startup" md "%CD%\Users\MedEvil\UserData" md "%CD%\Users\MedEvil\Templates REM create MedEvil.reg REM-------------------- ECHO> MedEvil.reg REGEDIT4 ECHO>>MedEvil.reg [HKEY_CURRENT_USER\SOFTWARE\MedEvil] REM create Delete.reg REM------------------- ECHO> Delete.reg REGEDIT4 ECHO>>Delete.reg [-HKEY_CURRENT_USER\SOFTWARE\MedEvil]
REMdelete RegKey REM-------------- regedit.exe /s %CD%\Delete.reg REMInstall Regkey REM--------------- regedit.exe /s %CD%\MedEvil.reg REM Set Environment REM----------------- Set ALLUSERSPROFILE="%CD%\Users\All Users" Set USERPROFILE=%CD%\Users\MedEvil Set HOMEDRIVE=%CD% Set SystemDrive=%CD% Set SystemRoot=%CD%\WINDOWS Set windir=%CD%\WINDOWS Set ProgramFiles=%CD%\ProgramData Set CommonProgramFiles=%CD%\ProgramData\CommonFiles Set HOMEPATH=\Users\MedEvil Set APPDATA="%CD%\Users\MedEvil\Application Data" Set Path=%CD%\Windows\system32;%CD%\Windows;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem REM Temp should best left to point to HDD,If you're paranoid, enable the settings below;-) // Set TEMP=C:\DOCUME~1\MedEvil\LOCALE~1\Temp // Set TMP=C:\DOCUME~1\MedEvil\LOCALE~1\Temp REM Start Explorer REM--------------- RegReMapper Explorer.exe REM save RegKey REM------------- regedit.exe /s /e %CD%\MedEvil.reg HKEY_CURRENT_USER\SOFTWARE\MedEvil REM delete RegKey REM--------------- regedit.exe /s %CD%\Delete.reg
Posted 26 July 2007 - 09:15 PM
Posted 26 July 2007 - 10:59 PM
Set SystemRoot=%CD%\WINDOWS
RegReMapper Explorer.exeshould be executed with the WAIT switch - explorer makes thing simpler indeed.
Posted 27 July 2007 - 08:59 AM
A few useful links:
http://www.codeproje...2k/regsvrex.asp
http://geekswithblog...2/01/16583.aspx
http://www.ddj.com/d...ndows/184416328
Posted 27 July 2007 - 09:37 AM
All changes apply only to the used cmd and all child processes. Any program started 'outside' will still have the default environment.One question, will the new %SystemRoot% return to original value after the batch file finishes?
Set SystemRoot=%CD%\WINDOWS
Why? The cmd file will not proceed, as long as explorer.exe is not finished.Also noticed that perhaps
RegReMapper Explorer.exeshould be executed with the WAIT switch
Posted 27 July 2007 - 09:51 AM
Yes, the first one is the most interesting from the shown code.The first one yesterday forced my decision to do the job!
Peter
Posted 27 July 2007 - 10:55 AM
@echo off explorer.exe notepad.exe
Posted 27 July 2007 - 11:17 AM
Nuno, maybe you should try your script yourself.Try this..
@echo off explorer.exe notepad.exe
It will open both apps because no rules are set to wait for explorer to finish - this was the reason why I've mentioned the wait switch - or at least implement a small function on the new app to redirect registry and wait while explorer is running.
@echo off start explorer.exe start notepad.exe
Posted 27 July 2007 - 11:26 AM
Posted 27 July 2007 - 12:03 PM
@echo off explorer.exe notepad.exeWill start explorer and only upon closing explorer will start notepad. And only after notepad is closed will finish and close the cmd window.
@echo off start explorer.exe start notepad.exeWill start explorer, then notepad and then finish, without waiting for any of the started processes to finish or to even finish loading. It's a sort of, kick off and forget behaviour.
Posted 27 July 2007 - 12:10 PM
Posted 27 July 2007 - 01:24 PM
@pcs
Maybe hooks would be a way to go, but i have no clever idea how to bind them just to processes and by them created child processes, we started via our launcher.![]()
http://www.codeproje...tem/Paladin.asp
![]()
PS: We can't use the folder the app is running from as determinator, but maybe we can set an environment variable that the hook function could check for?
Posted 27 July 2007 - 02:11 PM
Posted 27 July 2007 - 02:11 PM
0 members, 0 guests, 0 anonymous users