I want to get an "Invalid Query" exception when trying to execute the following query:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskQuota WHERE QuotaVolume.DeviceID = 'C:'"); ManagementObjectCollection quotaCollection = searcher.Get();
However, this works: "SELECT * FROM Win32_DiskQuota".
According to MSDN:
For most uses of class descriptors in a WHERE clause, WMI places the request as invalid and returns an error. However, use the dot (.) Operator for the properties of a type object in WMI. For example, the following query is valid if Prop is a valid property of MyClass and is an object type:
SELECT * FROM MyClass WHERE Prop.embedprop = 5
Does this mean that it only works if Prop is declared as an OBJECT?
Here is the exception information:
System.Management.ManagementException was unhandled HResult=-2146233087 Message=Invalid query Source=System.Management StackTrace: System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() UserQuota.Program.getQuota() c:\users\administrator\documents\visual studio 2015\Projects\UserQuota\UserQuota\Program.cs: 40 UserQuota.Program.Main(String[] args) c:\users\administrator\documents\visual studio 2015\Projects\UserQuota\UserQuota\Program.cs: 33 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() System.Threading.ThreadHelper.ThreadStart_Context(Object state) System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) System.Threading.ThreadHelper.ThreadStart() InnerException:
source share