C# – Audit Method Added to Jump Tool

email me

I have created a new audit method for my elevated tool to track usage.

static void Audit()
{
// create registry key

// set up strings
string reg1 = "HKEY_LOCAL_MACHINE";
string reg2 = @"SOFTWARE\XXXXX\XXXX";
string regPath = reg1 + @"\" + reg2;
string UName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string regVal = appName + " " + UName;

DateTime dt = DateTime.Now;

// create new reg key each time
Registry.SetValue(regPath, dt.ToString(), regVal, RegistryValueKind.String);


// log event

// set up strings 
string sSource;
string sLog;
string sEvent;

sSource = "ABC.exe";
sLog = "Application";

sEvent = appName + " was installed using the Jump tool by " + UName;

if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);

// create new event each time
EventLog.WriteEntry(sSource, sEvent);

// output to console
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("{{{ Security log has been updated }}}\n");
Console.ForegroundColor = ConsoleColor.White;
}