Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.ServiceProcess;
- using System.Text;
- namespace VlcService
- {
- public class VlcService : ServiceBase
- {
- public const string MyServiceName = "VlcService";
- public static String VlcProcessName = "vlc";
- public static String VlcPath = "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe";
- public static String VlcAgrs = "-I http --sout-keep --http-password=\"qwerty\"";
- public VlcService()
- {
- InitializeComponent();
- }
- private void InitializeComponent()
- {
- this.ServiceName = MyServiceName;
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- }
- /// <summary>
- /// Start this service.
- /// </summary>
- protected override void OnStart(string[] args)
- {
- if (Process.GetProcessesByName(VlcProcessName).Length<1) {
- Process.Start(VlcPath,VlcAgrs);
- }
- }
- /// <summary>
- /// Stop this service.
- /// </summary>
- protected override void OnStop()
- {
- Process[] processes = Process.GetProcessesByName(VlcProcessName);
- if (processes.Length>0) {
- if (!processes[0].CloseMainWindow())
- processes[0].Kill();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement