title: Windows service that runs a batch file
body: <p>I have developed a Windows service which runs on Windows server. The purpose of the service is to run a batch file on local system which further runs a Java-based thread. The problem is that when I log in to server using remote session the service starts normally but both batch file and Java thread run in the background but when I log in to server without using remote session, i.e. going physically where the server is, then both Java thread and batch file window appears. My question is how can I prevent both batch file and Java thread running in the background when I log in to the server using remote session. The code which runs the batch file is appended below:</p>
  
  <pre><code>public void RunBatchFile()
          {
              while (!this.isStopped)
              {
                  while (StartnStop)
                  {
                      foreach (object element in apps)
                      {
                          App_arr chkapp = (App_arr)element;
  
                          System.DateTime now_date = System.DateTime.Now;
                          System.DateTime last_date = new System.DateTime(chkapp.last_time.Year, chkapp.last_time.Month, chkapp.last_time.Day, chkapp.last_time.Hour, chkapp.last_time.Minute, chkapp.last_time.Second);
  
                          System.TimeSpan time_span = now_date.Subtract(last_date);
  
  
                          if (time_span.Minutes &gt;= chkapp.mins)
                          {
                            try
                              {
                                  p = new Process();
  
                                  string targetDir = string.Format(@chkapp.app_path.ToString().Substring(0, chkapp.app_path.ToString().LastIndexOf("\\")));
                                  p.StartInfo.WorkingDirectory = targetDir;
                                  string batch_file_name = chkapp.app_path.ToString().Substring(chkapp.app_path.ToString().LastIndexOf("\\") + 1);
                                  p.StartInfo.FileName = batch_file_name;
  
                                  p.StartInfo.Arguments = string.Format("C-Sharp CTF-Service Application");
                                  p.StartInfo.CreateNoWindow = false;
                                  //p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                                  p.Start();
  
  
                              }
                              catch (Win32Exception ex1)
                              {                              
                                  log.WriteEntry(ex1.Message + "\n" + ex1.StackTrace, EventLogEntryType.Error);
                                  sw.BaseStream.Seek(0, SeekOrigin.End);
                                  sw.WriteLine(ex1.Message);
                                  sw.Flush();
                              }
                          }
                      }
                      Thread.Sleep(40000);
                  }
              }
              fs.Close();
  
          }
  </code></pre>