1

I have a really simple Powershell query:

Get-WmiObject -query 'ASSOCIATORS OF {Win32_LogicalDisk.DeviceID="C:"} WHERE AssocClass = Win32_LogicalDiskToPartition'

On a Windows 7 (64-bit) machine, running this in a Powershell correctly enumerates a single management object. However if I run the same query in an elevated Powershell I get a long pause and then no results.

I find a similar problem when trying to execute the WMI query in code (which is what I am actually trying to do) - when my program runs without elevation the code works, when it runs with elevation no results are returned. This is the simplest version of my code that shows this problem:

static void Main(string[] args)
{
    var query = "ASSOCIATORS OF {Win32_LogicalDisk.DeviceID=\"C:\"} WHERE AssocClass = Win32_LogicalDiskToPartition";
    var searcher = new ManagementObjectSearcher(query);
    foreach (var o in searcher.Get())
    {
        Console.WriteLine(o);
    }
    Console.WriteLine("DONE");
    Console.ReadLine();
}

Why does this happen ? More importantly is there anyway I can ensure that this query will execute correctly when run elevated - as the final program will need to run elevated for other reasons.

Kal
  • 1,887
  • 12
  • 16
  • I can't duplicate the Get-WmiObject problem on my Windows 7 x64 machine. The response comes back quickly and is the same as the non-elevated shell's response. – Keith Hill Dec 06 '12 at 16:13
  • That's interesting, thanks Keith. I find that the problem doesn't happen on my Windows 8 machine, so I had assumed it was related to OS version. Unfortunately I have no other Win7 x64 machine to try replicating this on. – Kal Dec 06 '12 at 16:24

1 Answers1

0

I think I found the culprit - I have an encrypted drive mounted using TrueCrypt. When I dismount that drive the enumeration works correctly, when I mount it again the problem re-appears.

My best guess is that WMI is hitting a problem because the encrypted drive has no partitions - though why it works when not running elevated is another thing entirely.

Kal
  • 1,887
  • 12
  • 16