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

Ven H venh.123 at gmail.com
Thu Apr 5 10:11:41 PDT 2018


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