0

I have written a WCF service API which will create process inside to convert something for my application, also this service deployed in IIS in windows server using windows authentication. I used below code to run c# .exe but not running. If I run below code without username and password .exe is running but as SYSTEM user. I want to run this exe with specified user name.

public byte[] InvokeShtToPdfConvertor(string userId, string connectionAlias)
{
        try
        {                
            using (Process shtToPdfProc = new Process())
            {
                shtToPdfProc.StartInfo.FileName = Constants.SHT_PDF_CONVERTOR_APP_PATH;
                shtToPdfProc.StartInfo.Arguments = userId + " " + connectionAlias;
                shtToPdfProc.StartInfo.Verb = "runas";
                shtToPdfProc.StartInfo.UserName = _tempUserName;
                shtToPdfProc.StartInfo.Domain = "cw01.contiwan.com";
                shtToPdfProc.StartInfo.Password = ConvertToSecureString("ABCDFEDD");

                shtToPdfProc.StartInfo.UseShellExecute = false;


                shtToPdfProc.Start();
                shtToPdfProc.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            throw new FaultException<MplCustomException>(new MplExceptionHandler().MplExceptionHandlerMethod(ex));
        }

        return GetPdfFilePath(userId);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Arunagiri
  • 11
  • 2
  • Why would you write some c# that runs a c# exe? Just take the c# that comprises the exe and put it into the c# that would have run it but now doesn't need to.. – Caius Jard Jan 30 '22 at 20:55
  • Getting error message on server like "Application Popup: ShtToPdfConvertorApp.exe - Application Error: The application failed to start correctly (0xc0000142). Click "OK" to close the application. – Arunagiri Jan 31 '22 at 18:32
  • It doesn't sound like it's an exe well suited to a server environment; what does it do? – Caius Jard Jan 31 '22 at 18:56
  • You can see if [this post](https://stackoverflow.com/questions/11296819/run-mstsc-exe-with-specified-username-and-password) helps you. – Lan Huang Feb 03 '22 at 07:33

0 Answers0