Search code examples
dllinstallationinno-setupregsvr32

Inno Setup: Run regsvr32 with a specific working directory


I'm trying to register a number of DLL's as part of my installer. I'm using the regserver flag, and it works perfectly for most of the DLL's. However, one DLL fails to register. It tries to load other DLL's and fails if it can't find them in the current directory. It registers cleanly if regsvr32 is run manually from the {app} directory.

Is there any way to set the working directory for the regserver flag? Or the whole installer?

For now, I'm working round it via a [Run] entry:

[Run]
;Register components that are "special"
Filename: "{sys}\Regsvr32.exe"; Parameters: "/s Awkward.dll"; \
    WorkingDir: "{app}"; StatusMsg: "Registering components ... "; \
    Flags: runhidden; 

But this is not ideal, as I suspect I also ought to add an [UninstallRun] section and add an unregister command. I'd hoped I could do:

[Files]
Source: "{#mysrc}\Awkward.dll"; DestDir: "{app}"; Flags: regserver;  \
    WorkingDir: "{app}"

Is there an easier way to register/unregister from a specific directory?


Solution

  • You cannot. The regsvr32.exe that Inno Setup runs internally to (un)register DLLs is explicitly run from a system directory (typically the C:\Windows\System32).


    Your workaround is the best way.

    Just add an equivalent [UninstallRun] entry to unregister the DLL:

    [UninstallRun]
    Filename: "{sys}\regsvr32.exe"; Parameters: "/u /s Awkward.dll"; 
        WorkingDir: "{app}"; Flags: runhidden;
    

    Or even better, fix the DLL not to rely on a working directory. You can use the LOAD_WITH_ALTERED_SEARCH_PATH flag for the LoadLibraryEx.

    See also Dynamic-Link Library Search Order.