Created
November 6, 2010 12:29
-
-
Save aont/665379 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.Runtime.InteropServices; | |
using System.Diagnostics; | |
namespace StandByPreventor | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var length = args.Length; | |
Process process = null; | |
switch (length) | |
{ | |
case 0: | |
Console.WriteLine("Not Specified..."); | |
Console.WriteLine("Press any key to exit"); | |
Console.ReadKey(); | |
break; | |
case 1: | |
process = Process.Start(new ProcessStartInfo(args[0])); | |
break; | |
default: | |
if (length > 2) | |
{ | |
var argments = new StringBuilder(); | |
for (int i = 1; i < args.Length; i++) | |
{ | |
argments.Append(args[i]); | |
argments.Append(' '); | |
process = Process.Start(new ProcessStartInfo(args[0], argments.ToString())); | |
} | |
} | |
else | |
{ | |
process = Process.Start(new ProcessStartInfo(args[0], args[1])); | |
} | |
break; | |
} | |
if (process == null) | |
return; | |
SetThreadExecutionState(ExecutionState.SystemRequired | ExecutionState.Continuous); | |
process.WaitForExit(); | |
} | |
[DllImport("kernel32.dll")] | |
extern static ExecutionState SetThreadExecutionState(ExecutionState esFlags); | |
} | |
[FlagsAttribute] | |
public enum ExecutionState : uint | |
{ | |
// 関数が失敗した時の戻り値 | |
Null = 0, | |
// スタンバイを抑止 | |
SystemRequired = 1, | |
// 画面OFFを抑止 | |
DisplayRequired = 2, | |
// 効果を永続させる。ほかオプションと併用する。 | |
Continuous = 0x80000000, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment