Solved

Execute batch file using windows service

Posted on 2013-01-15
3
1,996 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Jaroslav Mraz earned 500 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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