VBScript to C#
-
I'm trying to write an app that handles system restore related stuff and would like to know how to convert the VBScript(s) in the following page into C# equivalent: http://support.microsoft.com/default.aspx?scid=KB;en-us;295299&
-
I'm trying to write an app that handles system restore related stuff and would like to know how to convert the VBScript(s) in the following page into C# equivalent: http://support.microsoft.com/default.aspx?scid=KB;en-us;295299&
Look at the
System.Management.ManagementClass
class. My quick stab looks like:ManagementClass mc =
new ManagementClass( @"\\.\root\default:Systemrestore" );
mc.Get();mc.InvokeMethod(
"CreateRestorePoint",
new object[] { "this is a test", 0, 100 }
);However, this didn't appear to do anything - but then I may be misunderstanding the underlying API.
-
Look at the
System.Management.ManagementClass
class. My quick stab looks like:ManagementClass mc =
new ManagementClass( @"\\.\root\default:Systemrestore" );
mc.Get();mc.InvokeMethod(
"CreateRestorePoint",
new object[] { "this is a test", 0, 100 }
);However, this didn't appear to do anything - but then I may be misunderstanding the underlying API.
Thanks. It works (at least on WinXP) but i'm wondering how to get the other one to work : set SRP = getobject("winmgmts:\\.\root\default").InstancesOf ("systemrestore") for each Point in SRP msgbox point.creationtime & vbcrlf & point.description & vbcrlf & "Sequence Number= " & point.sequencenumber next
-
Thanks. It works (at least on WinXP) but i'm wondering how to get the other one to work : set SRP = getobject("winmgmts:\\.\root\default").InstancesOf ("systemrestore") for each Point in SRP msgbox point.creationtime & vbcrlf & point.description & vbcrlf & "Sequence Number= " & point.sequencenumber next
After a bit of trial and terror:
ManagementScope scope =
new ManagementScope( @"\\.\root\default" );
scope.Connect();SelectQuery sq = new SelectQuery( "SystemRestore" );
ManagementObjectSearcher mos =
new ManagementObjectSearcher( scope, sq );foreach ( ManagementObject mo in mos.Get() )
{
Console.WriteLine(
"{0}: {1}, sequence no {2}",
mo[ "CreationTime" ],
mo[ "Description" ],
mo[ "SequenceNumber" ]
);
}When investigating a
ManagementObject
, you may find theProperties
collection helpful. -
After a bit of trial and terror:
ManagementScope scope =
new ManagementScope( @"\\.\root\default" );
scope.Connect();SelectQuery sq = new SelectQuery( "SystemRestore" );
ManagementObjectSearcher mos =
new ManagementObjectSearcher( scope, sq );foreach ( ManagementObject mo in mos.Get() )
{
Console.WriteLine(
"{0}: {1}, sequence no {2}",
mo[ "CreationTime" ],
mo[ "Description" ],
mo[ "SequenceNumber" ]
);
}When investigating a
ManagementObject
, you may find theProperties
collection helpful.