Created
October 21, 2010 14:25
-
-
Save tfl/638576 to your computer and use it in GitHub Desktop.
Compile and run it as scheduled task - it fails here! It does not fail when run logged on.
This file contains hidden or 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 Microsoft.Win32; | |
using System.IO; | |
using System.Security.Principal; | |
namespace regtest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
StreamWriter sw = new StreamWriter("regtest.log"); | |
try | |
{ | |
RegistryKey HKLM = Registry.LocalMachine; | |
try | |
{ | |
WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); | |
string isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator) ? "Yes" : "No"; | |
sw.WriteLine("Is the user admin: " + isAdmin); | |
// Apply Your path here!! | |
RegistryKey General = HKLM.OpenSubKey("your\\path\\here", false); | |
try | |
{ | |
// Apply Your setting!! | |
sw.WriteLine("OK: " + General.GetValue("@YOUR KEY@")"); | |
} | |
catch (Exception c) | |
{ | |
sw.WriteLine("Could not read key: " + c.ToString()); | |
} | |
} | |
catch (Exception b) | |
{ | |
sw.WriteLine("Could not open path: " + b.ToString()); | |
} | |
} | |
catch (Exception a) | |
{ | |
sw.WriteLine("Could not open HKLM: " + a.ToString()); | |
} | |
sw.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment