[wix-users] Execute BCP through batch file in C# Custom Action not working

Ven H venh.123 at gmail.com
Fri Apr 6 09:14:21 PDT 2018


Me too, Edwin. I never expected it too. But when I saw it in that blog and
gave a try, that is when it actually worked.

Regards,
Venkatesh

On Fri, Apr 6, 2018 at 9:19 PM, Edwin Castro <egcastr at gmail.com> wrote:

> Interesting. I've never needed to Execute="commit" previously. The fact
> that if you "use a Builtin Custom Action with ExeCommand attribute" works
> suggests that Execute="commit" is not actually necessary. I don't know
> enough about commit custom actions but I suspect there's no huge risk in
> using one in this particular case. I'm more interested in actually
> understanding why this wasn't working with Execute="deferred" as I would
> expect.
>
> --
> Edwin G. Castro
>
>
> On Fri, Apr 6, 2018 at 3:29 AM, Ven H via wix-users <
> wix-users at lists.wixtoolset.org> wrote:
>
>> I figured it out. The solution was to use Execute="commit" in the above
>> CustomAction element in place of "deferred". I found it from the below
>> link. Hope it helps someone.
>>
>> https://dylanwooters.wordpress.com/2014/03/20/creating-
>> custom-actions-with-wix-and-running-as-administrator/
>>
>> Regards,
>> Venkatesh
>>
>> On Thu, Apr 5, 2018 at 10:41 PM, Ven H <venh.123 at gmail.com> wrote:
>>
>> > I have a Custom Action code snippet as below.
>> >
>> >                pStartInfo = new ProcessStartInfo("cmd.exe");
>> >                 pStartInfo.WorkingDirectory = dirName;
>> >                 pStartInfo.UseShellExecute = false;
>> >                 pStartInfo.CreateNoWindow = false;
>> >                 pStartInfo.RedirectStandardOutput = true;
>> >                 string space = "  ";
>> >                 pStartInfo.Arguments = string.Concat("/c ", fileName,
>> > space, serverName, space, userName, space, pwd);
>> >                 pBcp = Process.Start(pStartInfo);
>> >                 string output = pBcp.StandardOutput.ReadToEnd();
>> >                 pBcp.WaitForExit();
>> >
>> > Following is the Custom Action defined in the Product.wxs.
>> >
>> > <CustomAction Id="CA_ExecuteBCP" BinaryKey="ExecBCPCADLL"
>> > DllEntry="ExecuteBCP" Execute="deferred" Return="check"
>> Impersonate="yes"></
>> > CustomAction>
>> >
>> >     <CustomAction Id="CA_GetInstallLocation" Property="CA_ExecuteBCP"
>> > Value="InstallLocn=[INSTALLFOLDER];SqlServer=[SQLSERVER]\[SQLINSTANCE];
>> > UserName=[SQLUSER];Password=[SQLPASSWORD]" />
>> >
>> >     <InstallExecuteSequence>
>> >       <Custom Action="CA_GetInstallLocation" Before="CA_ExecuteBCP">NOT
>> > Installed</Custom>
>> >     <Custom Action="CA_ExecuteBCP" After="InstallFiles">NOT
>> > Installed</Custom>
>> >     </InstallExecuteSequence>
>> >
>> > The code is getting executed properly and I can see the output string
>> > properly assigned with a value. Basically, it is executing the batch
>> file
>> > and calling the BCP command along with arguments and returning the
>> output.
>> > But the data is not imported into the table. If I execute the process
>> code
>> > from a Console App, it is working fine. Looks like it could be a
>> permission
>> > issue. I have heard deferred actions already run with elevated
>> privileges.
>> > Hence I initially tried without the Impersonate attribute, but it didn't
>> > work. I tried with that also, still it didn't work. I am not sure what
>> is
>> > wrong or missing. Can anyone please help?
>> >
>> > PS: If I use a Builtin Custom Action with ExeCommand attribute, it is
>> > working without any additional permissions.
>> >
>> >
>>
>> ____________________________________________________________________
>> WiX Toolset Users Mailing List provided by FireGiant
>> http://www.firegiant.com/
>>
>
>


More information about the wix-users mailing list