0

From my previous question, Executing batch file in C# web service

I have checked the permission of all related stuff and found that:

batch file: permission = full control for all user

IIS user = myUser

..win32\cmd.exe: permission for system, admin, myUser = read&execute, read permission for "TrustedInstaller"(what is it?) = full control

Visual Studio is running under administrator mode.

I did some research on the Internet and it seems like I need to do something with 'Local Policies' on my machine. Unfortunately, I am using Windows Vista Home Premium, which seems like I cannot set local policies... I also try changing permission of cmd.exe to 'Full control', but it just doesn't allow me to do so.

It seems like I am facing an 'unsolvable' problem, so I will explain what I am doing so that someone may give me an idea what to do.

  • I have developed Blackberry application using blackberry simulator. It is on the same PC as my web service.

  • I developed web service in C#, published in my localhost.

  • Blackberry app upload a file to web service. Web service stores the file on my PC. (I have no problem with this part.)

  • There is one program on my PC, I will call it myprogram.exe. The program only runs on dos. The program will convert file from one file type to another file type using the command myprogram.exe path\oldfile.x path\newfile.y newfile.y will be created and stored on my PC automatically.

  • I need to convert the file that was sent from BB and is now storing on my local PC, so I wrote 1 batch file containing dos command. Web service should execute the batch file, but it wouldn't.

If i stop trying to work with batch file, is there any way i can to to execute those command? (or any way that I can run that external program) Please give me an idea. I have searched on the Internet and still doesn't get any idea. I don't know what to do now. T_T

PS. Forgive me if my questions are stupid. I just want to try every possible way to make this part of project success.

7
  • What for are you creating batch file instead of calling myprogram.exe directly. And what happens when you assign another user to your service instead of Local Service who has enough rights for operation you need? Commented Aug 14, 2011 at 16:18
  • I really don't know how to call myprogram.exe and input command to it directly. could you please give me and example? Commented Aug 14, 2011 at 16:53
  • I tried System.Diagnostics.Process.Start(@"C:\Program Files\TotalAudioConverter\AudioConverter.exe"); but nothing happen. Y_Y Commented Aug 14, 2011 at 17:01
  • Your AudioConverter.exe probably needs some arguments? So System.Diagnostics.Process.Start(@"C:\Program Files\TotalAudioConverter\AudioConverter.exe",@"C:\MyFolder\MyInFile C:\MyFolder\MyOutFile"); (or whenever parameters it needs) Commented Aug 14, 2011 at 17:46
  • so it means that i can put all parameters after C:\Program Files\TotalAudioConverter\AudioConverter.exe right? the full parameters are C:\MyFolder\MyInFile C:\MyFolder\MyOutFile c-mp3 so it will look like System.Diagnostics.Process.Start(@"C:\Program Files\TotalAudioConverter\AudioConverter.exe",@"C:\MyFolder\MyInFile C:\MyFolder\MyOutFile -cmp3"); right? really thanks for your help, elevener!!! i will try as soon as i can and will tell you the result :) Commented Aug 15, 2011 at 1:41

1 Answer 1

1

All I can think of is:

  1. Your ASP.NET website runs under the DefaultAppPool. The DefaultAppPool has only limited rights.

    In order to execute a batch file from within your service create a new application pool.

    a) Open Internet Information Services Manager (IIS 7). You will find the Internet Information Services Manager in your Windows Vista start menu.

    b) In the tree on the left side right click Application Pools and add a new application pool.

    c) Select your newly created application pool and click Advanced Settings.

    d) Under identity choose LocalSystem.

    e) In the tree select your web site (e.g. Default Web Site). Select basic settings and choose your created application pool.

    f) Restart your web site (right click your web site, under Manage your web site select restart).

    You should be able to execute your batch file. Here is an example:

    Process oProcess = new Process();

    oProcess.StartInfo.UseShellExecute = false;

    oProcess.StartInfo.WorkingDirectory = @"c:\temp\test";

    oProcess.StartInfo.FileName = @"c:\windows\system32\cmd.exe";

    oProcess.StartInfo.CreateNoWindow = true;

    oProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

    oProcess.StartInfo.Arguments = @"/C c:\temp\test\mybatch.bat";

    oProcess.Start();

    However, I do not recommend this approach.

  2. Rethink your design. I would recommend using a WCF-Service hosted in a Windows Service to execute your batch file. Then from your web service call the WCF-Service to execute your batch file like so (pseudo code):

    var wcfClient = new ConverterServiceClient();

    wcfClient.Convert(@"c:\temp\oldfile.x", "c:\temp\newfile.y");

    // Here your service has converted the file using your application.

    If you are tied to the .NET Framework 2.0 you could host a .NET Remoting service in your Windows Service application.

Hope, this helps.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks Hansjoerg! I will try and tell you the result! :)
Now, I have wwwroot using DefaultApplicationPool(network service) and MyApp using NewAppPool (local system). I still can't run batch file. I tried put <identity impersonate="true" userName="myuser" password="mypassword"/> in web.config, but nothing happen. please guide me what mistake i made.
I saw all process in task manager and there was a process of .exe program with user name = system. But I still don't understand why it was never executed. :(
I think your program was never executed because of Windows Vista's user account control (UAC). UAC limits apps to standard user privilegues.
Oh no... I am planning to change to another machine(Windows 7). Just hope I would not face this problem again on Windows 7. :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.