Avatar of ankouny
ankouny
Flag 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
C#ASP.NET.NET Programming

Avatar of undefined
Last Comment
kaufmed

8/22/2022 - Mon
kaufmed

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.
ankouny

ASKER
How do I know which account it is running or using ?
kaufmed

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
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.
kaufmed

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).
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 ?  
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
kaufmed

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question