473,387 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Management Object vrs Scripting

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
1 5602

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Academic Q | last post by:
It may be a bad question, but.. What is the difference between Object Oriented Language and Object Orinted Srcipting? The code is simplier in scripting than the code in other programming language?...
4
by: The_Incubator | last post by:
As the subject suggests, I am interested in using Python as a scripting language for a game that is primarily implemented in C++, and I am also interested in using generators in those scripts... ...
8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
1
by: Abelardo Vacca | last post by:
Hello, I am currently in the process of switching our application to a N-Tier model with .NET. One of the aspects we want ot get right from the start not to worry about it after is the...
9
by: Keith Rowe | last post by:
Hello, I am trying to reference a Shockwave Flash Object on a vb code behind page in an ASP.NET project and I receive the following error: Guid should contain 32 digits with 4 dashes...
5
by: Abhilash.k.m | last post by:
This is regarding the session management using Out of proc session management(SQL SERVER). Among the samples below which one is better to set the session? 1. There are 20 session...
7
by: scorpion53061 | last post by:
I get the following error with the class below it when installing on a NT/98/Me machine. Any suggestions would be helpful. Kind of in a bind. Suspect the issue revolves ...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
8
by: =?ISO-8859-15?B?TnXxbw==?= I.G | last post by:
Hello to everybody: I'm trying to get some information about "process management". Let's explain a little... I want to write some code that allows me to execute some "aplications" and collect...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.