Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Сделано в SharpDevelop.
- * Пользователь: Андрей Михайлович
- * Дата: 18.03.2015
- * Время: 10:11
- *
- * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
- */
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.ServiceProcess;
- using System.Text;
- using Microsoft.Win32;
- namespace scrblckService
- {
- public class scrblckService : ServiceBase
- {
- public const string MyServiceName = "scrblckService";
- public scrblckService()
- {
- InitializeComponent();
- }
- void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
- {
- Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
- if ((e.Reason == SessionSwitchReason.SessionLock) || (e.Reason == SessionSwitchReason.SessionLogoff))
- {
- //I left my desk
- Process[] proc = Process.GetProcessesByName("ScreenBlocker");
- foreach (Process prs in proc)
- {
- prs.Kill();
- }
- Process[] proc2 = Process.GetProcessesByName("ScreenStream");
- foreach (Process prs in proc2)
- {
- prs.Kill();
- }
- }
- else if ((e.Reason == SessionSwitchReason.SessionUnlock) || (e.Reason == SessionSwitchReason.SessionLogon))
- {
- //I returned to my desk
- Process[] proc = Process.GetProcessesByName("ScreenBlocker");
- int count = 0;
- foreach (Process prs in proc)
- {
- count++;
- }
- if (count > 0)
- {
- try
- {
- Process.Start(@"C:\Program Files\ScreenBlocker\ScreenBlocker.exe");
- }
- catch
- {
- Process.Start(@"C:\Program Files (x86)\ScreenBlocker\ScreenBlocker.exe");
- }
- }
- }
- }
- private void InitializeComponent()
- {
- this.ServiceName = MyServiceName;
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose(bool disposing)
- {
- // TODO: Add cleanup code here (if required)
- base.Dispose(disposing);
- }
- /// <summary>
- /// Start this service.
- /// </summary>
- protected override void OnStart(string[] args)
- {
- // TODO: Add start code here (if required) to start your service.
- }
- /// <summary>
- /// Stop this service.
- /// </summary>
- protected override void OnStop()
- {
- // TODO: Add tear-down code here (if required) to stop your service.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement