Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top