static void Main(string[] args)
{
// Build an options object for the remote connection
// if you plan to connect to the remote
// computer with a different user name
// and password than the one +you are currently using.
// This example uses the default values. ConnectionOptions options =
new ConnectionOptions();
// options.Authentication = AuthenticationLevel.Call;
// options.Authority = "Security";
options.Impersonation = ImpersonationLevel.Impersonate;
options.EnablePrivileges = true; // Make a connection to a remote computer.
// Replace the "FullComputerName" section of the
// string "\\\\FullComputerName\\root\\cimv2" with
// the full computer name or IP address of the
// remote computer.
ManagementScope scope =
new ManagementScope(
"\\\\127.0.0.1\\root\\cimv2", options);
scope.Connect(); //Query system for Operating System information
ObjectQuery query = new ObjectQuery(
"SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Security' ");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query); ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine(m["TimeGenerated"].ToString());
Console.WriteLine();
Console.WriteLine();
}
Console.Read();
}C#不能通过WMI访问Security日志,但是可以访问Application、System日志。求访问Security日志的解决方案
{
// Build an options object for the remote connection
// if you plan to connect to the remote
// computer with a different user name
// and password than the one +you are currently using.
// This example uses the default values. ConnectionOptions options =
new ConnectionOptions();
// options.Authentication = AuthenticationLevel.Call;
// options.Authority = "Security";
options.Impersonation = ImpersonationLevel.Impersonate;
options.EnablePrivileges = true; // Make a connection to a remote computer.
// Replace the "FullComputerName" section of the
// string "\\\\FullComputerName\\root\\cimv2" with
// the full computer name or IP address of the
// remote computer.
ManagementScope scope =
new ManagementScope(
"\\\\127.0.0.1\\root\\cimv2", options);
scope.Connect(); //Query system for Operating System information
ObjectQuery query = new ObjectQuery(
"SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Security' ");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query); ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine(m["TimeGenerated"].ToString());
Console.WriteLine();
Console.WriteLine();
}
Console.Read();
}C#不能通过WMI访问Security日志,但是可以访问Application、System日志。求访问Security日志的解决方案
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货