PowerToys/WinAlfred.Plugin.System/Sys.cs

84 lines
2.4 KiB
C#
Raw Normal View History

2013-12-21 16:44:56 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2013-12-22 11:35:21 +00:00
using System.Runtime.InteropServices;
2013-12-21 16:44:56 +00:00
using System.Text;
2013-12-22 11:35:21 +00:00
using System.Windows.Forms;
2013-12-21 16:44:56 +00:00
namespace WinAlfred.Plugin.System
{
2014-01-03 15:52:36 +00:00
public class Sys : ISystemPlugin
2013-12-21 16:44:56 +00:00
{
2013-12-22 11:35:21 +00:00
List<Result> availableResults = new List<Result>();
2014-01-04 12:26:13 +00:00
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;
2013-12-22 11:35:21 +00:00
[DllImport("user32")]
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
[DllImport("user32")]
public static extern void LockWorkStation();
2013-12-21 16:44:56 +00:00
public List<Result> Query(Query query)
{
2013-12-22 11:35:21 +00:00
List<Result> results = new List<Result>();
2014-01-03 15:52:36 +00:00
foreach (Result availableResult in availableResults)
2013-12-22 11:35:21 +00:00
{
2014-01-03 15:52:36 +00:00
if (availableResult.Title.ToLower().StartsWith(query.RawQuery.ToLower()))
{
results.Add(availableResult);
}
2013-12-21 16:44:56 +00:00
}
return results;
}
2014-01-03 15:52:36 +00:00
public void Init(PluginInitContext context)
2013-12-21 16:44:56 +00:00
{
2013-12-22 11:35:21 +00:00
availableResults.Add(new Result
{
Title = "Shutdown",
SubTitle = "Shutdown Computer",
Score = 100,
2014-01-04 12:26:13 +00:00
IcoPath = "Images\\exit.png",
Action = () => ExitWindowsEx(EWX_SHUTDOWN,0)
2013-12-22 11:35:21 +00:00
});
availableResults.Add(new Result
{
Title = "Log off",
SubTitle = "Log off current user",
2014-01-04 12:26:13 +00:00
Score = 20,
IcoPath = "Images\\logoff.png",
Action = () => ExitWindowsEx(EWX_LOGOFF, 0)
2013-12-22 11:35:21 +00:00
});
availableResults.Add(new Result
{
Title = "Lock",
SubTitle = "Lock this computer",
Score = 20,
IcoPath = "Images\\lock.png",
Action = () => LockWorkStation()
2014-01-03 15:52:36 +00:00
});
}
public string Name
{
get
{
return "sys";
}
}
public string Description
{
get
{
return "provide system commands";
}
2013-12-21 16:44:56 +00:00
}
}
}