Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Execute batch file using windows service

Posted on 2013-01-15
3
Medium Priority
?
2,202 Views
Last Modified: 2013-01-16
I tried almost first 2 pages of google search with text "calling batch file from windows service". Still no luck. Also tried to edit registry of service (my service) as suggested in one of the link. My service is running under "Network services" account

Here is my sample code

private static void InvokeBatchFile()
        {
            using (System.Diagnostics.Process process = new System.Diagnostics.Process())
            {
                process.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);
                process.StartInfo = new System.Diagnostics.ProcessStartInfo(@"c:\windows\system32\cmd.exe");
                process.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe");

               process.StartInfo.Arguments = string.Format(@"/C C:\data\test.bat");
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.ErrorDialog = false;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.RedirectStandardInput = true;

                process.Start();

             

            }
        }

Open in new window


Batch file code

echo "Batch file invoked" >> kiran.txt

Open in new window

0
Comment
Question by:sonawanekiran
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Jaroslav Mraz earned 1500 total points
ID: 38778028
Hi,

it looks like the problem is your account :) Network services account have minimum rights to local computer. Cant you make normla accoun just for the service or you your onw to test.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684272(v=vs.85).aspx
0
 
LVL 17

Author Comment

by:sonawanekiran
ID: 38781738
I tried with all account still no luck. Even I didn't get error....
0
 
LVL 17

Author Closing Comment

by:sonawanekiran
ID: 38785684
Your solution doesn't help...
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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