By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,033 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,033 IT Pros & Developers. It's quick & easy.

Management Object vrs Scripting

P: n/a
I have used System.Management in the past to extract and
walk thru drives & check their type. I can also do it
with COM's FileSystemObject. Here I am trying to just use
the Management Object after using the Directory class...

There seems to be a way to load the System Management
Object with string path ( 8 overloads ), but every time I
try a variation it crashes. Any ideas ? Thanks

Scripting.FileSystemObject FSO = new
Scripting.FileSystemObjectClass();
string [] logDrives=Directory.GetLogicalDrives();
for ( int i =0;i< logDrives.GetUpperBound(0)+1;i++)
{
System.Management.ManagementObject moDrive = new
System.Management.ManagementObject(logDrives[i]); // crash
moDrive.Properties["DriveType"].Value.ToString();
Scripting.Drive thisdrive=FSO.GetDrive(logDrives[i]);
if (thisdrive.DriveType==Scripting.DriveTypeConst.CDR om)
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Hi Andrew,

You should pass the WMI path to the ManagementObject's constructor.
To get the disk information by ManagementObject, you should use parameter:
"Win32_LogicalDisk='[diskletter]:'"

So you can do something like this:

Scripting.FileSystemObject FSO = new Scripting.FileSystemObjectClass();
string [] logDrives=System.IO.Directory.GetLogicalDrives();
for ( int i =0;i< logDrives.GetUpperBound(0)+1;i++)
{
string disk=logDrives[i].Substring(0,2);
string param="Win32_LogicalDisk='"+disk+"'";
System.Management.ManagementObject moDrive = new
System.Management.ManagementObject(param); // crash
//moDrive.Properties["DriveType"].Value.ToString();
Scripting.Drive thisdrive=FSO.GetDrive(logDrives[i]);
if (thisdrive.DriveType==Scripting.DriveTypeConst.CDR om )
{
MessageBox.Show(thisdrive.Path);
}
}

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "andrewcw" <an************@boeing.com>
| Sender: "andrewcw" <an************@boeing.com>
| Subject: Management Object vrs Scripting
| Date: Fri, 19 Sep 2003 14:24:16 -0700
| Lines: 19
| Message-ID: <12****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcN+9GEFc9zUkkAbSyuqmAfP8D/uLw==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:186216
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have used System.Management in the past to extract and
| walk thru drives & check their type. I can also do it
| with COM's FileSystemObject. Here I am trying to just use
| the Management Object after using the Directory class...
|
| There seems to be a way to load the System Management
| Object with string path ( 8 overloads ), but every time I
| try a variation it crashes. Any ideas ? Thanks
|
| Scripting.FileSystemObject FSO = new
| Scripting.FileSystemObjectClass();
| string [] logDrives=Directory.GetLogicalDrives();
| for ( int i =0;i< logDrives.GetUpperBound(0)+1;i++)
| {
| System.Management.ManagementObject moDrive = new
| System.Management.ManagementObject(logDrives[i]); // crash
| moDrive.Properties["DriveType"].Value.ToString();
| Scripting.Drive thisdrive=FSO.GetDrive(logDrives[i]);
| if (thisdrive.DriveType==Scripting.DriveTypeConst.CDR om)
|

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.