Advertisement
overloop

vlc_service.cs

Aug 1st, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.ServiceProcess;
  7. using System.Text;
  8.  
  9. namespace VlcService
  10. {
  11.     public class VlcService : ServiceBase
  12.     {
  13.         public const string MyServiceName = "VlcService";
  14.        
  15.         public static String VlcProcessName = "vlc";
  16.         public static String VlcPath = "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe";
  17.         public static String VlcAgrs = "-I http --sout-keep --http-password=\"qwerty\"";
  18.    
  19.         public VlcService()
  20.         {
  21.             InitializeComponent();
  22.            
  23.         }
  24.        
  25.         private void InitializeComponent()
  26.         {
  27.             this.ServiceName = MyServiceName;
  28.         }
  29.        
  30.         /// <summary>
  31.         /// Clean up any resources being used.
  32.         /// </summary>
  33.         protected override void Dispose(bool disposing)
  34.         {
  35.             base.Dispose(disposing);
  36.         }
  37.        
  38.         /// <summary>
  39.         /// Start this service.
  40.         /// </summary>
  41.         protected override void OnStart(string[] args)
  42.         {
  43.             if (Process.GetProcessesByName(VlcProcessName).Length<1) {
  44.                 Process.Start(VlcPath,VlcAgrs);
  45.             }
  46.         }
  47.        
  48.         /// <summary>
  49.         /// Stop this service.
  50.         /// </summary>
  51.         protected override void OnStop()
  52.         {
  53.             Process[] processes = Process.GetProcessesByName(VlcProcessName);
  54.             if (processes.Length>0) {
  55.                 if (!processes[0].CloseMainWindow())
  56.                     processes[0].Kill();
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement