/
ManagementOptions.cs
1741 lines (1608 loc) · 74.5 KB
/
ManagementOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
using System.Security;
namespace System.Management
{
/// <summary>
/// <para>Describes the authentication level to be used to connect to WMI. This is used for the COM connection to WMI.</para>
/// </summary>
public enum AuthenticationLevel
{
/// <summary>
/// <para>The default COM authentication level. WMI uses the default Windows Authentication setting.</para>
/// </summary>
Default = 0,
/// <summary>
/// <para> No COM authentication.</para>
/// </summary>
None = 1,
/// <summary>
/// <para> Connect-level COM authentication.</para>
/// </summary>
Connect = 2,
/// <summary>
/// <para> Call-level COM authentication.</para>
/// </summary>
Call = 3,
/// <summary>
/// <para> Packet-level COM authentication.</para>
/// </summary>
Packet = 4,
/// <summary>
/// <para>Packet Integrity-level COM authentication.</para>
/// </summary>
PacketIntegrity = 5,
/// <summary>
/// <para>Packet Privacy-level COM authentication.</para>
/// </summary>
PacketPrivacy = 6,
/// <summary>
/// <para>The default COM authentication level. WMI uses the default Windows Authentication setting.</para>
/// </summary>
Unchanged = -1
}
/// <summary>
/// <para>Describes the impersonation level to be used to connect to WMI.</para>
/// </summary>
public enum ImpersonationLevel
{
/// <summary>
/// <para>Default impersonation.</para>
/// </summary>
Default = 0,
/// <summary>
/// <para> Anonymous COM impersonation level that hides the
/// identity of the caller. Calls to WMI may fail
/// with this impersonation level.</para>
/// </summary>
Anonymous = 1,
/// <summary>
/// <para> Identify-level COM impersonation level that allows objects
/// to query the credentials of the caller. Calls to
/// WMI may fail with this impersonation level.</para>
/// </summary>
Identify = 2,
/// <summary>
/// <para> Impersonate-level COM impersonation level that allows
/// objects to use the credentials of the caller. This is the recommended impersonation level for WMI calls.</para>
/// </summary>
Impersonate = 3,
/// <summary>
/// <para> Delegate-level COM impersonation level that allows objects
/// to permit other objects to use the credentials of the caller. This
/// level, which will work with WMI calls but may constitute an unnecessary
/// security risk, is supported only under Windows 2000.</para>
/// </summary>
Delegate = 4
}
/// <summary>
/// <para>Describes the possible effects of saving an object to WMI when
/// using <see cref='System.Management.ManagementObject.Put()'/>.</para>
/// </summary>
public enum PutType
{
/// <summary>
/// <para> Invalid Type </para>
/// </summary>
None = 0,
/// <summary>
/// <para> Updates an existing object
/// only; does not create a new object.</para>
/// </summary>
UpdateOnly = 1,
/// <summary>
/// <para> Creates an object only;
/// does not update an existing object.</para>
/// </summary>
CreateOnly = 2,
/// <summary>
/// <para> Saves the object, whether
/// updating an existing object or creating a new object.</para>
/// </summary>
UpdateOrCreate = 3
}
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
/// <summary>
/// <para>
/// Provides an abstract base class for all Options objects.</para>
/// <para>Options objects are used to customize different management operations. </para>
/// <para>Use one of the Options classes derived from this class, as
/// indicated by the signature of the operation being performed.</para>
/// </summary>
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
[TypeConverter(typeof(ExpandableObjectConverter))]
public abstract class ManagementOptions : ICloneable
{
/// <summary>
/// <para> Specifies an infinite timeout.</para>
/// </summary>
public static readonly TimeSpan InfiniteTimeout = TimeSpan.MaxValue;
internal int flags;
internal ManagementNamedValueCollection context;
internal TimeSpan timeout;
//Used when any public property on this object is changed, to signal
//to the containing object that it needs to be refreshed.
internal event IdentifierChangedEventHandler IdentifierChanged;
//Fires IdentifierChanged event
internal void FireIdentifierChanged()
{
IdentifierChanged?.Invoke(this, null);
}
//Called when IdentifierChanged() event fires
internal void HandleIdentifierChange(object sender,
IdentifierChangedEventArgs args)
{
//Something inside ManagementOptions changed, we need to fire an event
//to the parent object
FireIdentifierChanged();
}
internal int Flags
{
get { return flags; }
set { flags = value; }
}
/// <summary>
/// <para> Gets or sets a WMI context object. This is a
/// name-value pairs list to be passed through to a WMI provider that supports
/// context information for customized operation.</para>
/// </summary>
/// <value>
/// <para>A name-value pairs list to be passed through to a WMI provider that
/// supports context information for customized operation.</para>
/// </value>
public ManagementNamedValueCollection Context
{
get
{
return context ??= new ManagementNamedValueCollection();
}
set
{
ManagementNamedValueCollection oldContext = context;
if (null != value)
context = (ManagementNamedValueCollection)value.Clone();
else
context = new ManagementNamedValueCollection();
if (null != oldContext)
oldContext.IdentifierChanged -= new IdentifierChangedEventHandler(HandleIdentifierChange);
//register for change events in this object
context.IdentifierChanged += new IdentifierChangedEventHandler(HandleIdentifierChange);
//the context property has changed so act like we fired the event
HandleIdentifierChange(this, null);
}
}
/// <summary>
/// <para>Gets or sets the timeout to apply to the operation.
/// Note that for operations that return collections, this timeout applies to the
/// enumeration through the resulting collection, not the operation itself
/// (the <see cref='System.Management.EnumerationOptions.ReturnImmediately'/>
/// property is used for the latter).</para>
/// This property is used to indicate that the operation should be performed semisynchronously.
/// </summary>
/// <value>
/// <para>The default value for this property is <see cref='System.Management.ManagementOptions.InfiniteTimeout'/>
/// , which means the operation will block.
/// The value specified must be positive.</para>
/// </value>
public TimeSpan Timeout
{
get
{ return timeout; }
set
{
//Timespan allows for negative values, but we want to make sure it's positive here...
if (value.Ticks < 0)
throw new ArgumentOutOfRangeException(nameof(value));
timeout = value;
FireIdentifierChanged();
}
}
internal ManagementOptions() : this(null, InfiniteTimeout) { }
internal ManagementOptions(ManagementNamedValueCollection context, TimeSpan timeout) : this(context, timeout, 0) { }
internal ManagementOptions(ManagementNamedValueCollection context, TimeSpan timeout, int flags)
{
this.flags = flags;
if (context != null)
this.Context = context;
else
this.context = null;
this.Timeout = timeout;
}
internal IWbemContext GetContext()
{
if (context != null)
return context.GetContext();
else
return null;
}
// We do not expose this publicly; instead the flag is set automatically
// when making an async call if we detect that someone has requested to
// listen for status messages.
internal bool SendStatus
{
get
{ return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_SEND_STATUS) != 0) ? true : false); }
set
{
Flags = (value == false) ? (Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_SEND_STATUS) :
(Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_SEND_STATUS);
}
}
/// <summary>
/// <para> Returns a copy of the object.</para>
/// </summary>
/// <returns>
/// <para>The cloned object.</para>
/// </returns>
public abstract object Clone();
}
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
/// <summary>
/// <para>Provides a base class for query and enumeration-related options
/// objects.</para>
/// <para>Use this class to customize enumeration of management
/// objects, traverse management object relationships, or query for
/// management objects.</para>
/// </summary>
/// <example>
/// <code lang='C#'>using System;
/// using System.Management;
///
/// // This example demonstrates how to enumerate all top-level WMI classes
/// // and subclasses in root/cimv2 namespace.
/// class Sample_EnumerationOptions
/// {
/// public static int Main(string[] args) {
/// ManagementClass newClass = new ManagementClass();
/// EnumerationOptions options = new EnumerationOptions();
/// options.EnumerateDeep = false;
/// foreach (ManagementObject o in newClass.GetSubclasses(options)) {
/// Console.WriteLine(o["__Class"]);
/// }
/// return 0;
/// }
/// }
/// </code>
/// <code lang='VB'>Imports System
/// Imports System.Management
///
/// ' This example demonstrates how to enumerate all top-level WMI classes
/// ' and subclasses in root/cimv2 namespace.
/// Class Sample_EnumerationOptions
/// Overloads Public Shared Function Main(args() As String) As Integer
/// Dim newClass As New ManagementClass()
/// Dim options As New EnumerationOptions()
/// options.EnumerateDeep = False
/// Dim o As ManagementObject
/// For Each o In newClass.GetSubclasses(options)
/// Console.WriteLine(o("__Class"))
/// Next o
/// Return 0
/// End Function
/// End Class
/// </code>
/// </example>
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
public class EnumerationOptions : ManagementOptions
{
private int blockSize;
/// <summary>
/// <para>Gets or sets a value indicating whether the invoked operation should be
/// performed in a synchronous or semisynchronous fashion. If this property is set
/// to <see langword='true'/>, the enumeration is invoked and the call returns immediately. The actual
/// retrieval of the results will occur when the resulting collection is walked.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if the invoked operation should
/// be performed in a synchronous or semisynchronous fashion; otherwise,
/// <see langword='false'/>. The default value is <see langword='true'/>.</para>
/// </value>
public bool ReturnImmediately
{
get { return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_RETURN_IMMEDIATELY) != 0) ? true : false); }
set
{
Flags = (value == false) ? (Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_RETURN_IMMEDIATELY) :
(Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_RETURN_IMMEDIATELY);
}
}
/// <summary>
/// <para> Gets or sets the block size
/// for block operations. When enumerating through a collection, WMI will return results in
/// groups of the specified size.</para>
/// </summary>
/// <value>
/// <para>The default value is 1.</para>
/// </value>
public int BlockSize
{
get { return blockSize; }
set
{
//Unfortunately BlockSize was defined as int, but valid values are only > 0
if (value <= 0)
throw new ArgumentOutOfRangeException(nameof(value));
blockSize = value;
}
}
/// <summary>
/// <para>Gets or sets a value indicating whether the collection is assumed to be
/// rewindable. If <see langword='true'/>, the objects in the
/// collection will be kept available for multiple enumerations. If
/// <see langword='false'/>, the collection
/// can only be enumerated one time.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if the collection is assumed to
/// be rewindable; otherwise, <see langword='false'/>. The default value is
/// <see langword='true'/>.</para>
/// </value>
/// <remarks>
/// <para>A rewindable collection is more costly in memory
/// consumption as all the objects need to be kept available at the same time.
/// In a collection defined as non-rewindable, the objects are discarded after being returned
/// in the enumeration.</para>
/// </remarks>
public bool Rewindable
{
get { return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_FORWARD_ONLY) != 0) ? false : true); }
set
{
Flags = value ? (Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_FORWARD_ONLY) :
(Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_FORWARD_ONLY);
}
}
/// <summary>
/// <para> Gets or sets a value indicating whether the objects returned from
/// WMI should contain amended information. Typically, amended information is localizable
/// information attached to the WMI object, such as object and property
/// descriptions.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if the objects returned from WMI
/// should contain amended information; otherwise, <see langword='false'/>. The
/// default value is <see langword='false'/>.</para>
/// </value>
/// <remarks>
/// <para>If descriptions and other amended information are not of
/// interest, setting this property to <see langword='false'/>
/// is more
/// efficient.</para>
/// </remarks>
public bool UseAmendedQualifiers
{
get { return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS) != 0) ? true : false); }
set
{
Flags = value ? (Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS) :
(Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS);
}
}
/// <summary>
/// <para>Gets or sets a value indicating whether to the objects returned should have
/// locatable information in them. This ensures that the system properties, such as
/// <see langword='__PATH'/>, <see langword='__RELPATH'/>, and
/// <see langword='__SERVER'/>, are non-NULL. This flag can only be used in queries,
/// and is ignored in enumerations.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if WMI
/// should ensure all returned objects have valid paths; otherwise,
/// <see langword='false'/>. The default value is <see langword='false'/>.</para>
/// </value>
public bool EnsureLocatable
{
get
{ return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_ENSURE_LOCATABLE) != 0) ? true : false); }
set
{
Flags = value ? (Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_ENSURE_LOCATABLE) :
(Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_ENSURE_LOCATABLE);
}
}
/// <summary>
/// <para>Gets or sets a value indicating whether the query should return a
/// prototype of the result set instead of the actual results. This flag is used for
/// prototyping.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if the
/// query should return a prototype of the result set instead of the actual results;
/// otherwise, <see langword='false'/>. The default value is
/// <see langword='false'/>.</para>
/// </value>
public bool PrototypeOnly
{
get
{ return (((Flags & (int)tag_WBEM_QUERY_FLAG_TYPE.WBEM_FLAG_PROTOTYPE) != 0) ? true : false); }
set
{
Flags = value ? (Flags | (int)tag_WBEM_QUERY_FLAG_TYPE.WBEM_FLAG_PROTOTYPE) :
(Flags & (int)~tag_WBEM_QUERY_FLAG_TYPE.WBEM_FLAG_PROTOTYPE);
}
}
/// <summary>
/// <para> Gets or sets a value indicating whether direct access to the WMI provider is requested for the specified class,
/// without any regard to its base class or derived classes.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if only
/// objects of the specified class should be received, without regard to derivation
/// or inheritance; otherwise, <see langword='false'/>. The default value is
/// <see langword='false'/>. </para>
/// </value>
public bool DirectRead
{
get
{ return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_DIRECT_READ) != 0) ? true : false); }
set
{
Flags = value ? (Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_DIRECT_READ) :
(Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_DIRECT_READ);
}
}
/// <summary>
/// <para> Gets or sets a value indicating whether recursive enumeration is requested
/// into all classes derived from the specified base class. If
/// <see langword='false'/>, only immediate derived
/// class members are returned.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if recursive enumeration is requested
/// into all classes derived from the specified base class; otherwise,
/// <see langword='false'/>. The default value is <see langword='false'/>.</para>
/// </value>
public bool EnumerateDeep
{
get
{ return (((Flags & (int)tag_WBEM_QUERY_FLAG_TYPE.WBEM_FLAG_SHALLOW) != 0) ? false : true); }
set
{
Flags = (value == false) ? (Flags | (int)tag_WBEM_QUERY_FLAG_TYPE.WBEM_FLAG_SHALLOW) :
(Flags & (int)~tag_WBEM_QUERY_FLAG_TYPE.WBEM_FLAG_SHALLOW);
}
}
//default constructor
/// <overload>
/// Initializes a new instance
/// of the <see cref='System.Management.EnumerationOptions'/> class.
/// </overload>
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.EnumerationOptions'/>
/// class with default values (see the individual property descriptions
/// for what the default values are). This is the default constructor. </para>
/// </summary>
public EnumerationOptions() : this(null, InfiniteTimeout, 1, true, true, false, false, false, false, false) { }
//Constructor that specifies flags as individual values - we need to set the flags accordingly !
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.EnumerationOptions'/> class to be used for queries or enumerations,
/// allowing the user to specify values for the different options.</para>
/// </summary>
/// <param name='context'>The options context object containing provider-specific information that can be passed through to the provider.</param>
/// <param name=' timeout'>The timeout value for enumerating through the results.</param>
/// <param name=' blockSize'>The number of items to retrieve at one time from WMI.</param>
/// <param name=' rewindable'><see langword='true'/> to specify whether the result set is rewindable (=allows multiple traversal or one-time); otherwise, <see langword='false'/>.</param>
/// <param name=' returnImmediatley'><see langword='true'/> to specify whether the operation should return immediately (semi-sync) or block until all results are available; otherwise, <see langword='false'/> .</param>
/// <param name=' useAmendedQualifiers'><see langword='true'/> to specify whether the returned objects should contain amended (locale-aware) qualifiers; otherwise, <see langword='false'/> .</param>
/// <param name=' ensureLocatable'><see langword='true'/> to specify to WMI that it should ensure all returned objects have valid paths; otherwise, <see langword='false'/> .</param>
/// <param name=' prototypeOnly'><see langword='true'/> to return a prototype of the result set instead of the actual results; otherwise, <see langword='false'/> .</param>
/// <param name=' directRead'><see langword='true'/> to retrieve objects of only the specified class only or from derived classes as well; otherwise, <see langword='false'/> .</param>
/// <param name=' enumerateDeep'><see langword='true'/> to specify recursive enumeration in subclasses; otherwise, <see langword='false'/> .</param>
public EnumerationOptions(
ManagementNamedValueCollection context,
TimeSpan timeout,
int blockSize,
bool rewindable,
bool returnImmediatley,
bool useAmendedQualifiers,
bool ensureLocatable,
bool prototypeOnly,
bool directRead,
bool enumerateDeep) : base(context, timeout)
{
BlockSize = blockSize;
Rewindable = rewindable;
ReturnImmediately = returnImmediatley;
UseAmendedQualifiers = useAmendedQualifiers;
EnsureLocatable = ensureLocatable;
PrototypeOnly = prototypeOnly;
DirectRead = directRead;
EnumerateDeep = enumerateDeep;
}
/// <summary>
/// <para> Returns a copy of the object.</para>
/// </summary>
/// <returns>
/// <para>The cloned object.</para>
/// </returns>
public override object Clone()
{
ManagementNamedValueCollection newContext = null;
if (null != Context)
newContext = (ManagementNamedValueCollection)Context.Clone();
return new EnumerationOptions(newContext, Timeout, blockSize, Rewindable,
ReturnImmediately, UseAmendedQualifiers, EnsureLocatable, PrototypeOnly, DirectRead, EnumerateDeep);
}
}//EnumerationOptions
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
/// <summary>
/// <para> Specifies options for management event watching.</para>
/// <para>Use this class to customize subscriptions for watching management events. </para>
/// </summary>
/// <example>
/// <code lang='C#'>using System;
/// using System.Management;
///
/// // This example demonstrates how to listen to an event using ManagementEventWatcher object.
/// class Sample_EventWatcherOptions
/// {
/// public static int Main(string[] args) {
/// ManagementClass newClass = new ManagementClass();
/// newClass["__CLASS"] = "TestDeletionClass";
/// newClass.Put();
///
/// EventWatcherOptions options = new EventWatcherOptions();
/// ManagementEventWatcher watcher = new ManagementEventWatcher(null,
/// new WqlEventQuery("__classdeletionevent"),
/// options);
/// MyHandler handler = new MyHandler();
/// watcher.EventArrived += new EventArrivedEventHandler(handler.Arrived);
/// watcher.Start();
///
/// // Delete class to trigger event
/// newClass.Delete();
///
/// //For the purpose of this example, we will wait
/// // two seconds before main thread terminates.
/// System.Threading.Thread.Sleep(2000);
///
/// watcher.Stop();
///
/// return 0;
/// }
///
/// public class MyHandler
/// {
/// public void Arrived(object sender, EventArrivedEventArgs e) {
/// Console.WriteLine("Class Deleted= " +
/// ((ManagementBaseObject)e.NewEvent["TargetClass"])["__CLASS"]);
/// }
/// }
/// }
/// </code>
/// <code lang='VB'>Imports System
/// Imports System.Management
///
/// ' This example demonstrates how to listen to an event using the ManagementEventWatcher object.
/// Class Sample_EventWatcherOptions
/// Public Shared Sub Main()
/// Dim newClass As New ManagementClass()
/// newClass("__CLASS") = "TestDeletionClass"
/// newClass.Put()
///
/// Dim options As _
/// New EventWatcherOptions()
/// Dim watcher As New ManagementEventWatcher( _
/// Nothing, _
/// New WqlEventQuery("__classdeletionevent"), _
/// options)
/// Dim handler As New MyHandler()
/// AddHandler watcher.EventArrived, AddressOf handler.Arrived
/// watcher.Start()
///
/// ' Delete class to trigger event
/// newClass.Delete()
///
/// ' For the purpose of this example, we will wait
/// ' two seconds before main thread terminates.
/// System.Threading.Thread.Sleep(2000)
/// watcher.Stop()
/// End Sub
///
/// Public Class MyHandler
/// Public Sub Arrived(sender As Object, e As EventArrivedEventArgs)
/// Console.WriteLine("Class Deleted = " & _
/// CType(e.NewEvent("TargetClass"), ManagementBaseObject)("__CLASS"))
/// End Sub
/// End Class
/// End Class
/// </code>
/// </example>
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
public class EventWatcherOptions : ManagementOptions
{
private int blockSize = 1;
/// <summary>
/// <para>Gets or sets the block size for block operations. When waiting for events, this
/// value specifies how many events to wait for before returning.</para>
/// </summary>
/// <value>
/// <para>The default value is 1.</para>
/// </value>
public int BlockSize
{
get { return blockSize; }
set
{
blockSize = value;
FireIdentifierChanged();
}
}
/// <overload>
/// <para>Initializes a new instance of the <see cref='System.Management.EventWatcherOptions'/> class. </para>
/// </overload>
/// <summary>
/// <para> Initializes a new instance of the <see cref='System.Management.EventWatcherOptions'/> class for event watching, using default values.
/// This is the default constructor.</para>
/// </summary>
public EventWatcherOptions()
: this(null, InfiniteTimeout, 1) { }
/// <summary>
/// <para> Initializes a new instance of the <see cref='System.Management.EventWatcherOptions'/> class with the given
/// values.</para>
/// </summary>
/// <param name='context'>The options context object containing provider-specific information to be passed through to the provider. </param>
/// <param name=' timeout'>The timeout to wait for the next events.</param>
/// <param name=' blockSize'>The number of events to wait for in each block.</param>
public EventWatcherOptions(ManagementNamedValueCollection context, TimeSpan timeout, int blockSize)
: base(context, timeout)
{
Flags = (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_RETURN_IMMEDIATELY | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_FORWARD_ONLY;
BlockSize = blockSize;
}
/// <summary>
/// <para> Returns a copy of the object.</para>
/// </summary>
/// <returns>
/// The cloned object.
/// </returns>
public override object Clone()
{
ManagementNamedValueCollection newContext = null;
if (null != Context)
newContext = (ManagementNamedValueCollection)Context.Clone();
return new EventWatcherOptions(newContext, Timeout, blockSize);
}
}//EventWatcherOptions
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
/// <summary>
/// <para> Specifies options for getting a management object.</para>
/// Use this class to customize retrieval of a management object.
/// </summary>
/// <example>
/// <code lang='C#'>using System;
/// using System.Management;
///
/// // This example demonstrates how to set a timeout value and list
/// // all amended qualifiers in a ManagementClass object.
/// class Sample_ObjectGetOptions
/// {
/// public static int Main(string[] args) {
/// // Request amended qualifiers
/// ObjectGetOptions options =
/// new ObjectGetOptions(null, new TimeSpan(0,0,0,5), true);
/// ManagementClass diskClass =
/// new ManagementClass("root/cimv2", "Win32_Process", options);
/// foreach (QualifierData qualifier in diskClass.Qualifiers) {
/// Console.WriteLine(qualifier.Name + ":" + qualifier.Value);
/// }
/// return 0;
/// }
/// }
/// </code>
/// <code lang='VB'>Imports System
/// Imports System.Management
///
/// ' This example demonstrates how to set a timeout value and list
/// ' all amended qualifiers in a ManagementClass object.
/// Class Sample_ObjectGetOptions
/// Overloads Public Shared Function Main(args() As String) As Integer
/// ' Request amended qualifiers
/// Dim options As _
/// New ObjectGetOptions(Nothing, New TimeSpan(0, 0, 0, 5), True)
/// Dim diskClass As New ManagementClass( _
/// "root/cimv2", _
/// "Win32_Process", _
/// options)
/// Dim qualifier As QualifierData
/// For Each qualifier In diskClass.Qualifiers
/// Console.WriteLine(qualifier.Name & ":" & qualifier.Value)
/// Next qualifier
/// Return 0
/// End Function
/// End Class
/// </code>
/// </example>
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
public class ObjectGetOptions : ManagementOptions
{
internal static ObjectGetOptions _Clone(ObjectGetOptions options)
{
return ObjectGetOptions._Clone(options, null);
}
internal static ObjectGetOptions _Clone(ObjectGetOptions options, IdentifierChangedEventHandler handler)
{
ObjectGetOptions optionsTmp;
if (options != null)
optionsTmp = new ObjectGetOptions(options.context, options.timeout, options.UseAmendedQualifiers);
else
optionsTmp = new ObjectGetOptions();
// Wire up change handler chain. Use supplied handler, if specified;
// otherwise, default to that of the path argument.
if (handler != null)
optionsTmp.IdentifierChanged += handler;
else if (options != null)
optionsTmp.IdentifierChanged += new IdentifierChangedEventHandler(options.HandleIdentifierChange);
return optionsTmp;
}
/// <summary>
/// <para> Gets or sets a value indicating whether the objects returned from WMI should
/// contain amended information. Typically, amended information is localizable information
/// attached to the WMI object, such as object and property descriptions.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if the objects returned from WMI
/// should contain amended information; otherwise, <see langword='false'/>. The
/// default value is <see langword='false'/>.</para>
/// </value>
public bool UseAmendedQualifiers
{
get { return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS) != 0) ? true : false); }
set
{
Flags = value ? (Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS) :
(Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS);
FireIdentifierChanged();
}
}
/// <overload>
/// <para>Initializes a new instance of the <see cref='System.Management.ObjectGetOptions'/> class.</para>
/// </overload>
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.ObjectGetOptions'/> class for getting a WMI object, using
/// default values. This is the default constructor.</para>
/// </summary>
public ObjectGetOptions() : this(null, InfiniteTimeout, false) { }
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.ObjectGetOptions'/> class for getting a WMI object, using the
/// specified provider-specific context.</para>
/// </summary>
/// <param name='context'>A provider-specific, named-value pairs context object to be passed through to the provider.</param>
public ObjectGetOptions(ManagementNamedValueCollection context) : this(context, InfiniteTimeout, false) { }
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.ObjectGetOptions'/> class for getting a WMI object,
/// using the given options values.</para>
/// </summary>
/// <param name='context'>A provider-specific, named-value pairs context object to be passed through to the provider.</param>
/// <param name=' timeout'>The length of time to let the operation perform before it times out. The default is <see cref='System.Management.ManagementOptions.InfiniteTimeout'/> .</param>
/// <param name=' useAmendedQualifiers'><see langword='true'/> if the returned objects should contain amended (locale-aware) qualifiers; otherwise, <see langword='false'/>. </param>
public ObjectGetOptions(ManagementNamedValueCollection context, TimeSpan timeout, bool useAmendedQualifiers) : base(context, timeout)
{
UseAmendedQualifiers = useAmendedQualifiers;
}
/// <summary>
/// <para> Returns a copy of the object.</para>
/// </summary>
/// <returns>
/// <para>The cloned object.</para>
/// </returns>
public override object Clone()
{
ManagementNamedValueCollection newContext = null;
if (null != Context)
newContext = (ManagementNamedValueCollection)Context.Clone();
return new ObjectGetOptions(newContext, Timeout, UseAmendedQualifiers);
}
}
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
/// <summary>
/// <para> Specifies options for committing management
/// object changes.</para>
/// <para>Use this class to customize how values are saved to a management object.</para>
/// </summary>
/// <example>
/// <code lang='C#'>using System;
/// using System.Management;
///
/// // This example demonstrates how to specify a PutOptions using
/// // PutOptions object when saving a ManagementClass object to
/// // the WMI respository.
/// class Sample_PutOptions
/// {
/// public static int Main(string[] args) {
/// ManagementClass newClass = new ManagementClass("root/default",
/// String.Empty,
/// null);
/// newClass["__Class"] = "class999xc";
///
/// PutOptions options = new PutOptions();
/// options.Type = PutType.UpdateOnly;
///
/// try
/// {
/// newClass.Put(options); //will fail if the class doesn't already exist
/// }
/// catch (ManagementException e)
/// {
/// Console.WriteLine("Couldn't update class: " + e.ErrorCode);
/// }
/// return 0;
/// }
/// }
/// </code>
/// <code lang='VB'>Imports System
/// Imports System.Management
///
/// ' This example demonstrates how to specify a PutOptions using
/// ' PutOptions object when saving a ManagementClass object to
/// ' WMI respository.
/// Class Sample_PutOptions
/// Overloads Public Shared Function Main(args() As String) As Integer
/// Dim newClass As New ManagementClass( _
/// "root/default", _
/// String.Empty, _
/// Nothing)
/// newClass("__Class") = "class999xc"
///
/// Dim options As New PutOptions()
/// options.Type = PutType.UpdateOnly 'will fail if the class doesn't already exist
///
/// Try
/// newClass.Put(options)
/// Catch e As ManagementException
/// Console.WriteLine("Couldn't update class: " & e.ErrorCode)
/// End Try
/// Return 0
/// End Function
/// End Class
/// </code>
/// </example>
//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
public class PutOptions : ManagementOptions
{
/// <summary>
/// <para> Gets or sets a value indicating whether the objects returned from WMI should
/// contain amended information. Typically, amended information is localizable information
/// attached to the WMI object, such as object and property descriptions.</para>
/// </summary>
/// <value>
/// <para><see langword='true'/> if the objects returned from WMI
/// should contain amended information; otherwise, <see langword='false'/>. The
/// default value is <see langword='false'/>.</para>
/// </value>
public bool UseAmendedQualifiers
{
get { return (((Flags & (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS) != 0) ? true : false); }
set
{
Flags = value ? (Flags | (int)tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS) :
(Flags & (int)~tag_WBEM_GENERIC_FLAG_TYPE.WBEM_FLAG_USE_AMENDED_QUALIFIERS);
}
}
/// <summary>
/// <para>Gets or sets the type of commit to be performed for the object.</para>
/// </summary>
/// <value>
/// <para>The default value is <see cref='System.Management.PutType.UpdateOrCreate'/>.</para>
/// </value>
public PutType Type
{
get
{
return (((Flags & (int)tag_WBEM_CHANGE_FLAG_TYPE.WBEM_FLAG_UPDATE_ONLY) != 0) ? PutType.UpdateOnly :
((Flags & (int)tag_WBEM_CHANGE_FLAG_TYPE.WBEM_FLAG_CREATE_ONLY) != 0) ? PutType.CreateOnly :
PutType.UpdateOrCreate);
}
set
{
Flags |= value switch
{
PutType.UpdateOnly => (int)tag_WBEM_CHANGE_FLAG_TYPE.WBEM_FLAG_UPDATE_ONLY,
PutType.CreateOnly => (int)tag_WBEM_CHANGE_FLAG_TYPE.WBEM_FLAG_CREATE_ONLY,
PutType.UpdateOrCreate => (int)tag_WBEM_CHANGE_FLAG_TYPE.WBEM_FLAG_CREATE_OR_UPDATE,
_ => throw new ArgumentException(null, nameof(Type)),
};
}
}
/// <overload>
/// <para> Initializes a new instance of the <see cref='System.Management.PutOptions'/> class.</para>
/// </overload>
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.PutOptions'/> class for put operations, using default values.
/// This is the default constructor.</para>
/// </summary>
public PutOptions() : this(null, InfiniteTimeout, false, PutType.UpdateOrCreate) { }
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.PutOptions'/> class for committing a WMI object, using the
/// specified provider-specific context.</para>
/// </summary>
/// <param name='context'>A provider-specific, named-value pairs context object to be passed through to the provider.</param>
public PutOptions(ManagementNamedValueCollection context) : this(context, InfiniteTimeout, false, PutType.UpdateOrCreate) { }
/// <summary>
/// <para>Initializes a new instance of the <see cref='System.Management.PutOptions'/> class for committing a WMI object, using
/// the specified option values.</para>
/// </summary>