-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fuzzdeveloper
committed
May 1, 2019
0 parents
commit db75813
Showing
6 changed files
with
395 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.sln.docstates | ||
|
||
# Build results | ||
|
||
[Dd]ebug/ | ||
[Rr]elease/ | ||
x64/ | ||
build/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
.vs/ | ||
|
||
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets | ||
!packages/*/build/ | ||
|
||
# MSTest test Results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
*_i.c | ||
*_p.c | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.log | ||
*.scc | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opensdf | ||
*.sdf | ||
*.cachefile | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
|
||
# Guidance Automation Toolkit | ||
*.gpState | ||
|
||
# ReSharper is a .NET coding add-in | ||
_ReSharper*/ | ||
*.[Rr]e[Ss]harper | ||
|
||
# TeamCity is a build add-in | ||
_TeamCity* | ||
|
||
# DotCover is a Code Coverage Tool | ||
*.dotCover | ||
|
||
# NCrunch | ||
*.ncrunch* | ||
.*crunch*.local.xml | ||
|
||
# Installshield output folder | ||
[Ee]xpress/ | ||
|
||
# DocProject is a documentation generator add-in | ||
DocProject/buildhelp/ | ||
DocProject/Help/*.HxT | ||
DocProject/Help/*.HxC | ||
DocProject/Help/*.hhc | ||
DocProject/Help/*.hhk | ||
DocProject/Help/*.hhp | ||
DocProject/Help/Html2 | ||
DocProject/Help/html | ||
|
||
# Click-Once directory | ||
publish/ | ||
|
||
# Publish Web Output | ||
*.Publish.xml | ||
|
||
# NuGet Packages Directory | ||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line | ||
packages/ | ||
|
||
# Windows Azure Build Output | ||
csx | ||
*.build.csdef | ||
|
||
# Windows Store app package directory | ||
AppPackages/ | ||
|
||
# Others | ||
sql/ | ||
*.Cache | ||
ClientBin/ | ||
[Ss]tyle[Cc]op.* | ||
~$* | ||
*~ | ||
*.dbmdl | ||
*.[Pp]ublish.xml | ||
*.pfx | ||
*.publishsettings | ||
|
||
# RIA/Silverlight projects | ||
Generated_Code/ | ||
|
||
# Backup & report files from converting an old project file to a newer | ||
# Visual Studio version. Backup files are not needed, because we have git ;-) | ||
_UpgradeReport_Files/ | ||
Backup*/ | ||
UpgradeLog*.XML | ||
UpgradeLog*.htm | ||
|
||
# SQL Server files | ||
App_Data/*.mdf | ||
App_Data/*.ldf | ||
|
||
|
||
#LightSwitch generated files | ||
GeneratedArtifacts/ | ||
_Pvt_Extensions/ | ||
ModelManifest.xml | ||
|
||
# ========================= | ||
# Windows detritus | ||
# ========================= | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Mac desktop service store files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28010.2046 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdleShutdown", "IdleShutdown\IdleShutdown.csproj", "{BED6D4AE-A833-4047-89CD-E28650B29C66}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{BED6D4AE-A833-4047-89CD-E28650B29C66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BED6D4AE-A833-4047-89CD-E28650B29C66}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BED6D4AE-A833-4047-89CD-E28650B29C66}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BED6D4AE-A833-4047-89CD-E28650B29C66}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B6CAD42E-35A8-4A4B-BD03-B87C85698FE2} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{BED6D4AE-A833-4047-89CD-E28650B29C66}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>IdleShutdown</RootNamespace> | ||
<AssemblyName>IdleShutdown</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
namespace IdleShutdown | ||
{ | ||
class Program | ||
{ | ||
internal struct LASTINPUTINFO | ||
{ | ||
public uint cbSize; | ||
public uint dwTime; | ||
} | ||
|
||
[DllImport("User32.dll")] | ||
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); | ||
|
||
private static long GetLastInputTime() | ||
{ | ||
LASTINPUTINFO lastInPut = new LASTINPUTINFO(); | ||
lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut); | ||
if (!GetLastInputInfo(ref lastInPut)) | ||
{ | ||
throw new Exception("Call to GetLastInputInfo failed"); | ||
} | ||
return lastInPut.dwTime; | ||
} | ||
|
||
[DllImport("powrprof.dll")] | ||
private static extern uint CallNtPowerInformation(int informationLevel, IntPtr lpInputBuffer, uint nInputBufferSize, IntPtr lpOutputBuffer, uint nOutputBufferSize); | ||
|
||
private static uint GetSystemExecutionState() | ||
{ | ||
int size = Marshal.SizeOf(typeof(ulong)); | ||
IntPtr status = Marshal.AllocCoTaskMem(size); | ||
if (0 != CallNtPowerInformation(16, (IntPtr)null, 0, status, (uint)size)) | ||
{ | ||
Marshal.FreeCoTaskMem(status); | ||
throw new Exception("Call to CallNtPowerInformation failed"); | ||
} | ||
uint statusVal = (uint)Marshal.ReadInt32(status); | ||
Marshal.FreeCoTaskMem(status); | ||
return statusVal; | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
long msIdleBeforeShutdown = -1; | ||
int secondsShutdownTimer = -1; | ||
if (args.Length > 0) | ||
{ | ||
try | ||
{ | ||
msIdleBeforeShutdown = Convert.ToInt32(args[0]) * 1000L; | ||
secondsShutdownTimer = Convert.ToInt32(args[1]); | ||
} | ||
catch (FormatException) | ||
{ | ||
msIdleBeforeShutdown = -1; | ||
secondsShutdownTimer = -1; | ||
} | ||
} | ||
if (msIdleBeforeShutdown < 0 || secondsShutdownTimer < 0) | ||
{ | ||
System.Windows.Forms.MessageBox.Show("Usage:\n IdleShutdown [idle-time] [shutdown-time]\n\nNote: Time specified in seconds", "Invalid Parameters Used"); | ||
Environment.ExitCode = 1; | ||
return; | ||
} | ||
//run the idle detection and call to shutdown.exe in an endless loop - that way if user | ||
//aborts shutdown (via shutdown /a) we loop back to detecting next idle condition | ||
while (true) | ||
{ | ||
while (true) | ||
{ | ||
//GetSystemExecutionState() will return value other than 0 if movie player running, network share in use, etc | ||
if (0 != GetSystemExecutionState()) | ||
{ | ||
Thread.Sleep((int)(int.MaxValue & msIdleBeforeShutdown)); | ||
continue; | ||
} | ||
long lastInputTime = Environment.TickCount - GetLastInputTime(); | ||
if (msIdleBeforeShutdown <= lastInputTime) | ||
break; | ||
Thread.Sleep((int)(int.MaxValue & (msIdleBeforeShutdown - lastInputTime))); | ||
} | ||
System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); | ||
pProcess.StartInfo.FileName = @"shutdown.exe"; | ||
pProcess.StartInfo.Arguments = "/s /t " + secondsShutdownTimer; | ||
pProcess.StartInfo.UseShellExecute = false; | ||
pProcess.StartInfo.RedirectStandardOutput = true; | ||
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | ||
pProcess.StartInfo.CreateNoWindow = true; | ||
pProcess.Start(); | ||
pProcess.WaitForExit(); | ||
pProcess.Dispose(); | ||
Thread.Sleep(secondsShutdownTimer * 1000 + 16000); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("IdleShutdown")] | ||
[assembly: AssemblyDescription("Shutdown computer when idle")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("IdleShutdown")] | ||
[assembly: AssemblyCopyright("Copyright © 2019")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("bed6d4ae-a833-4047-89cd-e28650b29c66")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.