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

Ven H venh.123 at gmail.com
Fri Apr 6 03:29:03 PDT 2018


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.
>
>



More information about the wix-users mailing list