내 응용 프로그램에서 Windows 7이 활성화되어 있는지 확인하고 싶습니다. 분명히하기 위해 나는 창문이 진짜인지 확인하고 싶지 않다. 여기에있는 코드를 사용합니다. http://www.dreamincode.net/forums/topic/166690-wmi-softwarelicensingproduct/WMI 쿼리 실행 시간 줄이기
쿼리를 실행하는 데 필요한 시간은 약 5-10 초입니다. 어쨌든 필요한 시간을 줄이기 위해 있습니까? 또는 winows 7이 활성화되어 있는지 확인하는 다른 방법은 있습니까?
public string VistaOrNewerStatus(){
string status = string.Empty;
string computer = ".";
try
{
//set the scope of this search
ManagementScope scope = new ManagementScope(@"\\" + computer + @"\root\cimv2");
//connect to the machine
scope.Connect();
//use a SelectQuery to tell what we're searching in
SelectQuery searchQuery = new SelectQuery("SELECT * FROM SoftwareLicensingProduct");
//set the search up
ManagementObjectSearcher searcherObj = new ManagementObjectSearcher(scope, searchQuery);
//get the results into a collection
using (ManagementObjectCollection obj = searcherObj.Get())
{
MessageBox.Show(obj.Count.ToString());
//now loop through the collection looking for
//an activation status
foreach (ManagementObject o in obj)
{
//MessageBox.Show(o["ActivationRequired"].ToString());
switch ((UInt32)o["LicenseStatus"])
{
case 0:
status = "Unlicensed";
break;
case 1:
status = "Licensed";
break;
case 2:
status = "Out-Of-Box Grace Period";
break;
case 3:
status = "Out-Of-Tolerance Grace Period";
break;
case 4:
status = "Non-Genuine Grace Period";
break;
}
}
}
// return activated;
}
catch (Exception ex)
{
// MessageBox.Show(ex.ToString());
status = ex.Message;
//return false;
}
return status;
}
싫다. 그게 wmi와 함께 할 수있는 방법. 그걸 빨리 만들지는 않을거야. –