Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Csharp running batch file Issue

Posted on 2011-10-04
7
Medium Priority
?
382 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:ankouny
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36909727
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.
0
 

Author Comment

by:ankouny
ID: 36909735
How do I know which account it is running or using ?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36909760
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.
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 

Author Comment

by:ankouny
ID: 36909785
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.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36909928
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).
0
 

Author Comment

by:ankouny
ID: 36910415
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 ?  
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 36910857
You have to understand how PSExcec works. Giving the web-site's user rights to execute the program is one thing; having rights on the remote machine is another thing. You either need to pass a username and password to PSExec in the batch file or you need to run your web-site as a user that has rights on both machines.

For more info on PSExec, see: http://technet.microsoft.com/en-us/sysinternals/bb897553 , particularly the blurb under "program arguments."
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question