EMDI는 지금도 개발중

C# : how to get Win32_TerminalServiceSetting information in C# 본문

언어/C#

C# : how to get Win32_TerminalServiceSetting information in C#

EMDI 2019. 11. 25. 16:38
// Win32_TerminalServiceSetting 데이터 가져오기
ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\CIMV2\\TerminalServices"); 
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_TerminalServiceSetting"); 
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); 
ManagementObjectCollection queryCollection = searcher.Get(); 

foreach (ManagementObject queryObj in queryCollection) 
{ 
    Console.WriteLine("-----------------------------------"); 
    ManagementBaseObject returnObj = queryObj.GetMethodParameters("GetWinstationDriverNames"); 
    ManagementBaseObject returnObj2 = queryObj.GetMethodParameters("CanAccessLicenseServer"); 

    Console.WriteLine("LicensingName: {0}", queryObj["LicensingName"]); 
    Console.WriteLine("Name: {0}", queryObj["Name"]); 
    Console.WriteLine("LimitedUserSessions: {0}", queryObj["LimitedUserSessions"]); 
}



//Win32_TerminalService 데이터 가져오기
ManagementClass             mgtClass; 
ManagementObjectCollection  mgtCollections;
mgtClass = new ManagementClass("Win32_TerminalService"); 
mgtCollections = mgtClass.GetInstances(); 

foreach (ManagementObject mo in mgtCollections) 
{ 
    // DisconnectedSessions 
    if (mo["DisconnectedSessions"] != null && 
    !string.IsNullOrEmpty(mo["DisconnectedSessions"].ToString())) 
    SysInfoString += mo["DisconnectedSessions"].ToString() + ","; 
}

Win32_TerminalServiceSetting는 searcher를 이용해서 데이터를 가져오고, Win32_TerminalService는 직접 class에서 바로 가져오는 방법입니다.

어떤 데이터가 있는지 확인하고 싶은 경우 아래의 링크 참고

 

Win32_TerminalServiceSetting class - Win32 apps

Represents the configuration for a Remote Desktop Session Host (RD Session Host) server.

docs.microsoft.com

Comments