Example #1
0
 public static bool IsServer()
 {
     if (Licensing.GetCurrentCompName() == Licensing.GetServerCompName())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #2
0
        public static bool CheckLicense()
        {
            if (!Licensing.IsServerConnected())
            {
                MessageBox.Show("กรุณาตรวจสอบการเชื่อมต่ออินเทอร์เน็ต");
                return(false);
            }

            SRV_RegisterData srv_regdata = Licensing.GetSrvRegisterData(Licensing.GetLocalRegData());

            if (srv_regdata == null)
            {
                return(false);
            }
            else
            {
                if (Licensing.IsLAN())
                {
                    //MessageBox.Show("Licensing.GetSErverCompName() : " + Licensing.GetServerCompName() + "\nsrv_regdata.comp_name : " + srv_regdata.comp_name);

                    if (Licensing.GetServerCompName() == srv_regdata.comp_name && srv_regdata.reg_type == "LAN")
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    string drive_letter = AppDomain.CurrentDomain.BaseDirectory.Substring(0, 1).ToUpper();
                    if (Licensing.GetHDDSerialNumber(drive_letter) == srv_regdata.machine_code && srv_regdata.reg_type == "LOCAL")
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Example #3
0
        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);
        }