none
Not able to run Batch File through process class in WCF service Method RRS feed

  • Question

  • Hi,

    I have one scenario where I have wcf rest service method and inside that I am executing batch file through Process class and this wcf service is hosted on IIS. Through Batch file exe will be executed with parameters and output will be put into C:\Test folder. 

    Now, I have added DefaultAppPool user on all folder which I need access. Currently, cmd.exe entry shown in Task Manager and don't perform or execute bat file. Please suggest which permission or priviledge I need to set on IIS.

    Regards,

    Amit Khurana

    Monday, April 10, 2017 10:28 AM

All replies

  • Does the user have Admin rights?

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Monday, April 10, 2017 10:37 AM
  • >>I have added DefaultAppPool user on all folder which I need access. Currently, cmd.exe entry shown in Task Manager and don't perform or execute bat file.

    Could you share us the code in WCF method and bat file? 

    To check whether it is related with WCF Service, I suggest you try to run the code and bat script in winform application.

    I made a test with below steps, it works at my side.

    1.Bat File

    echo. 2>EmptyFile.txt
     

    2.WCF Function

           public string GetValue(int value)
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = @"D:\Edward\Project\WCF2017\WCF2017\WCFRest\Test\Test.bat";
                proc.StartInfo.WorkingDirectory = @"D:\Edward\Project\WCF2017\WCF2017\WCFRest\Test\";
                proc.Start();
                return value.ToString();
            }

    3.Publish WCF Rest Service to IIS

    4.Access service from IE, it creates the file correctly.

    I suggest you try to add above bat files and WCF function in your current project to check whether it will work. If it works, I suggest you check whether you set "proc.StartInfo.WorkingDirectory" in your original code.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 11, 2017 4:31 AM