Link to home
Start Free TrialLog in
Avatar of ankouny
ankounyFlag for United States of America

asked on

Csharp running batch file Issue

Hi,
I'm trying to run a batch file on the server using an asp.net csharp webpage. After I execute below code  the batch is not showing that it is running and the webpage is not throwing an error.
Here is the code in the webpage button :
string str_Path = Server.MapPath(".") + "\\TLogExecutor.bat";
            ProcessStartInfo processInfo = new ProcessStartInfo(str_Path);
            processInfo.UseShellExecute = false;
            Process batchProcess = new Process();
            batchProcess.StartInfo = processInfo;
            batchProcess.Start();

------------------------------------------------
Here is the batch file code :
PSEXEC -accepteula \\tlog-server "e:\Sched_Processes\TLogExecutor_Launch_Rerun.bat" > D:\Inetpub\wwwroot_2\TLogStatus\Log.txt

Please notice that Batch file is trying to run another batch on another server ?
Any suggestions ?

Thanks
Avatar of kaufmed
kaufmed
Flag of United States of America image

Does the account you're running your web page (app pool) as have permissions on the other server? PSExec will use the account that is executing it if you do not specify a username and password for the remote machine.
Avatar of ankouny

ASKER

How do I know which account it is running or using ?
If you haven't assigned an app pool specifically, then it is most likely using the default app pool and running as the ASPNET user. It might be easier for you to create a service account on the remote machine and pass the username and password in the command line. However, this could be a security concern. You may want to do this, though, so that you can test that it actually works. If it works at that point, you can go back and fiddle with your IIS user accounts to avoid having to pass credentials on the command line.

By "command line" I am referring to the "PSEXEC..." line you have in your batch file.
Avatar of ankouny

ASKER

If I go now to the server and run this batch file manually, it works, but when I run the Csharp code above it wont run and it wont throw an error.
Right. When you log into the server, you are not using the ASPNET user; you are using, most likely, your account. You probably have an account on the remote machine as well (or you are a member of a domain and you are registered on that machine). When you log into the local server and run PSExec, your credentials are sent to the remote machine to confirm that you have an account there (or on the domain).
Avatar of ankouny

ASKER

Your right, I'm trying to login using my domain name credentials, but I 've also added in the security properties of this batch file the aspnet user to read and execute but it is not executing ...
Should I schedule the batch file to run through SQL server and then I call SQL serevre job through the web page ? is it a good idea to do this ?  
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial