public static string GetWorkGroupName() { string result = String.Empty; if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX) { //OS X string configFilePath = @"/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist"; PlistParser parser = new PlistParser(configFilePath); result = parser["Workgroup"].ToString(); } else if (OSVersionPlatform.GetGenericPlatform() == PlatformID.Unix) { //Linux string configFilePath = @"/etc/samba/smb.conf"; IniFileParser parser = new IniFileParser(configFilePath); result = parser.GetValue("Global", "Workgroup"); } else { //Windows using (ManagementObject managementObject = new ManagementObject(String.Format("Win32_ComputerSystem.Name='{0}'", Environment.MachineName))) { object workgroup; //Workgroup is NULL under XP if (OSVersionPlatform.IsWindowsVistaOrHigher()) workgroup = managementObject["Workgroup"]; else workgroup = managementObject["Domain"]; result = workgroup.ToString(); } } return result; }
public static string GetWorkGroupName() { string result = String.Empty; if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX) { //OS X string configFilePath = @"/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist"; PlistParser parser = new PlistParser(configFilePath); const string workgroupKey = "Workgroup"; if (parser.ContainsKey(workgroupKey)) { result = parser[workgroupKey].ToString(); } else { const string defaultWorkgroup = "WORKGROUP"; result = defaultWorkgroup; } } else if (OSVersionPlatform.GetGenericPlatform() == PlatformID.Unix) { //Linux string configFilePath = @"/etc/samba/smb.conf"; IniFileParser parser = new IniFileParser(configFilePath); result = parser.GetValue("Global", "Workgroup"); } else { //Windows using (ManagementObject managementObject = new ManagementObject(String.Format("Win32_ComputerSystem.Name='{0}'", Environment.MachineName))) { object workgroup = managementObject["Workgroup"]; //Workgroup is NULL under XP and Server OS //instead read Domain if (workgroup == null) { workgroup = managementObject["Domain"]; const string LocalSuffix = ".local"; if (workgroup != null) { string domain = (string)workgroup; if (domain.EndsWith(LocalSuffix)) { domain = Path.GetFileNameWithoutExtension(domain); } workgroup = domain; } } result = workgroup.ToString(); } } return(result); }
public void PlistParser_ParsesFile() { //arrange string executingPath = Path.GetFullPath("App_Data"); const string fileName = "com.apple.smb.server.plist"; string plistFilePath = Path.Combine(executingPath, fileName); //act PlistParser parser = new PlistParser(plistFilePath); //assert Assert.IsTrue(((string)parser["DOSCodePage"]).Equals("437")); Assert.IsTrue(((string)parser["NetBIOSName"]).Equals("NET-BIOS-NAME")); Assert.IsTrue(((string)parser["Workgroup"]).Equals("WORKGROUP")); }
public void PlistParser_ParsesFile() { //arrange string executingPath = Path.GetFullPath("App_Data"); const string fileName = "com.apple.smb.server.plist"; string plistFilePath = Path.Combine(executingPath, fileName); //act PlistParser parser = new PlistParser(plistFilePath); //assert Assert.IsTrue(((string)parser["DOSCodePage"]).Equals("437")); Assert.IsTrue(((string)parser["NetBIOSName"]).Equals("NET-BIOS-NAME")); Assert.IsTrue(((string)parser["Workgroup"]).Equals("WORKGROUP")); }
public static string GetWorkGroupName() { string result = String.Empty; if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX) { //OS X string configFilePath = @"/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist"; PlistParser parser = new PlistParser(configFilePath); result = parser["Workgroup"].ToString(); } else if (OSVersionPlatform.GetGenericPlatform() == PlatformID.Unix) { //Linux string configFilePath = @"/etc/samba/smb.conf"; IniFileParser parser = new IniFileParser(configFilePath); result = parser.GetValue("Global", "Workgroup"); } else { //Windows using (ManagementObject managementObject = new ManagementObject(String.Format("Win32_ComputerSystem.Name='{0}'", Environment.MachineName))) { object workgroup = managementObject["Workgroup"]; //Workgroup is NULL under XP and Server OS //instead read Domain if (workgroup == null) { workgroup = managementObject["Domain"]; const string LocalSuffix = ".local"; if (workgroup != null) { string domain = (string)workgroup; if (domain.EndsWith(LocalSuffix)) domain = Path.GetFileNameWithoutExtension(domain); workgroup = domain; } } result = workgroup.ToString(); } } return result; }