Created
September 7, 2012 19:25
-
-
Save DanSmith/3668859 to your computer and use it in GitHub Desktop.
Powershell script to register a windows event log source
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
# https://github.com/dansmith | |
# | |
$source = "My Application Name" | |
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent() | |
$prp=new-object System.Security.Principal.WindowsPrincipal($wid) | |
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator | |
$IsAdmin=$prp.IsInRole($adm) | |
if($IsAdmin -eq $false) | |
{ | |
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | |
[Windows.Forms.MessageBox]::Show(“Please run this as an Administrator”, | |
“Not Administrator”, | |
[Windows.Forms.MessageBoxButtons]::OK, | |
[Windows.Forms.MessageBoxIcon]::Information) | |
exit | |
} | |
if ([System.Diagnostics.EventLog]::SourceExists($source) -eq $false) | |
{ | |
[System.Diagnostics.EventLog]::CreateEventSource($source, "Application") | |
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | |
[Windows.Forms.MessageBox]::Show(“Event log created successfully”, | |
“Complete”, | |
[Windows.Forms.MessageBoxButtons]::OK, | |
[Windows.Forms.MessageBoxIcon]::Information) | |
} | |
else | |
{ | |
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | |
[Windows.Forms.MessageBox]::Show(“Event log already exists”, | |
“Complete”, | |
[Windows.Forms.MessageBoxButtons]::OK, | |
[Windows.Forms.MessageBoxIcon]::Information) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment