473,406 Members | 2,867 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,406 software developers and data experts.

Any alternative solutions to this

Hi,
i am new to Visual C#.
i am trying to develop a file searcher utility similar to that of Windows
own 'Search for files and folder' for desktop.
i want to know is there a method that can return all the valid hard
disk/partitions on a system, so i can have a option like 'Local harddrives'
in my program.
i have used 'Directory.GetLogicalDrives()' but it also returns floppy and CD
drives letters as well.

i faced the same result when i used 'WqlObjectQuery("select * from
Win32_LogicalDisk")'.i must mention i am new to WMI as well.
However i have succeeded in isolating the logical drives by checking
"DriveType" property of Management Objects returned by this query.

WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection disks = searcher.Get();
foreach (ManagementObject disk in disks)
{
if(disk["DriveType"].ToString() == "3")
{
Console.WriteLine("Disk = " + disk["deviceid"]);
}
}

The query takes considerable time to show the results so i was wondering if
there is a better way of getting the same result or speeding up execution of
this particular query. I dont want to use any unmanaged DLL to solve this.
Thanks for any help/hints offered.
Nov 17 '05 #1
4 3533
> i am new to Visual C#.

You could have fooled me, I wouldn't have found Wql so easily. Thanks for
introducing it to me.

As for your problem, you were so close its funny. All you have to do is add
"WHERE DriveType=3" to your query. Don't you love those rare cases where
things just work.?
As for the speed issue, it only seems slow the first time I run it. After
that, it returns pretty quick.

--
Jonathan Allen
"sysdeamon" <sy*******@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Hi,
i am new to Visual C#.
i am trying to develop a file searcher utility similar to that of Windows
own 'Search for files and folder' for desktop.
i want to know is there a method that can return all the valid hard
disk/partitions on a system, so i can have a option like 'Local
harddrives'
in my program.
i have used 'Directory.GetLogicalDrives()' but it also returns floppy and
CD
drives letters as well.

i faced the same result when i used 'WqlObjectQuery("select * from
Win32_LogicalDisk")'.i must mention i am new to WMI as well.
However i have succeeded in isolating the logical drives by checking
"DriveType" property of Management Objects returned by this query.

WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection disks = searcher.Get();
foreach (ManagementObject disk in disks)
{
if(disk["DriveType"].ToString() == "3")
{
Console.WriteLine("Disk = " + disk["deviceid"]);
}
}

The query takes considerable time to show the results so i was wondering
if
there is a better way of getting the same result or speeding up execution
of
this particular query. I dont want to use any unmanaged DLL to solve this.
Thanks for any help/hints offered.

Nov 17 '05 #2
One more point of usage of WMI (WqlObjectQuery("select * from Win32_LogicalDisk"))
This will not work on client computer if it has service Windows Management.. disabled.

Try to use PInvoke and some of kernel32.dll functions. Any way both of this behavior (except Directory.GetLogicalDrives()) will never twilight be ported.
"sysdeamon" <sy*******@discussions.microsoft.com> wrote in message news:65**********************************@microsof t.com...
Hi,
i am new to Visual C#.
i am trying to develop a file searcher utility similar to that of Windows
own 'Search for files and folder' for desktop.
i want to know is there a method that can return all the valid hard
disk/partitions on a system, so i can have a option like 'Local harddrives'
in my program.
i have used 'Directory.GetLogicalDrives()' but it also returns floppy and CD
drives letters as well.

i faced the same result when i used 'WqlObjectQuery("select * from
Win32_LogicalDisk")'.i must mention i am new to WMI as well.
However i have succeeded in isolating the logical drives by checking
"DriveType" property of Management Objects returned by this query.

WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection disks = searcher.Get();
foreach (ManagementObject disk in disks)
{
if(disk["DriveType"].ToString() == "3")
{
Console.WriteLine("Disk = " + disk["deviceid"]);
}
}

The query takes considerable time to show the results so i was wondering if
there is a better way of getting the same result or speeding up execution of
this particular query. I dont want to use any unmanaged DLL to solve this.
Thanks for any help/hints offered.
Nov 17 '05 #3
Any reason why a client would disable this service? To disable the service you need administrator privileges, do your clients run as administrator?, well seems you don't care about security at all.
The WMI service is a system service that's needed by other system components, it should not be disabled, unless you know the consequences of what you are doing. Heck, you don't disable the lssa service or the plug and play service as well do you?
Don't know for sure what is meant by this - Any way both of this behavior will never twilight be ported.
So please stop forcing people to PInvoke low level Win32 API's when higher level managed OO solutions are available (System.Management namespace is managed code).

