It's not executed.

Discussion in 'Mixed Languages' started by carmz, Jun 1, 2014.

  1. carmz

    carmz MDL Senior Member

    Nov 29, 2011
    311
    10
    10
    #1 carmz, Jun 1, 2014
    Last edited by a moderator: Apr 20, 2017
    Hi, I am creating simple windows services.but i think my test.bat did not executed, after i run my services.
    maybe the path is the problem for my test.bat.

    here is my code..

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Mysrv
    {
        public partial class MyService : ServiceBase
        {
            public MyService()
            {
                InitializeComponent();
            }
    
            protected override void OnStart(string[] args)
            {
                ProcessStartInfo processListener = new ProcessStartInfo{
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    FileName = "cmd.exe",
                    Arguments = string.Format("/C \"{0}\"", "C:\\wamp\\www\\test\\test.bat"),
                    WindowStyle = ProcessWindowStyle.Hidden,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    ErrorDialog = false
                };
              
                
            }
    
            protected override void OnStop()
            {
    
            }
        }
    }
    
    
    
    
     
  2. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    420
    198
    10
    The ProcessStartInfo class is just a container of information describing a process. You have to actually start the process by invoking Process.Start(processListener). See MSDN for additional documentation.
     
  3. carmz

    carmz MDL Senior Member

    Nov 29, 2011
    311
    10
    10

    Hi it's working now thank you so much.