Thought I've done this with:
<CustomAction Id="writeKey" BinaryKey="myInstaller" DllEntry="writeKey"
Execute="deferred" Impersonate="no"/>

Michael

> -----Ursprüngliche Nachricht-----
> Von: Wilson, Phil [mailto:phil.wil...@invensys.com]
> Gesendet: Freitag, 15. Juli 2011 01:43
> An: General discussion for Windows Installer XML toolset.
> Betreff: Re: [WiX-users] Writing to ProgramFolder with Custom Action
> Dll in C++
> 
> Custom actions need to be deferred to run with elevated privilege.
> 
> Phil Wilson
> 
> 
> -----Original Message-----
> From: Michael Ganz [mailto:michael_g...@t-online.de]
> Sent: Thursday, July 14, 2011 3:32 PM
> To: wix-users@lists.sourceforge.net
> Subject: [WiX-users] Writing to ProgramFolder with Custom Action Dll in
> C++
> 
> Hello List,
> 
> 
> 
> I'm using WiX for creating a setup with a keyfile with openSSL.
> 
> The keyfile has to be placed in the ProgramFolderDir.
> 
> 
> 
> After creating the key with the Custom Action, I push it in a Property
> called "LICENSE".
> 
> Another function should write this file to the products shortname with
> ".key" extension.
> 
> 
> 
> If I start the Installer from an administrator shell, all went fine.
> 
> If I start it as user with administrator privileges, the Custom Action
> returns an error.
> 
> 
> 
> -----snip Custom Action code
> 
> /**********************************************************************
> *****
> **/
> 
> bool writeToFile(const char *pcFileName, const char *pcData, DWORD
> szLen)
> 
> {
> 
>     bool _bReturn = false;
> 
> 
> 
>     int _iFile = _open(pcFileName, _O_WRONLY | _O_CREAT, _S_IWRITE );
> 
>     if(_iFile > 0)
> 
>     {
> 
>         if(_write(_iFile, pcData, szLen) == szLen)
> 
>         {
> 
>             _bReturn = true;
> 
>         }
> 
>         _close(_iFile);
> 
>     }
> 
> 
> 
>     return _bReturn;
> 
> }
> 
> 
> 
> /**********************************************************************
> *****
> **/
> 
> UINT __stdcall writeKey(MSIHANDLE hInstall)
> 
> {
> 
>     char _pcKeyPath[MAX_PATH];
> 
>     DWORD _dKeyPathLen = MAX_PATH;
> 
> 
> 
>     char _pcLicence[1024];
> 
>     DWORD _dLicenceLen = 1024;
> 
> 
> 
>     MsiGetPropertyA(hInstall, "INSTALLDIR", _pcKeyPath, &_dKeyPathLen);
> 
>     MsiGetPropertyA(hInstall, "LICENCE", _pcLicence, &_dLicenceLen);
> 
> 
> 
>     bool _bWriteSuccess = false;
> 
>     if(_dLicenceLen > 0)
> 
>     {
> 
>         if(_dKeyPathLen > 0)
> 
>         {
> 
>             string _sLicenceFile = _pcKeyPath;
> 
>             if(_sLicenceFile.size() > 0
> 
>                 && !(_sLicenceFile[_sLicenceFile.size()-1] == '/'
> 
>                         || _sLicenceFile[_sLicenceFile.size()-1] ==
> '\\'))
> 
>             {
> 
>                 _sLicenceFile += "\\";
> 
>             }
> 
>             _sLicenceFile += "mykey.key";
> 
> 
> 
>             string _sLogMsg = "Writing key file to dir: ";
> 
>             _sLogMsg += _sLicenceFile;
> 
> 
> 
>             MsiSetPropertyA(hInstall, "LASTDLLACTION",
> _sLogMsg.c_str());
> 
>             _bWriteSuccess = writeToFile(_sLicenceFile.c_str(),
> _pcLicence,
> _dLicenceLen);
> 
>         }
> 
>     }
> 
> 
> 
>     if(_bWriteSuccess)
> 
>     {
> 
>         MsiSetPropertyA(hInstall, "KEYWRITESUCCESS", "0");
> 
>     }
> 
>     else
> 
>     {
> 
>         MsiSetPropertyA(hInstall, "KEYWRITESUCCESS", "-1");
> 
>         MsiSetPropertyA(hInstall, "LASTDLLACTION", "Error writing key
> file");
> 
>     }
> 
> 
> 
>     return ERROR_SUCCESS;
> 
> }
> 
> 
> 
> -----snip end of Custom Action code
> 
> 
> 
> 
> 
> The dll is set by:
> 
>      <Binary Id="myInstaller" SourceFile="myInstaller.dll"/>
> 
> 
> 
> The function is specified by:
> 
>     <CustomAction Id="writeKey" BinaryKey="myInstaller"
> DllEntry="writeKey"
> Execute="deferred" Impersonate="no"/>
> 
> 
> 
> 
> 
> The install sequence calls the custom action before InstallFinalize
> 
>     <InstallExecuteSequence>
> 
>       <Custom Action="writeKey" Before="InstallFinalize">1</Custom>
> 
>     </InstallExecuteSequence>
> 
> 
> 
> 
> 
> First I tried it after InstallFinalize and without the Execute and
> Impersonate attribute, but that doesn't work.
> 
> In administrator shell, all action are done, so the code is fine, but
> something with rights, I guess.
> 
> 
> 
> What I'm doing wrong ?
> 
> How can I activate UAC or administrator privileges for running my
> function ?
> 
> Does the dll needs a special initialization routine ?
> 
> At linker section in Visual Studio I set the UACExecutionLevel="2"
> (administrator privileges), but nothing changed. I guess for dlls this
> is
> needless.
> 
> 
> 
> Regards Michael
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -----------------------------------------------------------------------
> -------
> AppSumo Presents a FREE Video for the SourceForge Community by Eric
> Ries, the creator of the Lean Startup Methodology on "Lean Startup
> Secrets Revealed." This video shows you how to validate your ideas,
> optimize your ideas and identify your business strategy.
> http://p.sf.net/sfu/appsumosfdev2dev
> _______________________________________________
> WiX-users mailing list
> WiX-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wix-users
> 
> 
> *** Confidentiality Notice: This e-mail, including any associated or
> attached files, is intended solely for the individual or entity to
> which it is addressed. This e-mail is confidential and may well also be
> legally privileged. If you have received it in error, you are on notice
> of its status. Please notify the sender immediately by reply e-mail and
> then delete this message from your system. Please do not copy it or use
> it for any purposes, or disclose its contents to any other person. This
> email comes from a division of the Invensys Group, owned by Invensys
> plc, which is a company registered in England and Wales with its
> registered office at 3rd Floor, 40 Grosvenor Place, London, SW1X 7AW
> (Registered number 166023). For a list of European legal entities
> within the Invensys Group, please go to
> http://www.invensys.com/legal/default.asp?top_nav_id=77&nav_id=80&prev_
> id=77.
> 
> You may contact Invensys plc on +44 (0)20 3155 1200 or e-mail
> recept...@invensys.com. This e-mail and any attachments thereto may be
> subject to the terms of any agreements between Invensys (and/or its
> subsidiaries and affiliates) and the recipient (and/or its subsidiaries
> and affiliates).
> 
> 
> 
> -----------------------------------------------------------------------
> -------
> AppSumo Presents a FREE Video for the SourceForge Community by Eric
> Ries, the creator of the Lean Startup Methodology on "Lean Startup
> Secrets Revealed." This video shows you how to validate your ideas,
> optimize your ideas and identify your business strategy.
> http://p.sf.net/sfu/appsumosfdev2dev
> _______________________________________________
> WiX-users mailing list
> WiX-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wix-users


------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to