Created
July 6, 2011 17:59
-
-
Save ShinNoNoir/1067890 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.Diagnostics; | |
using System.Reflection; | |
namespace RestartSound | |
{ | |
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length == 1 && args[0] == "Phase2") { | |
Phase2(); | |
} | |
else | |
{ | |
Phase1(); | |
} | |
} | |
static void Phase1() | |
{ | |
if (StartPhase2()) | |
{ | |
// only start explorer.exe using Phase1 rights | |
// if Phase2 was started correctly | |
Process.Start("explorer.exe"); | |
} | |
} | |
static bool StartPhase2() | |
{ | |
ProcessStartInfo proc = new ProcessStartInfo(); | |
proc.UseShellExecute = true; | |
proc.WorkingDirectory = Environment.CurrentDirectory; | |
proc.FileName = Assembly.GetEntryAssembly().Location; | |
proc.Verb = "runas"; | |
proc.Arguments = "Phase2"; | |
try { | |
Process.Start(proc).WaitForExit();; | |
} | |
catch | |
{ | |
return false; | |
} | |
return true; | |
} | |
static void Phase2() | |
{ | |
Process.Start("taskkill", "/F /IM explorer.exe").WaitForExit(); | |
Process.Start("devcon", "disable *VEN_10EC*").WaitForExit(); | |
Process.Start("net", "stop \"Windows Audio\"").WaitForExit(); | |
Process.Start("devcon", "enable *VEN_10EC*").WaitForExit(); | |
Process.Start("net", "start \"Windows Audio\"").WaitForExit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment