WMI를 사용하여 C : 드라이브 조각 모음을 수행하려고합니다.C#에서 WMI 조각 모음 메서드를 찾을 수 없습니다.
저는 Windows 7 Pro x64를 사용하고 있습니다.
Console.WriteLine(SMARTManager.Instance.SMARTHDD.Defrag("C:", ref ERR));
기능 :
public string Defrag(string a_DriveName, ref string ERR)
{
try
{
ManagementObject classInstance =
new ManagementObject("root\\CIMV2",
String.Format("Win32_Volume.DeviceID='{0}'", a_DriveName),
null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
classInstance.GetMethodParameters("Defrag");
// Add the input parameters.
inParams["Force"] = true;
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("Defrag", inParams, null);
// List outParams
string callback = "Out parameters:\n" + "ReturnValue: " + outParams["ReturnValue"];
return callback;
}
catch (ManagementException err)
{
ERR = "An error occurred while trying to execute the WMI method: " + err.Message;
}
return null;
}
나는 WMI 코드 작성자에서이 코드를 가지고 있지만 그것을 실행할 때 그것은 "찾을 수 없음"말하는 exeption를 반환합니다.
다른 사람이 사용해 보았습니까? 당신이 ManagementObject
생성자에 잘못된 개체 경로를 전달하기 때문에이 오류가 발생
당신은 어떤 OS를에 실행중인
Name
속성을 사용하여이 샘플 코드? WMI 공급자는 Windows 버전마다 다릅니다. – DaiWindows 7 Pro x64 –