| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * Copyright 2008-2010 The Eraser Project |
|---|
| 4 | * Original Author: Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 5 | * Modified By: |
|---|
| 6 | * |
|---|
| 7 | * This file is part of Eraser. |
|---|
| 8 | * |
|---|
| 9 | * Eraser is free software: you can redistribute it and/or modify it under the |
|---|
| 10 | * terms of the GNU General Public License as published by the Free Software |
|---|
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
|---|
| 12 | * version. |
|---|
| 13 | * |
|---|
| 14 | * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|---|
| 16 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * A copy of the GNU General Public License can be found at |
|---|
| 19 | * <http://www.gnu.org/licenses/>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | /* |
|---|
| 23 | * This is an AUTOMATICALLY GENERATED class. To re-generate the class, run this command: |
|---|
| 24 | * mgmtclassgen SystemRestore /P SystemRestoreApi.cs /N root\default |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | namespace Eraser.Util |
|---|
| 28 | { |
|---|
| 29 | using System; |
|---|
| 30 | using System.ComponentModel; |
|---|
| 31 | using System.Management; |
|---|
| 32 | using System.Collections; |
|---|
| 33 | using System.Globalization; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | // Functions ShouldSerialize<PropertyName> are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use Is<PropertyName>Null function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. |
|---|
| 37 | // Functions Is<PropertyName>Null() are used to check if a property is NULL. |
|---|
| 38 | // Functions Reset<PropertyName> are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. |
|---|
| 39 | // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. |
|---|
| 40 | // An Early Bound class generated for the WMI class.SystemRestore |
|---|
| 41 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("mgmtclassgen", "3.5.30729.1")] |
|---|
| 42 | public class SystemRestore : System.ComponentModel.Component { |
|---|
| 43 | |
|---|
| 44 | // Private property to hold the WMI namespace in which the class resides. |
|---|
| 45 | private static string CreatedWmiNamespace = "root\\default"; |
|---|
| 46 | |
|---|
| 47 | // Private property to hold the name of WMI class which created this class. |
|---|
| 48 | private static string CreatedClassName = "SystemRestore"; |
|---|
| 49 | |
|---|
| 50 | // Private member variable to hold the ManagementScope which is used by the various methods. |
|---|
| 51 | private static System.Management.ManagementScope statMgmtScope = null; |
|---|
| 52 | |
|---|
| 53 | private ManagementSystemProperties PrivateSystemProperties; |
|---|
| 54 | |
|---|
| 55 | // Underlying lateBound WMI object. |
|---|
| 56 | private System.Management.ManagementObject PrivateLateBoundObject; |
|---|
| 57 | |
|---|
| 58 | // Member variable to store the 'automatic commit' behavior for the class. |
|---|
| 59 | private bool AutoCommitProp; |
|---|
| 60 | |
|---|
| 61 | // Private variable to hold the embedded property representing the instance. |
|---|
| 62 | private System.Management.ManagementBaseObject embeddedObj; |
|---|
| 63 | |
|---|
| 64 | // The current WMI object used |
|---|
| 65 | private System.Management.ManagementBaseObject curObj; |
|---|
| 66 | |
|---|
| 67 | // Flag to indicate if the instance is an embedded object. |
|---|
| 68 | private bool isEmbedded; |
|---|
| 69 | |
|---|
| 70 | // Below are different overloads of constructors to initialize an instance of the class with a WMI object. |
|---|
| 71 | public SystemRestore() { |
|---|
| 72 | this.InitializeObject(null, null, null); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | public SystemRestore(uint keySequenceNumber) { |
|---|
| 76 | this.InitializeObject(null, new System.Management.ManagementPath(SystemRestore.ConstructPath(keySequenceNumber)), null); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | public SystemRestore(System.Management.ManagementScope mgmtScope, uint keySequenceNumber) { |
|---|
| 80 | this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(SystemRestore.ConstructPath(keySequenceNumber)), null); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | public SystemRestore(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { |
|---|
| 84 | this.InitializeObject(null, path, getOptions); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | public SystemRestore(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { |
|---|
| 88 | this.InitializeObject(mgmtScope, path, null); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | public SystemRestore(System.Management.ManagementPath path) { |
|---|
| 92 | this.InitializeObject(null, path, null); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | public SystemRestore(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { |
|---|
| 96 | this.InitializeObject(mgmtScope, path, getOptions); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | public SystemRestore(System.Management.ManagementObject theObject) { |
|---|
| 100 | Initialize(); |
|---|
| 101 | if ((CheckIfProperClass(theObject) == true)) { |
|---|
| 102 | PrivateLateBoundObject = theObject; |
|---|
| 103 | PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); |
|---|
| 104 | curObj = PrivateLateBoundObject; |
|---|
| 105 | } |
|---|
| 106 | else { |
|---|
| 107 | throw new System.ArgumentException("Class name does not match."); |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | public SystemRestore(System.Management.ManagementBaseObject theObject) { |
|---|
| 112 | Initialize(); |
|---|
| 113 | if ((CheckIfProperClass(theObject) == true)) { |
|---|
| 114 | embeddedObj = theObject; |
|---|
| 115 | PrivateSystemProperties = new ManagementSystemProperties(theObject); |
|---|
| 116 | curObj = embeddedObj; |
|---|
| 117 | isEmbedded = true; |
|---|
| 118 | } |
|---|
| 119 | else { |
|---|
| 120 | throw new System.ArgumentException("Class name does not match."); |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | // Property returns the namespace of the WMI class. |
|---|
| 125 | [Browsable(true)] |
|---|
| 126 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 127 | public string OriginatingNamespace { |
|---|
| 128 | get { |
|---|
| 129 | return "root\\default"; |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | [Browsable(true)] |
|---|
| 134 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 135 | public string ManagementClassName { |
|---|
| 136 | get { |
|---|
| 137 | string strRet = CreatedClassName; |
|---|
| 138 | if ((curObj != null)) { |
|---|
| 139 | if ((curObj.ClassPath != null)) { |
|---|
| 140 | strRet = ((string)(curObj["__CLASS"])); |
|---|
| 141 | if (((strRet == null) |
|---|
| 142 | || (strRet == string.Empty))) { |
|---|
| 143 | strRet = CreatedClassName; |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | return strRet; |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | // Property pointing to an embedded object to get System properties of the WMI object. |
|---|
| 152 | [Browsable(true)] |
|---|
| 153 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 154 | public ManagementSystemProperties SystemProperties { |
|---|
| 155 | get { |
|---|
| 156 | return PrivateSystemProperties; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | // Property returning the underlying lateBound object. |
|---|
| 161 | [Browsable(false)] |
|---|
| 162 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 163 | public System.Management.ManagementBaseObject LateBoundObject { |
|---|
| 164 | get { |
|---|
| 165 | return curObj; |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | // ManagementScope of the object. |
|---|
| 170 | [Browsable(true)] |
|---|
| 171 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 172 | public System.Management.ManagementScope Scope { |
|---|
| 173 | get { |
|---|
| 174 | if ((isEmbedded == false)) { |
|---|
| 175 | return PrivateLateBoundObject.Scope; |
|---|
| 176 | } |
|---|
| 177 | else { |
|---|
| 178 | return null; |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | set { |
|---|
| 182 | if ((isEmbedded == false)) { |
|---|
| 183 | PrivateLateBoundObject.Scope = value; |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). |
|---|
| 189 | [Browsable(false)] |
|---|
| 190 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 191 | public bool AutoCommit { |
|---|
| 192 | get { |
|---|
| 193 | return AutoCommitProp; |
|---|
| 194 | } |
|---|
| 195 | set { |
|---|
| 196 | AutoCommitProp = value; |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | // The ManagementPath of the underlying WMI object. |
|---|
| 201 | [Browsable(true)] |
|---|
| 202 | public System.Management.ManagementPath Path { |
|---|
| 203 | get { |
|---|
| 204 | if ((isEmbedded == false)) { |
|---|
| 205 | return PrivateLateBoundObject.Path; |
|---|
| 206 | } |
|---|
| 207 | else { |
|---|
| 208 | return null; |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | set { |
|---|
| 212 | if ((isEmbedded == false)) { |
|---|
| 213 | if ((CheckIfProperClass(null, value, null) != true)) { |
|---|
| 214 | throw new System.ArgumentException("Class name does not match."); |
|---|
| 215 | } |
|---|
| 216 | PrivateLateBoundObject.Path = value; |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | // Public static scope property which is used by the various methods. |
|---|
| 222 | [Browsable(true)] |
|---|
| 223 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 224 | public static System.Management.ManagementScope StaticScope { |
|---|
| 225 | get { |
|---|
| 226 | return statMgmtScope; |
|---|
| 227 | } |
|---|
| 228 | set { |
|---|
| 229 | statMgmtScope = value; |
|---|
| 230 | } |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | [Browsable(true)] |
|---|
| 234 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 235 | public string CreationTime { |
|---|
| 236 | get { |
|---|
| 237 | return ((string)(curObj["CreationTime"])); |
|---|
| 238 | } |
|---|
| 239 | set { |
|---|
| 240 | curObj["CreationTime"] = value; |
|---|
| 241 | if (((isEmbedded == false) |
|---|
| 242 | && (AutoCommitProp == true))) { |
|---|
| 243 | PrivateLateBoundObject.Put(); |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | [Browsable(true)] |
|---|
| 249 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 250 | public string Description { |
|---|
| 251 | get { |
|---|
| 252 | return ((string)(curObj["Description"])); |
|---|
| 253 | } |
|---|
| 254 | set { |
|---|
| 255 | curObj["Description"] = value; |
|---|
| 256 | if (((isEmbedded == false) |
|---|
| 257 | && (AutoCommitProp == true))) { |
|---|
| 258 | PrivateLateBoundObject.Put(); |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | [Browsable(false)] |
|---|
| 264 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 265 | public bool IsEventTypeNull { |
|---|
| 266 | get { |
|---|
| 267 | if ((curObj["EventType"] == null)) { |
|---|
| 268 | return true; |
|---|
| 269 | } |
|---|
| 270 | else { |
|---|
| 271 | return false; |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | [Browsable(true)] |
|---|
| 277 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 278 | [TypeConverter(typeof(WMIValueTypeConverter))] |
|---|
| 279 | public uint EventType { |
|---|
| 280 | get { |
|---|
| 281 | if ((curObj["EventType"] == null)) { |
|---|
| 282 | return System.Convert.ToUInt32(0); |
|---|
| 283 | } |
|---|
| 284 | return ((uint)(curObj["EventType"])); |
|---|
| 285 | } |
|---|
| 286 | set { |
|---|
| 287 | curObj["EventType"] = value; |
|---|
| 288 | if (((isEmbedded == false) |
|---|
| 289 | && (AutoCommitProp == true))) { |
|---|
| 290 | PrivateLateBoundObject.Put(); |
|---|
| 291 | } |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | [Browsable(false)] |
|---|
| 296 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 297 | public bool IsRestorePointTypeNull { |
|---|
| 298 | get { |
|---|
| 299 | if ((curObj["RestorePointType"] == null)) { |
|---|
| 300 | return true; |
|---|
| 301 | } |
|---|
| 302 | else { |
|---|
| 303 | return false; |
|---|
| 304 | } |
|---|
| 305 | } |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | [Browsable(true)] |
|---|
| 309 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 310 | [TypeConverter(typeof(WMIValueTypeConverter))] |
|---|
| 311 | public uint RestorePointType { |
|---|
| 312 | get { |
|---|
| 313 | if ((curObj["RestorePointType"] == null)) { |
|---|
| 314 | return System.Convert.ToUInt32(0); |
|---|
| 315 | } |
|---|
| 316 | return ((uint)(curObj["RestorePointType"])); |
|---|
| 317 | } |
|---|
| 318 | set { |
|---|
| 319 | curObj["RestorePointType"] = value; |
|---|
| 320 | if (((isEmbedded == false) |
|---|
| 321 | && (AutoCommitProp == true))) { |
|---|
| 322 | PrivateLateBoundObject.Put(); |
|---|
| 323 | } |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | [Browsable(false)] |
|---|
| 328 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 329 | public bool IsSequenceNumberNull { |
|---|
| 330 | get { |
|---|
| 331 | if ((curObj["SequenceNumber"] == null)) { |
|---|
| 332 | return true; |
|---|
| 333 | } |
|---|
| 334 | else { |
|---|
| 335 | return false; |
|---|
| 336 | } |
|---|
| 337 | } |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | [Browsable(true)] |
|---|
| 341 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
|---|
| 342 | [TypeConverter(typeof(WMIValueTypeConverter))] |
|---|
| 343 | public uint SequenceNumber { |
|---|
| 344 | get { |
|---|
| 345 | if ((curObj["SequenceNumber"] == null)) { |
|---|
| 346 | return System.Convert.ToUInt32(0); |
|---|
| 347 | } |
|---|
| 348 | return ((uint)(curObj["SequenceNumber"])); |
|---|
| 349 | } |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { |
|---|
| 353 | if (((path != null) |
|---|
| 354 | && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { |
|---|
| 355 | return true; |
|---|
| 356 | } |
|---|
| 357 | else { |
|---|
| 358 | return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); |
|---|
| 359 | } |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { |
|---|
| 363 | if (((theObj != null) |
|---|
| 364 | && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { |
|---|
| 365 | return true; |
|---|
| 366 | } |
|---|
| 367 | else { |
|---|
| 368 | System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); |
|---|
| 369 | if ((parentClasses != null)) { |
|---|
| 370 | int count = 0; |
|---|
| 371 | for (count = 0; (count < parentClasses.Length); count = (count + 1)) { |
|---|
| 372 | if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { |
|---|
| 373 | return true; |
|---|
| 374 | } |
|---|
| 375 | } |
|---|
| 376 | } |
|---|
| 377 | } |
|---|
| 378 | return false; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | private void ResetCreationTime() { |
|---|
| 382 | curObj["CreationTime"] = null; |
|---|
| 383 | if (((isEmbedded == false) |
|---|
| 384 | && (AutoCommitProp == true))) { |
|---|
| 385 | PrivateLateBoundObject.Put(); |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | private void ResetDescription() { |
|---|
| 390 | curObj["Description"] = null; |
|---|
| 391 | if (((isEmbedded == false) |
|---|
| 392 | && (AutoCommitProp == true))) { |
|---|
| 393 | PrivateLateBoundObject.Put(); |
|---|
| 394 | } |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | private bool ShouldSerializeEventType() { |
|---|
| 398 | if ((this.IsEventTypeNull == false)) { |
|---|
| 399 | return true; |
|---|
| 400 | } |
|---|
| 401 | return false; |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | private void ResetEventType() { |
|---|
| 405 | curObj["EventType"] = null; |
|---|
| 406 | if (((isEmbedded == false) |
|---|
| 407 | && (AutoCommitProp == true))) { |
|---|
| 408 | PrivateLateBoundObject.Put(); |
|---|
| 409 | } |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | private bool ShouldSerializeRestorePointType() { |
|---|
| 413 | if ((this.IsRestorePointTypeNull == false)) { |
|---|
| 414 | return true; |
|---|
| 415 | } |
|---|
| 416 | return false; |
|---|
| 417 | } |
|---|
| 418 | |
|---|
| 419 | private void ResetRestorePointType() { |
|---|
| 420 | curObj["RestorePointType"] = null; |
|---|
| 421 | if (((isEmbedded == false) |
|---|
| 422 | && (AutoCommitProp == true))) { |
|---|
| 423 | PrivateLateBoundObject.Put(); |
|---|
| 424 | } |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | private bool ShouldSerializeSequenceNumber() { |
|---|
| 428 | if ((this.IsSequenceNumberNull == false)) { |
|---|
| 429 | return true; |
|---|
| 430 | } |
|---|
| 431 | return false; |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | [Browsable(true)] |
|---|
| 435 | public void CommitObject() { |
|---|
| 436 | if ((isEmbedded == false)) { |
|---|
| 437 | PrivateLateBoundObject.Put(); |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | [Browsable(true)] |
|---|
| 442 | public void CommitObject(System.Management.PutOptions putOptions) { |
|---|
| 443 | if ((isEmbedded == false)) { |
|---|
| 444 | PrivateLateBoundObject.Put(putOptions); |
|---|
| 445 | } |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | private void Initialize() { |
|---|
| 449 | AutoCommitProp = true; |
|---|
| 450 | isEmbedded = false; |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | private static string ConstructPath(uint keySequenceNumber) { |
|---|
| 454 | string strPath = "root\\default:SystemRestore"; |
|---|
| 455 | strPath = string.Concat(strPath, string.Concat(".SequenceNumber=", ((System.UInt32 )(keySequenceNumber)).ToString())); |
|---|
| 456 | return strPath; |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { |
|---|
| 460 | Initialize(); |
|---|
| 461 | if ((path != null)) { |
|---|
| 462 | if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { |
|---|
| 463 | throw new System.ArgumentException("Class name does not match."); |
|---|
| 464 | } |
|---|
| 465 | } |
|---|
| 466 | PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); |
|---|
| 467 | PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); |
|---|
| 468 | curObj = PrivateLateBoundObject; |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | // Different overloads of GetInstances() help in enumerating instances of the WMI class. |
|---|
| 472 | public static SystemRestoreCollection GetInstances() { |
|---|
| 473 | return GetInstances(null, null, null); |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | public static SystemRestoreCollection GetInstances(string condition) { |
|---|
| 477 | return GetInstances(null, condition, null); |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | public static SystemRestoreCollection GetInstances(System.String [] selectedProperties) { |
|---|
| 481 | return GetInstances(null, null, selectedProperties); |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | public static SystemRestoreCollection GetInstances(string condition, System.String [] selectedProperties) { |
|---|
| 485 | return GetInstances(null, condition, selectedProperties); |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | public static SystemRestoreCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { |
|---|
| 489 | if ((mgmtScope == null)) { |
|---|
| 490 | if ((statMgmtScope == null)) { |
|---|
| 491 | mgmtScope = new System.Management.ManagementScope(); |
|---|
| 492 | mgmtScope.Path.NamespacePath = "root\\default"; |
|---|
| 493 | } |
|---|
| 494 | else { |
|---|
| 495 | mgmtScope = statMgmtScope; |
|---|
| 496 | } |
|---|
| 497 | } |
|---|
| 498 | System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); |
|---|
| 499 | pathObj.ClassName = "SystemRestore"; |
|---|
| 500 | pathObj.NamespacePath = "root\\default"; |
|---|
| 501 | System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); |
|---|
| 502 | if ((enumOptions == null)) { |
|---|
| 503 | enumOptions = new System.Management.EnumerationOptions(); |
|---|
| 504 | enumOptions.EnsureLocatable = true; |
|---|
| 505 | } |
|---|
| 506 | return new SystemRestoreCollection(clsObject.GetInstances(enumOptions)); |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | public static SystemRestoreCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { |
|---|
| 510 | return GetInstances(mgmtScope, condition, null); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | public static SystemRestoreCollection GetInstances(System.Management.ManagementScope mgmtScope, System.String [] selectedProperties) { |
|---|
| 514 | return GetInstances(mgmtScope, null, selectedProperties); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | public static SystemRestoreCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, System.String [] selectedProperties) { |
|---|
| 518 | if ((mgmtScope == null)) { |
|---|
| 519 | if ((statMgmtScope == null)) { |
|---|
| 520 | mgmtScope = new System.Management.ManagementScope(); |
|---|
| 521 | mgmtScope.Path.NamespacePath = "root\\default"; |
|---|
| 522 | } |
|---|
| 523 | else { |
|---|
| 524 | mgmtScope = statMgmtScope; |
|---|
| 525 | } |
|---|
| 526 | } |
|---|
| 527 | System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("SystemRestore", condition, selectedProperties)); |
|---|
| 528 | System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); |
|---|
| 529 | enumOptions.EnsureLocatable = true; |
|---|
| 530 | ObjectSearcher.Options = enumOptions; |
|---|
| 531 | return new SystemRestoreCollection(ObjectSearcher.Get()); |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | [Browsable(true)] |
|---|
| 535 | public static SystemRestore CreateInstance() { |
|---|
| 536 | System.Management.ManagementScope mgmtScope = null; |
|---|
| 537 | if ((statMgmtScope == null)) { |
|---|
| 538 | mgmtScope = new System.Management.ManagementScope(); |
|---|
| 539 | mgmtScope.Path.NamespacePath = CreatedWmiNamespace; |
|---|
| 540 | } |
|---|
| 541 | else { |
|---|
| 542 | mgmtScope = statMgmtScope; |
|---|
| 543 | } |
|---|
| 544 | System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); |
|---|
| 545 | System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); |
|---|
| 546 | return new SystemRestore(tmpMgmtClass.CreateInstance()); |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | [Browsable(true)] |
|---|
| 550 | public void Delete() { |
|---|
| 551 | PrivateLateBoundObject.Delete(); |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | public static uint CreateRestorePoint(string Description, uint EventType, uint RestorePointType) { |
|---|
| 555 | bool IsMethodStatic = true; |
|---|
| 556 | if ((IsMethodStatic == true)) { |
|---|
| 557 | System.Management.ManagementBaseObject inParams = null; |
|---|
| 558 | System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); |
|---|
| 559 | System.Management.ManagementClass classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null); |
|---|
| 560 | inParams = classObj.GetMethodParameters("CreateRestorePoint"); |
|---|
| 561 | inParams["Description"] = ((System.String )(Description)); |
|---|
| 562 | inParams["EventType"] = ((System.UInt32 )(EventType)); |
|---|
| 563 | inParams["RestorePointType"] = ((System.UInt32 )(RestorePointType)); |
|---|
| 564 | System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("CreateRestorePoint", inParams, null); |
|---|
| 565 | return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); |
|---|
| 566 | } |
|---|
| 567 | else { |
|---|
| 568 | return System.Convert.ToUInt32(0); |
|---|
| 569 | } |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | public static uint Disable(string Drive) { |
|---|
| 573 | bool IsMethodStatic = true; |
|---|
| 574 | if ((IsMethodStatic == true)) { |
|---|
| 575 | System.Management.ManagementBaseObject inParams = null; |
|---|
| 576 | System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); |
|---|
| 577 | System.Management.ManagementClass classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null); |
|---|
| 578 | inParams = classObj.GetMethodParameters("Disable"); |
|---|
| 579 | inParams["Drive"] = ((System.String )(Drive)); |
|---|
| 580 | System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("Disable", inParams, null); |
|---|
| 581 | return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); |
|---|
| 582 | } |
|---|
| 583 | else { |
|---|
| 584 | return System.Convert.ToUInt32(0); |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | public static uint Enable(string Drive, bool WaitTillEnabled) { |
|---|
| 589 | bool IsMethodStatic = true; |
|---|
| 590 | if ((IsMethodStatic == true)) { |
|---|
| 591 | System.Management.ManagementBaseObject inParams = null; |
|---|
| 592 | System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); |
|---|
| 593 | System.Management.ManagementClass classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null); |
|---|
| 594 | inParams = classObj.GetMethodParameters("Enable"); |
|---|
| 595 | inParams["Drive"] = ((System.String )(Drive)); |
|---|
| 596 | inParams["WaitTillEnabled"] = ((System.Boolean )(WaitTillEnabled)); |
|---|
| 597 | System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("Enable", inParams, null); |
|---|
| 598 | return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); |
|---|
| 599 | } |
|---|
| 600 | else { |
|---|
| 601 | return System.Convert.ToUInt32(0); |
|---|
| 602 | } |
|---|
| 603 | } |
|---|
| 604 | |
|---|
| 605 | public static uint GetLastRestoreStatus() { |
|---|
| 606 | bool IsMethodStatic = true; |
|---|
| 607 | if ((IsMethodStatic == true)) { |
|---|
| 608 | System.Management.ManagementBaseObject inParams = null; |
|---|
| 609 | System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); |
|---|
| 610 | System.Management.ManagementClass classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null); |
|---|
| 611 | System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("GetLastRestoreStatus", inParams, null); |
|---|
| 612 | return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); |
|---|
| 613 | } |
|---|
| 614 | else { |
|---|
| 615 | return System.Convert.ToUInt32(0); |
|---|
| 616 | } |
|---|
| 617 | } |
|---|
| 618 | |
|---|
| 619 | public static uint Restore(uint SequenceNumber) { |
|---|
| 620 | bool IsMethodStatic = true; |
|---|
| 621 | if ((IsMethodStatic == true)) { |
|---|
| 622 | System.Management.ManagementBaseObject inParams = null; |
|---|
| 623 | System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); |
|---|
| 624 | System.Management.ManagementClass classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null); |
|---|
| 625 | inParams = classObj.GetMethodParameters("Restore"); |
|---|
| 626 | inParams["SequenceNumber"] = ((System.UInt32 )(SequenceNumber)); |
|---|
| 627 | System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("Restore", inParams, null); |
|---|
| 628 | return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); |
|---|
| 629 | } |
|---|
| 630 | else { |
|---|
| 631 | return System.Convert.ToUInt32(0); |
|---|
| 632 | } |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | // Enumerator implementation for enumerating instances of the class. |
|---|
| 636 | public class SystemRestoreCollection : object, ICollection { |
|---|
| 637 | |
|---|
| 638 | private ManagementObjectCollection privColObj; |
|---|
| 639 | |
|---|
| 640 | public SystemRestoreCollection(ManagementObjectCollection objCollection) { |
|---|
| 641 | privColObj = objCollection; |
|---|
| 642 | } |
|---|
| 643 | |
|---|
| 644 | public virtual int Count { |
|---|
| 645 | get { |
|---|
| 646 | return privColObj.Count; |
|---|
| 647 | } |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | public virtual bool IsSynchronized { |
|---|
| 651 | get { |
|---|
| 652 | return privColObj.IsSynchronized; |
|---|
| 653 | } |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | public virtual object SyncRoot { |
|---|
| 657 | get { |
|---|
| 658 | return this; |
|---|
| 659 | } |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | public virtual void CopyTo(System.Array array, int index) { |
|---|
| 663 | privColObj.CopyTo(array, index); |
|---|
| 664 | int nCtr; |
|---|
| 665 | for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { |
|---|
| 666 | array.SetValue(new SystemRestore(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); |
|---|
| 667 | } |
|---|
| 668 | } |
|---|
| 669 | |
|---|
| 670 | public virtual System.Collections.IEnumerator GetEnumerator() { |
|---|
| 671 | return new SystemRestoreEnumerator(privColObj.GetEnumerator()); |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | public class SystemRestoreEnumerator : object, System.Collections.IEnumerator { |
|---|
| 675 | |
|---|
| 676 | private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; |
|---|
| 677 | |
|---|
| 678 | public SystemRestoreEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { |
|---|
| 679 | privObjEnum = objEnum; |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | public virtual object Current { |
|---|
| 683 | get { |
|---|
| 684 | return new SystemRestore(((System.Management.ManagementObject)(privObjEnum.Current))); |
|---|
| 685 | } |
|---|
| 686 | } |
|---|
| 687 | |
|---|
| 688 | public virtual bool MoveNext() { |
|---|
| 689 | return privObjEnum.MoveNext(); |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | public virtual void Reset() { |
|---|
| 693 | privObjEnum.Reset(); |
|---|
| 694 | } |
|---|
| 695 | } |
|---|
| 696 | } |
|---|
| 697 | |
|---|
| 698 | // TypeConverter to handle null values for ValueType properties |
|---|
| 699 | public class WMIValueTypeConverter : TypeConverter { |
|---|
| 700 | |
|---|
| 701 | private TypeConverter baseConverter; |
|---|
| 702 | |
|---|
| 703 | private System.Type baseType; |
|---|
| 704 | |
|---|
| 705 | public WMIValueTypeConverter(System.Type inBaseType) { |
|---|
| 706 | baseConverter = TypeDescriptor.GetConverter(inBaseType); |
|---|
| 707 | baseType = inBaseType; |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { |
|---|
| 711 | return baseConverter.CanConvertFrom(context, srcType); |
|---|
| 712 | } |
|---|
| 713 | |
|---|
| 714 | public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { |
|---|
| 715 | return baseConverter.CanConvertTo(context, destinationType); |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { |
|---|
| 719 | return baseConverter.ConvertFrom(context, culture, value); |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { |
|---|
| 723 | return baseConverter.CreateInstance(context, dictionary); |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { |
|---|
| 727 | return baseConverter.GetCreateInstanceSupported(context); |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| 730 | public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { |
|---|
| 731 | return baseConverter.GetProperties(context, value, attributeVar); |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { |
|---|
| 735 | return baseConverter.GetPropertiesSupported(context); |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { |
|---|
| 739 | return baseConverter.GetStandardValues(context); |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { |
|---|
| 743 | return baseConverter.GetStandardValuesExclusive(context); |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { |
|---|
| 747 | return baseConverter.GetStandardValuesSupported(context); |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { |
|---|
| 751 | if ((baseType.BaseType == typeof(System.Enum))) { |
|---|
| 752 | if ((value.GetType() == destinationType)) { |
|---|
| 753 | return value; |
|---|
| 754 | } |
|---|
| 755 | if ((((value == null) |
|---|
| 756 | && (context != null)) |
|---|
| 757 | && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { |
|---|
| 758 | return "NULL_ENUM_VALUE" ; |
|---|
| 759 | } |
|---|
| 760 | return baseConverter.ConvertTo(context, culture, value, destinationType); |
|---|
| 761 | } |
|---|
| 762 | if (((baseType == typeof(bool)) |
|---|
| 763 | && (baseType.BaseType == typeof(System.ValueType)))) { |
|---|
| 764 | if ((((value == null) |
|---|
| 765 | && (context != null)) |
|---|
| 766 | && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { |
|---|
| 767 | return ""; |
|---|
| 768 | } |
|---|
| 769 | return baseConverter.ConvertTo(context, culture, value, destinationType); |
|---|
| 770 | } |
|---|
| 771 | if (((context != null) |
|---|
| 772 | && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { |
|---|
| 773 | return ""; |
|---|
| 774 | } |
|---|
| 775 | return baseConverter.ConvertTo(context, culture, value, destinationType); |
|---|
| 776 | } |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | // Embedded class to represent WMI system Properties. |
|---|
| 780 | [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] |
|---|
| 781 | public class ManagementSystemProperties { |
|---|
| 782 | |
|---|
| 783 | private System.Management.ManagementBaseObject PrivateLateBoundObject; |
|---|
| 784 | |
|---|
| 785 | public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { |
|---|
| 786 | PrivateLateBoundObject = ManagedObject; |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | [Browsable(true)] |
|---|
| 790 | public int GENUS { |
|---|
| 791 | get { |
|---|
| 792 | return ((int)(PrivateLateBoundObject["__GENUS"])); |
|---|
| 793 | } |
|---|
| 794 | } |
|---|
| 795 | |
|---|
| 796 | [Browsable(true)] |
|---|
| 797 | public string CLASS { |
|---|
| 798 | get { |
|---|
| 799 | return ((string)(PrivateLateBoundObject["__CLASS"])); |
|---|
| 800 | } |
|---|
| 801 | } |
|---|
| 802 | |
|---|
| 803 | [Browsable(true)] |
|---|
| 804 | public string SUPERCLASS { |
|---|
| 805 | get { |
|---|
| 806 | return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); |
|---|
| 807 | } |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | [Browsable(true)] |
|---|
| 811 | public string DYNASTY { |
|---|
| 812 | get { |
|---|
| 813 | return ((string)(PrivateLateBoundObject["__DYNASTY"])); |
|---|
| 814 | } |
|---|
| 815 | } |
|---|
| 816 | |
|---|
| 817 | [Browsable(true)] |
|---|
| 818 | public string RELPATH { |
|---|
| 819 | get { |
|---|
| 820 | return ((string)(PrivateLateBoundObject["__RELPATH"])); |
|---|
| 821 | } |
|---|
| 822 | } |
|---|
| 823 | |
|---|
| 824 | [Browsable(true)] |
|---|
| 825 | public int PROPERTY_COUNT { |
|---|
| 826 | get { |
|---|
| 827 | return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); |
|---|
| 828 | } |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | [Browsable(true)] |
|---|
| 832 | public string[] DERIVATION { |
|---|
| 833 | get { |
|---|
| 834 | return ((string[])(PrivateLateBoundObject["__DERIVATION"])); |
|---|
| 835 | } |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | [Browsable(true)] |
|---|
| 839 | public string SERVER { |
|---|
| 840 | get { |
|---|
| 841 | return ((string)(PrivateLateBoundObject["__SERVER"])); |
|---|
| 842 | } |
|---|
| 843 | } |
|---|
| 844 | |
|---|
| 845 | [Browsable(true)] |
|---|
| 846 | public string NAMESPACE { |
|---|
| 847 | get { |
|---|
| 848 | return ((string)(PrivateLateBoundObject["__NAMESPACE"])); |
|---|
| 849 | } |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | [Browsable(true)] |
|---|
| 853 | public string PATH { |
|---|
| 854 | get { |
|---|
| 855 | return ((string)(PrivateLateBoundObject["__PATH"])); |
|---|
| 856 | } |
|---|
| 857 | } |
|---|
| 858 | } |
|---|
| 859 | } |
|---|
| 860 | } |
|---|