Willy.
"Dmitry Klymenko" <te**@proofingonline.com> wrote in message news:d8**********@news.dg.net.ua...
One more point of usage of WMI (WqlObjectQuery("select * from Win32_LogicalDisk"))
This will not work on client computer if it has service Windows Management.. disabled.

Try to use PInvoke and some of kernel32.dll functions. Any way both of this behavior (except Directory.GetLogicalDrives()) will never twilight be ported.
"sysdeamon" <sy*******@discussions.microsoft.com> wrote in message news:65**********************************@microsof t.com...
Hi,
i am new to Visual C#.
i am trying to develop a file searcher utility similar to that of Windows
own 'Search for files and folder' for desktop.
i want to know is there a method that can return all the valid hard
disk/partitions on a system, so i can have a option like 'Local harddrives'
in my program.
i have used 'Directory.GetLogicalDrives()' but it also returns floppy and CD
drives letters as well.

i faced the same result when i used 'WqlObjectQuery("select * from
Win32_LogicalDisk")'.i must mention i am new to WMI as well.
However i have succeeded in isolating the logical drives by checking
"DriveType" property of Management Objects returned by this query.

WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection disks = searcher.Get();
foreach (ManagementObject disk in disks)
{
if(disk["DriveType"].ToString() == "3")
{
Console.WriteLine("Disk = " + disk["deviceid"]);
}
}

The query takes considerable time to show the results so i was wondering if
there is a better way of getting the same result or speeding up execution of
this particular query. I dont want to use any unmanaged DLL to solve this.
Thanks for any help/hints offered.
Nov 17 '05 #4

"sysdeamon" <sy*******@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Hi,
i am new to Visual C#.
i am trying to develop a file searcher utility similar to that of Windows
own 'Search for files and folder' for desktop.
i want to know is there a method that can return all the valid hard
disk/partitions on a system, so i can have a option like 'Local
harddrives'
in my program.
i have used 'Directory.GetLogicalDrives()' but it also returns floppy and
CD
drives letters as well.

i faced the same result when i used 'WqlObjectQuery("select * from
Win32_LogicalDisk")'.i must mention i am new to WMI as well.
However i have succeeded in isolating the logical drives by checking
"DriveType" property of Management Objects returned by this query.

WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection disks = searcher.Get();
foreach (ManagementObject disk in disks)
{
if(disk["DriveType"].ToString() == "3")
{
Console.WriteLine("Disk = " + disk["deviceid"]);
}
}

The query takes considerable time to show the results so i was wondering
if
there is a better way of getting the same result or speeding up execution
of
this particular query. I dont want to use any unmanaged DLL to solve this.
Thanks for any help/hints offered.


Do as Jonathan told you, the query should not take more than a few ten
millisecs.

Willy.
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
by: Paul McGuire | last post by:
There are a number of messages on the python-dev mail list that indicate that Guido is looking for some concensus to come from this list as to what *one* alternative syntax for decorators we would...
1
by: Sune Christesen | last post by:
Hi, I'm trying to get some data from an external website using XMLHTTP, but my problem is that the data is with special danish characters in (ÆØÅ), which are being replaced with "?" due to...
3
by: SomeDude | last post by:
Lo group, During my quest for the "perfect" way for storing tree-structures it quickly became clear that all of the available SQL-solutions have their own peculiar weaknesses (scalability, slow...
7
by: mal_k100 | last post by:
I am seeting up a help system that uses some common text. Using a frame I can link to the common text : <FRAMESET ROWS="100,*" > <FRAME SRC="SpecificTextForHelpPage1.htm" scrolling=no...
13
by: Pamela via AccessMonster.com | last post by:
Hi All; I work for a company which is currently utlizing MS Access on a shared drive where people from all over the country access. Because all are wishing to view a single database maintained...
7
by: Per W. | last post by:
Hi, is there some alternative to iisProtect and AuthentiX to protect folders and files on a IIS server and manage users from web, maybe som freeware or shareware? /Per W.
14
by: ajfish | last post by:
Hi, I am trying to allocate a unique ID to every instance of tag 'foo' in a large XML document. currently I'm doing this: <xsl:variable name="UniqueId"> <xsl:number count="foo" level="any"/>...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: cloud255 | last post by:
Hi, I've been doing some research and i cannot seem to find a good alternative to MS Info Path. I found some applications that perform a small part of what Info Path does but not one...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.