Any alternative solutions to this

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sysdeamon

    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.GetL ogicalDrives()' but it also returns floppy and CD
    drives letters as well.

    i faced the same result when i used 'WqlObjectQuery ("select * from
    Win32_LogicalDi sk")'.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_LogicalDi sk");
    ManagementObjec tSearcher searcher = new
    ManagementObjec tSearcher(objec tQuery);
    ManagementObjec tCollection disks = searcher.Get();
    foreach (ManagementObje ct disk in disks)
    {
    if(disk["DriveType"].ToString() == "3")
    {
    Console.WriteLi ne("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.
  • Jonathan Allen

    #2
    Re: Any alternative solutions to this

    > 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" <sysdeamon@disc ussions.microso ft.com> wrote in message
    news:65A0C1A8-8E40-480B-9776-776E553AC8FD@mi crosoft.com...[color=blue]
    > 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.GetL ogicalDrives()' but it also returns floppy and
    > CD
    > drives letters as well.
    >
    > i faced the same result when i used 'WqlObjectQuery ("select * from
    > Win32_LogicalDi sk")'.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_LogicalDi sk");
    > ManagementObjec tSearcher searcher = new
    > ManagementObjec tSearcher(objec tQuery);
    > ManagementObjec tCollection disks = searcher.Get();
    > foreach (ManagementObje ct disk in disks)
    > {
    > if(disk["DriveType"].ToString() == "3")
    > {
    > Console.WriteLi ne("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.[/color]


    Comment

    • Dmitry Klymenko

      #3
      Re: Any alternative solutions to this

      One more point of usage of WMI (WqlObjectQuery ("select * from Win32_LogicalDi sk"))
      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.GetLo gicalDrives()) will never twilight be ported.
      "sysdeamon" <sysdeamon@disc ussions.microso ft.com> wrote in message news:65A0C1A8-8E40-480B-9776-776E553AC8FD@mi crosoft.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.GetL ogicalDrives()' but it also returns floppy and CD
      drives letters as well.

      i faced the same result when i used 'WqlObjectQuery ("select * from
      Win32_LogicalDi sk")'.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_LogicalDi sk");
      ManagementObjec tSearcher searcher = new
      ManagementObjec tSearcher(objec tQuery);
      ManagementObjec tCollection disks = searcher.Get();
      foreach (ManagementObje ct disk in disks)
      {
      if(disk["DriveType"].ToString() == "3")
      {
      Console.WriteLi ne("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.

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Any alternative solutions to this

        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.Managem ent namespace is managed code).

        Willy.


        "Dmitry Klymenko" <test@proofingo nline.com> wrote in message news:d80vil$afe $1@news.dg.net. ua...
        One more point of usage of WMI (WqlObjectQuery ("select * from Win32_LogicalDi sk"))
        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.GetLo gicalDrives()) will never twilight be ported.
        "sysdeamon" <sysdeamon@disc ussions.microso ft.com> wrote in message news:65A0C1A8-8E40-480B-9776-776E553AC8FD@mi crosoft.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.GetL ogicalDrives()' but it also returns floppy and CD
        drives letters as well.

        i faced the same result when i used 'WqlObjectQuery ("select * from
        Win32_LogicalDi sk")'.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_LogicalDi sk");
        ManagementObjec tSearcher searcher = new
        ManagementObjec tSearcher(objec tQuery);
        ManagementObjec tCollection disks = searcher.Get();
        foreach (ManagementObje ct disk in disks)
        {
        if(disk["DriveType"].ToString() == "3")
        {
        Console.WriteLi ne("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.

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Any alternative solutions to this


          "sysdeamon" <sysdeamon@disc ussions.microso ft.com> wrote in message
          news:65A0C1A8-8E40-480B-9776-776E553AC8FD@mi crosoft.com...[color=blue]
          > 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.GetL ogicalDrives()' but it also returns floppy and
          > CD
          > drives letters as well.
          >
          > i faced the same result when i used 'WqlObjectQuery ("select * from
          > Win32_LogicalDi sk")'.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_LogicalDi sk");
          > ManagementObjec tSearcher searcher = new
          > ManagementObjec tSearcher(objec tQuery);
          > ManagementObjec tCollection disks = searcher.Get();
          > foreach (ManagementObje ct disk in disks)
          > {
          > if(disk["DriveType"].ToString() == "3")
          > {
          > Console.WriteLi ne("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.[/color]

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

          Willy.


          Comment

          Working...