public static void Command(string vCommand, string machineName, string username, string password)
{
ManagementScope Scope = null;
ConnectionOptions ConnOptions = null;
ObjectQuery ObjQuery = null;
ManagementObjectSearcher ObjSearcher = null;
try
{
ConnOptions = new ConnectionOptions();
ConnOptions.Impersonation = ImpersonationLevel.Impersonate;
ConnOptions.EnablePrivileges = true;
if (machineName.ToUpper() == Environment.MachineName.ToUpper())
Scope = new ManagementScope(@"\ROOT\CIMV2", ConnOptions);
else
{
ConnOptions.Username = username;
ConnOptions.Password = password;
Scope = new ManagementScope(@"\\" + machineName + @"\ROOT\CIMV2", ConnOptions);
}
Scope.Connect();
ObjQuery = new ObjectQuery("SELECT * FROM Win32_Directory WHERE Name = 'c:\\0stuff'");
ObjSearcher = new ManagementObjectSearcher(Scope, ObjQuery);
foreach (ManagementObject obj in ObjSearcher.Get())
{
}
if (ObjSearcher != null)
{
ObjSearcher.Dispose();
}
}
catch (Exception ex)
{
throw ex;
}
}
}
If I use only "ObjQuery = new ObjectQuery (" SELECT * FROM Win32_Directory ")," I don't see a problem at all.
But as soon as I try to use "WHERE Name = X", I get an "invalid request" error.
I do not know what is wrong. (and before someone asks yes c: \ 0stuff exist).
source
share