本文整理汇总了C#中System.Management.EnumerationOptions类的典型用法代码示例。如果您正苦于以下问题:C# EnumerationOptions类的具体用法?C# EnumerationOptions怎么用?C# EnumerationOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EnumerationOptions类属于System.Management命名空间,在下文中一共展示了EnumerationOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var sb = new StringBuilder();
var scope = Wmi.GetScope();
var enumOptions = new EnumerationOptions { EnsureLocatable = true };
var processor = Processor.GetInstances(scope, enumOptions).Cast<Processor>().FirstOrDefault();
if (processor != null)
{
sb.AppendLine(string.Format("{0,-22} {1}", "Name:", processor.Name));
sb.AppendLine(string.Format("{0,-22} {1} ({2}-bit)", "Architecture:",
processor.Architecture.GetDescription(), processor.DataWidth));
sb.AppendLine(string.Format("{0,-22} {1}", "Processor ID:", processor.ProcessorId));
}
sb.AppendLine();
var os = new OperatingSystem0(scope);
{
sb.AppendLine(string.Format("{0,-22} {1} [{2}] ({3})", "Operating System:", os.Caption, os.Version, os.OSArchitecture));
sb.AppendLine(string.Format("{0,-22} {1:yyyy-MM-dd HH:mm:ss} ({2,3:dd} days {2:hh}:{2:mm}:{2:ss})",
"Install Date", os.InstallDate, (DateTime.Now - os.InstallDate)));
sb.AppendLine(string.Format("{0,-22} {1:yyyy-MM-dd HH:mm:ss} ({2,3:dd} days {2:hh}:{2:mm}:{2:ss})",
"Last boot", os.LastBootUpTime, (DateTime.Now - os.LastBootUpTime)));
}
sb.AppendLine();
Console.WriteLine(sb.ToString());
Console.Write("Press any key to continue...");
Console.ReadKey();
}
开发者ID:b1thunt3r,项目名称:WinInfo,代码行数:31,代码来源:Program.cs
示例2: TriggerClientAction
public void TriggerClientAction(string scheduleId, ManagementScope remote)
{
ObjectQuery query = new SelectQuery("SELECT * FROM meta_class WHERE __Class = 'SMS_Client'");
var eOption = new EnumerationOptions();
var searcher = new ManagementObjectSearcher(remote, query, eOption);
var queryCollection = searcher.Get();
foreach (ManagementObject ro in queryCollection)
{
// Obtain in-parameters for the method
var inParams = ro.GetMethodParameters("TriggerSchedule");
// Add the input parameters.
inParams["sScheduleID"] = scheduleId;
try
{
var outParams = ro.InvokeMethod("TriggerSchedule", inParams, null);
ResultConsole.Instance.AddConsoleLine($"Returned with value {_wmiServices.GetProcessReturnValueText(Convert.ToInt32(outParams["ReturnValue"]))}");
}
catch (Exception ex)
{
ResultConsole.Instance.AddConsoleLine("Error performing SCCM Client Function due to an error.");
_logger.LogError($"Error performing SCCM Client Function due to the following error: {ex.Message}", ex);
}
}
}
开发者ID:ZXeno,项目名称:Andromeda,代码行数:28,代码来源:SccmClientServices.cs
示例3: GetManagementObjects
static IEnumerable<byte[]> GetManagementObjects()
{
var options = new EnumerationOptions {Rewindable = false, ReturnImmediately = true};
var scope = new ManagementScope(ManagementPath.DefaultPath);
var query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapter");
var searcher = new ManagementObjectSearcher(scope, query, options);
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject obj in collection)
{
byte[] bytes;
try
{
PropertyData propertyData = obj.Properties["MACAddress"];
string propertyValue = propertyData.Value.ToString();
bytes = propertyValue.Split(':')
.Select(x => byte.Parse(x, NumberStyles.HexNumber))
.ToArray();
}
catch (Exception)
{
continue;
}
if (bytes.Length == 6)
yield return bytes;
}
}
开发者ID:Xamarui,项目名称:NewId,代码行数:30,代码来源:WMINetworkAddressWorkerIdProvider.cs
示例4: Should_pull_using_WMI
public void Should_pull_using_WMI()
{
var options = new EnumerationOptions {Rewindable = false, ReturnImmediately = true};
var scope = new ManagementScope(ManagementPath.DefaultPath);
var query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapter");
var searcher = new ManagementObjectSearcher(scope, query, options);
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject obj in collection)
{
try
{
PropertyData typeData = obj.Properties["AdapterType"];
string typeValue = typeData.Value.ToString();
PropertyData propertyData = obj.Properties["MACAddress"];
string propertyValue = propertyData.Value.ToString();
Console.WriteLine("Adapter: {0}-{1}", propertyValue, typeValue);
}
catch (Exception ex)
{
}
}
}
开发者ID:Xamarui,项目名称:NewId,代码行数:25,代码来源:NetworkAddress_Specs.cs
示例5: MyGetSearcher
private static ManagementObjectSearcher MyGetSearcher(ManagementScope scope, string myquery)
{
EnumerationOptions options = new EnumerationOptions();
options.Rewindable = false;
options.ReturnImmediately = true;
return new ManagementObjectSearcher(scope, new ObjectQuery(myquery), options);
}
开发者ID:jonaslsl,项目名称:modSIC,代码行数:8,代码来源:FileMethod.cs
示例6: ExecuteQueryReturnJSON
public string ExecuteQueryReturnJSON(string query)
{
ManagementObjectSearcher searcher;
searcher = new ManagementObjectSearcher(Scope, query);
EnumerationOptions options = new EnumerationOptions();
options.ReturnImmediately = true;
ManagementObjectCollection res = searcher.Get();
return DataConverter.DataTableToJSON(WmiToDataTable(res));
}
开发者ID:nicoriff,项目名称:NinoJS,代码行数:12,代码来源:WMI.cs
示例7: ManagementObjectCollection
//internal IWbemServices GetIWbemServices () {
// return scope.GetIWbemServices ();
//}
//internal ConnectionOptions Connection {
// get { return scope.Connection; }
//}
//Constructor
internal ManagementObjectCollection(
ManagementScope scope,
EnumerationOptions options,
IEnumWbemClassObject enumWbem)
{
if (null != options)
this.options = (EnumerationOptions) options.Clone();
else
this.options = new EnumerationOptions ();
if (null != scope)
this.scope = (ManagementScope)scope.Clone ();
else
this.scope = ManagementScope._Clone(null);
this.enumWbem = enumWbem;
}
开发者ID:JianwenSun,项目名称:cc,代码行数:26,代码来源:ManagementObjectCollection.cs
示例8: ExecuteTask
protected override void ExecuteTask() {
try {
ObjectQuery query = new ObjectQuery("SELECT * FROM MSBTS_Orchestration"
+ " WHERE Name = " + SqlQuote(OrchestrationName));
EnumerationOptions enumerationOptions = new EnumerationOptions();
enumerationOptions.ReturnImmediately = false;
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query, enumerationOptions)) {
ManagementObjectCollection orchestrations = searcher.Get();
// ensure we found a matching orchestration
if (orchestrations.Count == 0) {
throw new BuildException(string.Format(CultureInfo.InvariantCulture,
"Orchestration \"{0}\" does not exist on \"{0}\".",
OrchestrationName, Server), Location);
}
// perform actions on each matching orchestration
foreach (ManagementObject orchestration in orchestrations) {
try {
// invoke each action in the order in which they
// were added (in the build file)
foreach (IOrchestrationAction action in _actions) {
action.Invoke(orchestration);
}
} catch (Exception ex) {
if (FailOnError) {
throw;
}
// log exception and continue processing the actions
// for the next orchestration
Log(Level.Error, ex.Message);
}
}
}
} catch (BuildException) {
throw;
} catch (Exception ex) {
throw new BuildException("Error looking up orchestration(s).",
Location, ex);
}
}
开发者ID:kiprainey,项目名称:nantcontrib,代码行数:44,代码来源:Orchestration.cs
示例9: WmiInformationGatherer
/// <summary>
/// Targets the specified namespace on a specified computer, and scavenges it for all classes, if the bool is set to true. If false, it is used to setup the ManagementPath which
/// consists of the specified system and specified namespace
/// </summary>
/// <param name="pNamespace"></param>
/// <param name="pHostName"></param>
public WmiInformationGatherer(string pNamespace, string pHostName, bool pScavenge)
{
mRemoteWmiPath = new ManagementPath(@"\\" + pHostName + @"\root\" + pNamespace);
if (pScavenge)
{
try
{
ManagementClass managementClass = new ManagementClass(mRemoteWmiPath);
EnumerationOptions scavengeOptions = new EnumerationOptions();
scavengeOptions.EnumerateDeep = false;
WmiResults = new WmiResult(pHostName);
WmiResults.PopulateClassesList(managementClass.GetSubclasses());
}
catch (Exception e)
{
WmiResults.WmiError = e;
}
}
}
开发者ID:Sparse,项目名称:MultiRDP,代码行数:26,代码来源:WmiInformationGatherer.cs
示例10: ManagementObjectSearcher
public ManagementObjectSearcher(ManagementScope scope, ObjectQuery query, EnumerationOptions options)
{
this.scope = ManagementScope._Clone(scope);
if (query != null)
{
this.query = (ObjectQuery) query.Clone();
}
else
{
this.query = new ObjectQuery();
}
if (options != null)
{
this.options = (EnumerationOptions) options.Clone();
}
else
{
this.options = new EnumerationOptions();
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:ManagementObjectSearcher.cs
示例11: ManagementObjectCollection
internal ManagementObjectCollection(ManagementScope scope, EnumerationOptions options, IEnumWbemClassObject enumWbem)
{
if (options != null)
{
this.options = (EnumerationOptions) options.Clone();
}
else
{
this.options = new EnumerationOptions();
}
if (scope != null)
{
this.scope = scope.Clone();
}
else
{
this.scope = ManagementScope._Clone(null);
}
this.enumWbem = enumWbem;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:ManagementObjectCollection.cs
示例12: GetInstances
public static BcdObjectCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions)
{
if ((mgmtScope == null)) {
if ((statMgmtScope == null)) {
mgmtScope = new System.Management.ManagementScope();
mgmtScope.Path.NamespacePath = "root\\WMI";
}
else {
mgmtScope = statMgmtScope;
}
}
System.Management.ManagementPath pathObj = new System.Management.ManagementPath();
pathObj.ClassName = "BcdObject";
pathObj.NamespacePath = "root\\WMI";
System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null);
if ((enumOptions == null)) {
enumOptions = new System.Management.EnumerationOptions();
enumOptions.EnsureLocatable = true;
}
return new BcdObjectCollection(clsObject.GetInstances(enumOptions));
}
开发者ID:dgrapp1,项目名称:WindowsSDK7-Samples,代码行数:21,代码来源:ROOT.WMI.BcdObject.cs
示例13: ConnectGetWMI
//.........这里部分代码省略.........
}
connectArray.Add(scope);
currentNamesapceCount++;
}
if ((sinkArray.Count != namespaceArray.Count) || (connectArray.Count != namespaceArray.Count)) // not expected throw exception
{
internalException = new InvalidOperationException();
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
return;
}
currentNamesapceCount = 0;
while (currentNamesapceCount < namespaceArray.Count)
{
string connectNamespace = (string)namespaceArray[currentNamesapceCount];
ManagementObjectSearcher searcher = getObject.GetObjectList((ManagementScope)connectArray[currentNamesapceCount]);
if (searcher == null)
{
currentNamesapceCount++;
continue;
}
if (topNamespace)
{
topNamespace = false;
searcher.Get(_results);
}
else
{
searcher.Get((ManagementOperationObserver)sinkArray[currentNamesapceCount]);
}
currentNamesapceCount++;
}
}
else
{
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(_computerName, getObject.Namespace), options);
scope.Connect();
ManagementObjectSearcher searcher = getObject.GetObjectList(scope);
if (searcher == null)
throw new ManagementException();
searcher.Get(_results);
}
}
catch (ManagementException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.Runtime.InteropServices.COMException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.UnauthorizedAccessException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
return;
}
string queryString = string.IsNullOrEmpty(getObject.Query) ? GetWmiQueryString() : getObject.Query;
ObjectQuery query = new ObjectQuery(queryString.ToString());
try
{
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(_computerName, getObject.Namespace), options);
EnumerationOptions enumOptions = new EnumerationOptions();
enumOptions.UseAmendedQualifiers = getObject.Amended;
enumOptions.DirectRead = getObject.DirectRead;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, enumOptions);
// Execute the WMI command for each count value.
for (int i = 0; i < _cmdCount; ++i)
{
searcher.Get(_results);
}
}
catch (ManagementException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.Runtime.InteropServices.COMException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
catch (System.UnauthorizedAccessException e)
{
internalException = e;
_state = WmiState.Failed;
RaiseOperationCompleteEvent(null, OperationState.StopComplete);
}
}
开发者ID:dfinke,项目名称:powershell,代码行数:101,代码来源:WMIHelper.cs
示例14: GetInstances
public static PerfFormattedData_Counters_ProcessorInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions)
{
if ((mgmtScope == null)) {
if ((statMgmtScope == null)) {
mgmtScope = new System.Management.ManagementScope();
mgmtScope.Path.NamespacePath = "root\\CIMV2";
}
else {
mgmtScope = statMgmtScope;
}
}
System.Management.ManagementPath pathObj = new System.Management.ManagementPath();
pathObj.ClassName = "Win32_PerfFormattedData_Counters_ProcessorInformation";
pathObj.NamespacePath = "root\\CIMV2";
System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null);
if ((enumOptions == null)) {
enumOptions = new System.Management.EnumerationOptions();
enumOptions.EnsureLocatable = true;
}
return new PerfFormattedData_Counters_ProcessorInformationCollection(clsObject.GetInstances(enumOptions));
}
开发者ID:OrangeChan,项目名称:cshv3,代码行数:21,代码来源:root.CIMV2.Win32_PerfFormattedData_Counters_ProcessorInformation.cs
示例15: setNewLastPosition
private string setNewLastPosition(ManagementScope scope, EnumerationOptions opt)
{
L.Log(LogType.FILE, LogLevel.INFORM, "setNewLastPosition()| Start: Oldfirst_position:" + first_position);
Int64 lPosition = 0;
SelectQuery query = null;
try
{
string sWhereClause = "";
ValidateMe();
EventLog ev;
if (remote_host == "")
ev = new EventLog(location);
else
ev = new EventLog(location, remote_host);
string sTarih = ManagementDateTimeConverter.ToDmtfDateTime(DateTime.Now.AddHours(-2));
if (EventIDToFilter == "")
{
query = new SelectQuery("select CategoryString,ComputerName, EventIdentifier,Type,Message,RecordNumber,SourceName," +
"TimeGenerated,User from Win32_NtLogEvent where Logfile ='" + location + "' AND TimeGenerated>'" + sTarih + "'");
}
else
{
string[] EventIDArr = EventIDToFilter.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string FilterText = "";
if (EventIDArr.Length < 2)
{
FilterText = "EventIdentifier <> " + EventIDArr[0];
}
else
{
FilterText = "EventIdentifier <> " + EventIDArr[0] + " and ";
for (int f = 0; f < EventIDArr.Length - 2; f++)
{
FilterText += "EventIdentifier <> " + EventIDArr[f] + " and ";
}
FilterText += "EventIdentifier <> " + EventIDArr[EventIDArr.Length - 1];
}
query = new SelectQuery("select CategoryString,ComputerName, EventIdentifier,Type,Message,RecordNumber,SourceName," +
"TimeGenerated,User from Win32_NtLogEvent where " + FilterText + " and Logfile ='" +
location + "' AND TimeGenerated>'" + sTarih + "'");
}
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| query:" + query.QueryString);
List<ManagementObject> moList = new List<ManagementObject>();
opt.Timeout = System.TimeSpan.MaxValue;
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, opt))
{
//Int32 count = ev.Entries.Count;
foreach (ManagementObject mObject in searcher.Get())
{
lPosition = Convert.ToInt64(mObject["RecordNumber"]);
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| :lPosition" + lPosition);
if (fromend == 0)
{
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| fromend==1:lPosition" + lPosition);
lPosition = lPosition - ev.Entries.Count;
}
break;
}
}
}
catch (Exception exp)
{
L.Log(LogType.FILE, LogLevel.ERROR, "setNewLastPosition()| " + exp.Message);
L.Log(LogType.FILE, LogLevel.ERROR, "setNewLastPosition()| query:" + query.QueryString);
return "0";
}
L.Log(LogType.FILE, LogLevel.DEBUG, "setNewLastPosition()| End :lPosition:" + lPosition.ToString());
return lPosition.ToString();
}
开发者ID:salimci,项目名称:Legacy-Remote-Recorder,代码行数:80,代码来源:Class1.cs
示例16: GetInstances
public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions)
{
if ((mgmtScope == null)) {
if ((statMgmtScope == null)) {
mgmtScope = new System.Management.ManagementScope();
mgmtScope.Path.NamespacePath = "root\\virtualization";
}
else {
mgmtScope = statMgmtScope;
}
}
System.Management.ManagementPath pathObj = new System.Management.ManagementPath();
pathObj.ClassName = "Msvm_SyntheticEthernetPortSettingData";
pathObj.NamespacePath = "root\\virtualization";
System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null);
if ((enumOptions == null)) {
enumOptions = new System.Management.EnumerationOptions();
enumOptions.EnsureLocatable = true;
}
return new SyntheticEthernetPortSettingDataCollection(clsObject.GetInstances(enumOptions));
}
开发者ID:OrangeChan,项目名称:cshv3,代码行数:21,代码来源:ROOT.virtualization.Msvm_SyntheticEthernetPortSettingData.cs
示例17: DoAddComputerAction
private void DoAddComputerAction(string computer, string newName, bool isLocalhost, ConnectionOptions options, EnumerationOptions enumOptions, ObjectQuery computerSystemQuery)
{
int returnCode = 0;
bool success = false;
string computerName = isLocalhost ? _shortLocalMachineName : computer;
if (ParameterSetName == DomainParameterSet)
{
string action = StringUtil.Format(ComputerResources.AddComputerActionDomain, DomainName);
if (!ShouldProcess(computerName, action))
{
return;
}
}
else
{
string action = StringUtil.Format(ComputerResources.AddComputerActionWorkgroup, WorkgroupName);
if (!ShouldProcess(computerName, action))
{
return;
}
}
// Check the length of the new name
if (newName != null && newName.Length > ComputerWMIHelper.NetBIOSNameMaxLength)
{
string truncatedName = newName.Substring(0, ComputerWMIHelper.NetBIOSNameMaxLength);
string query = StringUtil.Format(ComputerResources.TruncateNetBIOSName, truncatedName);
string caption = ComputerResources.TruncateNetBIOSNameCaption;
if (!Force && !ShouldContinue(query, caption))
{
return;
}
}
// If LocalCred is given, use the local credential for WMI connection. Otherwise, use
// the current caller's context (Username = null, Password = null)
if (LocalCredential != null)
{
options.SecurePassword = LocalCredential.Password;
options.Username = ComputerWMIHelper.GetLocalAdminUserName(computerName, LocalCredential);
}
// The local machine will always be processed in the very end. If the
// current target computer is the local machine, it's the last one to
// be processed, so we can safely set the Username and Password to be
// null. We cannot use a user credential when connecting to the local
// machine.
if (isLocalhost)
{
options.Username = null;
options.SecurePassword = null;
}
ManagementScope scope = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), options);
try
{
using (var searcher = new ManagementObjectSearcher(scope, computerSystemQuery, enumOptions))
{
foreach (ManagementObject computerSystem in searcher.Get())
{
using (computerSystem)
{
// If we are not using the new computer name, check the length of the target machine name
string hostName = (string)computerSystem["DNSHostName"];
if (newName == null && hostName.Length > ComputerWMIHelper.NetBIOSNameMaxLength)
{
string truncatedName = hostName.Substring(0, ComputerWMIHelper.NetBIOSNameMaxLength);
string query = StringUtil.Format(ComputerResources.TruncateNetBIOSName, truncatedName);
string caption = ComputerResources.TruncateNetBIOSNameCaption;
if (!Force && !ShouldContinue(query, caption))
{
continue;
}
}
if (newName != null && hostName.Equals(newName, StringComparison.OrdinalIgnoreCase))
{
WriteErrorHelper(
ComputerResources.NewNameIsOldName,
"NewNameIsOldName",
newName,
ErrorCategory.InvalidArgument,
false,
computerName, newName);
continue;
}
if (ParameterSetName == DomainParameterSet)
{
if ((bool)computerSystem["PartOfDomain"])
{
string curDomainName = (string)LanguagePrimitives.ConvertTo(computerSystem["Domain"], typeof(string), CultureInfo.InvariantCulture);
string shortDomainName = "";
if (curDomainName.Contains("."))
{
int dotIndex = curDomainName.IndexOf(".", StringComparison.OrdinalIgnoreCase);
shortDomainName = curDomainName.Substring(0, dotIndex);
}
//.........这里部分代码省略.........
开发者ID:dfinke,项目名称:powershell,代码行数:101,代码来源:Computer.cs
示例18: timer1_Tick
private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
timer1.Enabled = false;
try
{
if (!callable.WaitOne(0))
{
L.Log(LogType.FILE, LogLevel.INFORM, "timer1_Tick -- CALLED MULTIPLE TIMES STILL IN USE");
callable.WaitOne();
try
{
throw new Exception("Parse already been processed by another thread while this call has made");
}
finally
{
callable.ReleaseMutex();
}
}
try
{
L.Log(LogType.FILE, LogLevel.DEBUG, "Evenlog Yeni");
L.Log(LogType.FILE, LogLevel.DEBUG, "Enter timer_tick1 method");
L.Log(LogType.FILE, LogLevel.INFORM, "Service Started");
if (!InitSystem())
{
return;
}
if (start_state & fromend == 1)
{
if (!Set_LastPosition())
{
L.Log(LogType.FILE, LogLevel.ERROR,
"Error on setting the last position see log for more details");
}
start_state = false;
}
L.Log(LogType.FILE, LogLevel.DEBUG, "Start Connecting host:");
L.Log(LogType.FILE, LogLevel.DEBUG, "Remote Host :" + remote_host);
if (remote_host == "")
{
L.Log(LogType.FILE, LogLevel.DEBUG, "Localden Okuyor. ");
co = new ConnectionOptions();
co.Timeout = new TimeSpan(0, 10, 0);
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.PacketPrivacy;
scope = new ManagementScope(@"\\localhost\root\cimv2", co);
}
else
{
co = new ConnectionOptions();
co.Username = user;
co.Password = password;
co.Timeout = new TimeSpan(0, 10, 0);
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.PacketPrivacy;
scope = new ManagementScope(@"\\" + remote_host + @"\root\cimv2", co);
}
scope.Options.Impersonation = ImpersonationLevel.Impersonate;
scope.Connect();
L.Log(LogType.FILE, LogLevel.DEBUG, "Connection successfull:");
// default blocksize = 1, larger value may increase network throughput
EnumerationOptions opt = new EnumerationOptions();
opt.BlockSize = 1000;
first_position = last_position;
if (Convert.ToInt64(first_position) <= 0)
{
first_position = setNewLastPosition(scope, opt);
last_position = first_position;
}
L.Log(LogType.FILE, LogLevel.DEBUG, "first_position is :" + first_position);
SelectQuery query = null;
if (EventIDToFilter == "")
{
query =
new SelectQuery(
"select CategoryString,ComputerName, EventIdentifier,Type,Message,RecordNumber,SourceName," +
"TimeGenerated,User from Win32_NtLogEvent where Logfile ='" + location +
"' and RecordNumber >=" + first_position +
" and RecordNumber <" +
Convert.ToString(Convert.ToInt64(first_position) + max_line_towait));
}
else
{
string[] EventIDArr = EventIDToFilter.Split(",".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries);
string FilterText = "";
if (EventIDArr.Length < 2)
{
FilterText = "EventIdentifier <> " + EventIDArr[0];
}
//.........这里部分代码省略.........
开发者ID:salimci,项目名称:Legacy-Remote-Recorder,代码行数:101,代码来源:Class1.cs
示例19: ProcessRecord
/// <summary>
/// ProcessRecord method
/// </summary>
protected override void ProcessRecord()
{
if (NewName != null && ComputerName.Length != 1)
{
WriteErrorHelper(ComputerResources.CannotRenameMultipleComputers, "CannotRenameMultipleComputers",
NewName, ErrorCategory.InvalidArgument, false);
return;
}
// If LocalCred is not provided, we use the current caller's context
ConnectionOptions options = new ConnectionOptions
{
Authentication = AuthenticationLevel.PacketPrivacy,
Impersonation = ImpersonationLevel.Impersonate,
EnablePrivileges = true
};
EnumerationOptions enumOptions = new EnumerationOptions { UseAmendedQualifiers = true, DirectRead = true };
ObjectQuery computerSystemQuery = new ObjectQuery("select * from " + ComputerWMIHelper.WMI_Class_ComputerSystem);
int oldJoinDomainFlags = _joinDomainflags;
if (NewName != null && ParameterSetName == DomainParameterSet)
{
// We rename the computer after it's joined to the target domain, so writing SPN and DNSHostName attributes
// on the computer object should be deferred until the rename operation that follows the join operation
_joinDomainflags |= (int)JoinOptions.DeferSPNSet;
}
try
{
foreach (string computer in ComputerName)
{
string targetComputer = ValidateComputerName(computer, NewName != null);
if (targetComputer == null)
{
continue;
}
bool isLocalhost = targetComputer.Equals("localhost", StringComparison.OrdinalIgnoreCase);
if (isLocalhost)
{
if (!_containsLocalHost)
_containsLocalHost = true;
_newNameForLocalHost = NewName;
continue;
}
DoAddComputerAction(targetComputer, NewName, false, options, enumOptions, computerSystemQuery);
}// end of foreach
}
finally
{
// Reverting the domainflags to previous status if DeferSPNSet is added to the domain flags.
if (NewName != null && ParameterSetName == DomainParameterSet)
{
_joinDomainflags = oldJoinDomainFlags;
}
}
}// end of ProcessRecord
开发者ID:dfinke,项目名称:powershell,代码行数:63,代码来源:Computer.cs
|
请发表评论