public static bool IsLAN() { if (!File.Exists(@"CL.DLL")) { MessageBox.Show("ค้นหาไฟล์ CL.DLL ไม่พบ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } string unc_path = Licensing.GetUncPath(new FileInfo(@"CL.DLL")); return(unc_path.StartsWith(@"\\")); }
public static string GetServerCompName() { string srv_name = string.Empty; if (!File.Exists(@"CL.DLL")) { return(srv_name); } string unc_path = Licensing.GetUncPath(new FileInfo(@"CL.DLL")); if (Licensing.IsLAN()) { int first_sep = unc_path.IndexOf("\\", 2); //start_path.IndexOf("\\", 2); srv_name = unc_path.Substring(2, first_sep - 2); } else { srv_name = Licensing.GetCurrentCompName(); } return(srv_name.ToLower()); }
public static DriveInformation GetDriveInfo() { //try //{ // StringBuilder volname = new StringBuilder(261); // StringBuilder fsname = new StringBuilder(261); // uint sernum, maxlen; // FileSystemFeature flags; // if (!GetVolumeInformation("c:\\", volname, volname.Capacity, out sernum, out maxlen, out flags, fsname, fsname.Capacity)) // Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); // string volnamestr = volname.ToString(); // string fsnamestr = fsname.ToString(); // Console.WriteLine(" >>>> volnamestr : " + volnamestr); // Console.WriteLine(" >>>> fsnamestr : " + fsnamestr); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} string start_path = AppDomain.CurrentDomain.BaseDirectory; DriveInformation drive = new DriveInformation(); // In case running app from \\comp_name\dir\exe_file.exe if (start_path.StartsWith("\\\\")) { //int first_sep = start_path.IndexOf("\\", 2); drive.isNetworkDrive = true; drive.compName = Licensing.GetServerCompName(); //start_path.Substring(2, first_sep - 2); if (Licensing.IsLAN() && Licensing.IsServer()) { drive.correctMachine = true; drive.hddSerialNumber = Licensing.GetHDDSerialNumber(Licensing.GetLocalDriveLetterFromUnc(Licensing.GetUncPath(new FileInfo(@"CL.DLL")))); } return(drive); } // In case running app from drive(Local, Network) string drive_letter = start_path.Substring(0, 3); DriveInfo[] drives = DriveInfo.GetDrives(); foreach (var drv in drives) { string driveName = drv.Name; // C:\, E:\, etc:\ if (drv.Name == drive_letter) { System.IO.DriveType driveType = drv.DriveType; switch (driveType) { case System.IO.DriveType.CDRom: // CD Rom drive.isCdRomDrive = true; break; case System.IO.DriveType.Fixed: // Local Drive drive.isLocalDrive = true; drive.hddSerialNumber = Licensing.GetHDDSerialNumber(drv.Name.Substring(0, 1)); drive.correctMachine = true; break; case System.IO.DriveType.Network: // Mapped Drive string unc_path = Licensing.GetUncPath(new FileInfo(@"CL.DLL")); drive.isNetworkDrive = true; drive.compName = Licensing.GetServerCompName(); if (Licensing.IsLAN() && Licensing.IsServer()) { drive.correctMachine = true; drive.hddSerialNumber = Licensing.GetHDDSerialNumber(Licensing.GetLocalDriveLetterFromUnc(Licensing.GetUncPath(new FileInfo(@"CL.DLL")))); } else if (Licensing.IsLAN() && !Licensing.IsServer()) { drive.correctMachine = false; drive.hddSerialNumber = (Licensing.GetLocalRegData() != null ? Licensing.GetLocalRegData().machine_code : ""); } //ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2"); //ObjectQuery query = new ObjectQuery("SELECT * From Win32_LogicalDisk Where DeviceID=\"" + drive_letter.Replace("\\", "") + "\""); //ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); //foreach (ManagementObject obj in searcher.Get()) //{ // if (obj["ProviderName"] != null) // { // string path = obj["ProviderName"].ToString(); // int first_sep = path.IndexOf("\\", 2); // drive.compName = path.Substring(2, first_sep - 2); // } //} //drive.isNetworkDrive = true; break; case System.IO.DriveType.NoRootDirectory: drive.isNoRootDirectory = true; break; case System.IO.DriveType.Ram: drive.isRamDrive = true; break; case System.IO.DriveType.Removable: // Usually a USB Drive drive.isRemovableDrive = true; break; case System.IO.DriveType.Unknown: drive.isUnknowDrive = true; break; } } } return(drive); }