mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
fix shutdown didn't work issue
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -44,7 +45,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
SubTitle = "Shutdown Computer",
|
SubTitle = "Shutdown Computer",
|
||||||
Score = 100,
|
Score = 100,
|
||||||
IcoPath = "Images\\exit.png",
|
IcoPath = "Images\\exit.png",
|
||||||
Action = () => ExitWindowsEx(EWX_SHUTDOWN,0)
|
Action = () => Process.Start("shutdown","/s /t 0")
|
||||||
});
|
});
|
||||||
availableResults.Add(new Result
|
availableResults.Add(new Result
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Application x:Class="WinAlfred.App"
|
<Application x:Class="WinAlfred.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
StartupUri="MainWindow.xaml">
|
>
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<Style x:Key="defaultQueryBoxStyle" BasedOn="{x:Null}" TargetType="{x:Type TextBox}">
|
<Style x:Key="defaultQueryBoxStyle" BasedOn="{x:Null}" TargetType="{x:Type TextBox}">
|
||||||
|
|||||||
@@ -1,11 +1,28 @@
|
|||||||
using System.Windows;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
namespace WinAlfred
|
using System.Windows;
|
||||||
{
|
|
||||||
/// <summary>
|
namespace WinAlfred
|
||||||
/// App.xaml 的交互逻辑
|
{
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public partial class App : Application
|
/// App.xaml 的交互逻辑
|
||||||
{
|
/// </summary>
|
||||||
}
|
public partial class App : Application
|
||||||
}
|
{
|
||||||
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnStartup(e);
|
||||||
|
bool startupFlag;
|
||||||
|
Mutex mutex = new Mutex(true, "WinAlfred", out startupFlag);
|
||||||
|
if (!startupFlag)
|
||||||
|
{
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MainWindow mainWindow = new MainWindow();
|
||||||
|
mainWindow.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using IWshRuntimeLibrary;
|
||||||
|
using Microsoft.Win32;
|
||||||
using WinAlfred.Commands;
|
using WinAlfred.Commands;
|
||||||
using WinAlfred.Helper;
|
using WinAlfred.Helper;
|
||||||
using WinAlfred.Plugin;
|
using WinAlfred.Plugin;
|
||||||
@@ -101,12 +103,31 @@ namespace WinAlfred
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetAutoStart(bool IsAtuoRun)
|
||||||
|
{
|
||||||
|
string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk";
|
||||||
|
if (IsAtuoRun)
|
||||||
|
{
|
||||||
|
WshShell shell = new WshShell();
|
||||||
|
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath);
|
||||||
|
shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||||
|
shortcut.WorkingDirectory = Environment.CurrentDirectory;
|
||||||
|
shortcut.WindowStyle = 1; //normal window
|
||||||
|
shortcut.Description = "WinAlfred";
|
||||||
|
shortcut.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.IO.File.Delete(LnkPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Plugins.Init(this);
|
Plugins.Init(this);
|
||||||
cmdDispatcher = new Command(this);
|
cmdDispatcher = new Command(this);
|
||||||
InitialTray();
|
InitialTray();
|
||||||
|
SetAutoStart(true);
|
||||||
//var engine = new Jurassic.ScriptEngine();
|
//var engine = new Jurassic.ScriptEngine();
|
||||||
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
|
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,6 +189,17 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="app.ico" />
|
<Resource Include="app.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<COMReference Include="IWshRuntimeLibrary">
|
||||||
|
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
|
||||||
|
<VersionMajor>1</VersionMajor>
|
||||||
|
<VersionMinor>0</VersionMinor>
|
||||||
|
<Lcid>0</Lcid>
|
||||||
|
<WrapperTool>tlbimp</WrapperTool>
|
||||||
|
<Isolated>False</Isolated>
|
||||||
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
|
</COMReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user