コード例 #1
1
ファイル: Cleaner.cs プロジェクト: rebootd/csinctools
        public bool CleanDirectory(DirectoryInfo dirInfo, string[] folderNames)
        {
            //get list of directories
            DirectoryInfo[] dirs = dirInfo.GetDirectories();

            //loop each
            foreach (DirectoryInfo dir in dirs)
            {
                bool istarget = false;
                foreach (string fname in folderNames)
                {
                    istarget = (dir.Name == fname);
                    if (istarget) break;
                }

                if (istarget)
                {
                    //dir.Attributes = FileAttributes.Normal;
                    //Directory.Delete(dir.FullName, true);
                    using (ManagementObject mo = new ManagementObject(String.Format("win32_Directory.Name='{0}'", dir.FullName)))
                    {
                        mo.Get();
                        ManagementBaseObject outParams = mo.InvokeMethod("Delete", null, null);
                        if (Convert.ToInt32(outParams.Properties["ReturnValue"].Value) != 0) return false;
                    }
                }
                else if (!CleanDirectory(dir, folderNames))
                    return false;
            }

            return true;
        }
コード例 #2
1
		public void readHDD_ID()
        {
            string drive = Path.GetPathRoot(Environment.SystemDirectory); //"C";
            drive = drive.Substring(0, 1);
            ManagementObject dsk = new ManagementObject(
                @"win32_logicaldisk.deviceid=""" + drive + @":""");
            dsk.Get();
            string volumeSerial = dsk["VolumeSerialNumber"].ToString();

            HDD_ID = volumeSerial;
        }
コード例 #3
0
ファイル: Securebox.cs プロジェクト: kaizenx/securebox
        private static String GetUniqueSystemIdentifier()
        {
            var search = new ManagementObjectSearcher("SELECT * FROM Win32_baseboard");
            var mobos = search.Get();
            var motherboardSerial ="";
            foreach (var m in mobos)
            {
                motherboardSerial = m["SerialNumber"].ToString(); // ProcessorID if you use Win32_CPU
            }
            String path = Path.GetPathRoot(Environment.SystemDirectory);
            String drive = path.Split(':')[0];
            ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
            dsk.Get();
            string volumeSerial = dsk["VolumeSerialNumber"].ToString();
           
            string cpuInfo = string.Empty;
            ManagementClass mc = new ManagementClass("win32_processor");
            ManagementObjectCollection moc = mc.GetInstances();

            foreach (ManagementObject mo in moc)
            {
                if (cpuInfo == "")
                {
                    //Get only the first CPU's ID
                    cpuInfo = mo.Properties["processorID"].Value.ToString();
                    break;
                }
            }

            return cpuInfo + motherboardSerial + volumeSerial;
        }
コード例 #4
0
        internal static string GetHwid()
        {
            string drive = string.Empty;

            foreach (System.IO.DriveInfo compDrive in System.IO.DriveInfo.GetDrives())
            {
                if (compDrive.IsReady)
                {
                    drive = compDrive.RootDirectory.ToString();
                    break;
                }
            }
            drive = drive.EndsWith(":\\") ? drive.Substring(0, drive.Length - 2) : drive;

            string volumeSerial = string.Empty;

            System.Management.ManagementObject disk = new System.Management.ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
            disk.Get();

            volumeSerial = disk["VolumeSerialNumber"].ToString();
            disk.Dispose();

            string a = Environment.OSVersion.Version.ToString();
            string b = volumeSerial;
            string c = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString();

            return(a + b + c);
        }
        public string SetHostname(string hostname)
        {
            var oldName = Environment.MachineName;
            _logger.Log("Old host name: " + oldName);
            _logger.Log("New host name: " + hostname);
            if (string.IsNullOrEmpty(hostname) || oldName.Equals(hostname, StringComparison.InvariantCultureIgnoreCase))
                return 0.ToString();

            using (var cs = new ManagementObject(@"Win32_Computersystem.Name='" + oldName + "'"))
            {
                cs.Get();
                var inParams = cs.GetMethodParameters("Rename");
                inParams.SetPropertyValue("Name", hostname);
                var methodOptions = new InvokeMethodOptions(null, TimeSpan.MaxValue);
                var outParams = cs.InvokeMethod("Rename", inParams, methodOptions);
                if (outParams == null)
                    return 1.ToString();

                var renameResult = Convert.ToString(outParams.Properties["ReturnValue"].Value);
                //Restart in 10 secs because we want finish current execution and write response back to Xenstore.
                if ("0".Equals(renameResult))
                    Process.Start(@"shutdown.exe", @"/r /t 10 /f /d p:2:4");
                return renameResult;
            }
        }
コード例 #6
0
 //获取硬盘卷标号
 public static string GetDiskVolumeSerialNumber()
 {
     ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");
     ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
     disk.Get();
     return disk.GetPropertyValue("VolumeSerialNumber").ToString();
 }
コード例 #7
0
        void VolumeManager_NewSession(VolumeSession rpSession)
        {
            var rHostProcessID = Process.GetCurrentProcess().Id;
            int? rProcessID = rpSession.ProcessID;

            var rIsBrowserProcess = false;

            while (rProcessID.HasValue)
                using (var rManagementObject = new ManagementObject($"Win32_Process.Handle='{rProcessID.Value}'"))
                    try
                    {
                        rManagementObject.Get();
                        rProcessID = Convert.ToInt32(rManagementObject["ParentProcessId"]);

                        if (rProcessID == rHostProcessID)
                        {
                            rIsBrowserProcess = true;
                            break;
                        }
                    }
                    catch (ManagementException e) when (e.ErrorCode == ManagementStatus.NotFound)
                    {
                        rProcessID = null;
                    }

            if (!rIsBrowserProcess)
                return;

            Volume?.Dispose();
            Volume = new BrowserVolume(rpSession);

            VolumeManager.Instance.NewSession -= VolumeManager_NewSession;
        }
コード例 #8
0
 public static string GetVolumeSerial(string strDriveLetter)
 {
     if (strDriveLetter == "" || strDriveLetter == null) strDriveLetter = "C";
       ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter + ":\"");
       disk.Get();
       return disk["VolumeSerialNumber"].ToString();
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: aifos29/Requerimientos
        static void Main()
        {
            DirectoryInfo currentDir = new DirectoryInfo(Environment.CurrentDirectory);
            string path = string.Format("win32_logicaldisk.deviceid=\"{0}\"",
                currentDir.Root.Name.Replace("\\", ""));
            ManagementObject disk = new ManagementObject(path);
            disk.Get();

            String serial = disk["VolumeSerialNumber"].ToString();
            Conexion_MSS conexion = new Conexion_MSS("null", "null", "Requerimientos", 0);
            conexion.conexion.Open();
            conexion.cmd = new System.Data.SqlClient.SqlCommand("Select usuario from Cuentas where ID='" + serial + "'", conexion.conexion);
            conexion.reader = conexion.cmd.ExecuteReader();
            List<String> cuentas = new List<string>();
            while (conexion.reader.Read())
            {
                cuentas.Add(conexion.reader[0].ToString());
            }
            conexion.reader.Close();
            conexion.conexion.Close();

            if (cuentas.Count() > 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Cuentas(serial,cuentas));

            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Login(serial));
            }
        }
コード例 #10
0
ファイル: LicenseService.cs プロジェクト: ddksaku/rzr
 protected string GetHDInfo()
 {
     string drive = "C";
     ManagementObject dsk = new ManagementObject(
         @"win32_logicaldisk.deviceid=""" + drive + @":""");
     dsk.Get();
     return dsk["VolumeSerialNumber"].ToString();
 }
コード例 #11
0
 //取得disk大小
 public static UInt64 DiskSize(string path, string propertys)
 {
     ManagementObject size = new ManagementObject("win32_logicaldisk.deviceid=" + path);
     size.Get();
     UInt64 b = 1024;
     UInt64 a = (Convert.ToUInt64(size[propertys]) / b) / b;
     return a;
 }
コード例 #12
0
ファイル: GetCpuId.cs プロジェクト: mootoomeepo/mootoo.meepo
        public static string GetId()
        {
            ManagementObject dsk = new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");
            dsk.Get();

            string a = dsk["VolumeSerialNumber"].ToString();

            return "_" + Md5Encrypt("+meepo"+a+"mootoo") + "_";
        }
コード例 #13
0
 public PerformanceCounters()
 {
     InitializeComponent();
     mObject = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
     mObject.Get();
     cpuCounter = new PerformanceCounter("Processor Information", "% Processor Time");
     performanceCounterChart.MarqueeAnimationSpeed = 1;
     Style = ProgressBarStyle.Blocks;
     ScaleMode = SpPerfChart.ScaleMode.Absolute;
 }
コード例 #14
0
ファイル: ProcessManager.cs プロジェクト: virajs/monoscape
 private static int GetParentProcess(int Id)
 {
     int parentPid = 0;
     using (ManagementObject mo = new ManagementObject("win32_process.handle='" + Id.ToString() + "'"))
     {
         mo.Get();
         parentPid = Convert.ToInt32(mo["ParentProcessId"]);
     }
     return parentPid;
 }
コード例 #15
0
ファイル: Main.cs プロジェクト: BjkGkh/Azure2
        private string getVolumeSerial(string drive)
        {
            ManagementObject disk = new ManagementObject(string.Format("{0}{1}{2}", @"win32_logicaldisk.deviceid=""", drive, @":"""));
            disk.Get();

            string volumeSerial = disk["VolumeSerialNumber"].ToString();
            disk.Dispose();

            return volumeSerial;
        }
コード例 #16
0
ファイル: EnterLicense.cs プロジェクト: Maginx/MallProject
 private void EnterLicense_Load(object sender, EventArgs e)
 {
     ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
     ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
     disk.Get();
     string temp = Des.EncryptDES(disk.GetPropertyValue("VolumeSerialNumber").ToString(), Des.ConstKey);
     tempStr = Des.EncryptDES(Des.EncryptDES(disk.GetPropertyValue("VolumeSerialNumber").ToString(), Des.ConstKey), Des.ConstKey);
     this.txtOnlyMsg.Text = temp.Trim();
     this.txtLicense.Text = DealXml.ReadSysConfig("appSettings", "license");
 }
コード例 #17
0
ファイル: HardwareKey.cs プロジェクト: afrog33k/eAd
 public string GetVolumeSerial(string strDriveLetter)
 {
     if ((strDriveLetter == "") || (strDriveLetter == null))
     {
         strDriveLetter = "C";
     }
     ManagementObject obj2 = new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter + ":\"");
     obj2.Get();
     return obj2["VolumeSerialNumber"].ToString();
 }
コード例 #18
0
ファイル: HWID.cs プロジェクト: ChrisPea/TuningSuites
        private string getVolumeSerial(string drive)
        {
            ManagementObject disk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
            disk.Get();

            string volumeSerial = disk["VolumeSerialNumber"].ToString();
            disk.Dispose();

            return volumeSerial;
        }
コード例 #19
0
ファイル: Class1.cs プロジェクト: khaha2210/CodeNewTeam
 /// <summary>
 ///           ''' return Volume Serial Number from hard drive
 ///           ''' </summary>
 /// <param name="strDriveLetter">[optional] Drive letter</param>
 /// <returns>[string] VolumeSerialNumber</returns>
 public static string GetVolumeSerial(string strDriveLetter)
 {
     if (Operators.CompareString(strDriveLetter, "", false) == 0 || strDriveLetter == null)
     {
         strDriveLetter = "C";
     }
     ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter + ":\"");
     disk.Get();
     return disk["VolumeSerialNumber"].ToString();
 }
コード例 #20
0
ファイル: Utils.cs プロジェクト: smosgin/labofthings
        /// <summary>
        /// Returns the HDD volume of c:
        /// </summary>
        /// <returns></returns>
        private static string CVolumeSerial()
        {
            var disk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");
            disk.Get();

            string volumeSerial = disk["VolumeSerialNumber"].ToString();
            disk.Dispose();

            return volumeSerial;
        }
コード例 #21
0
        /// <summary>
        /// 取得设备硬盘的卷标号
        /// </summary>
        /// <returns></returns>
        private string GetDiskVolumeSerialNumber() {
            try {
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
                disk.Get();
                return disk.GetPropertyValue("VolumeSerialNumber").ToString();
            } catch {
                return "unknow";
            } finally {

            }
        }
コード例 #22
0
ファイル: HardwareKey.cs プロジェクト: afrog33k/eAd
    /// <summary>
    /// return Volume Serial Number from hard drive
    /// </summary>
    /// <param name="strDriveLetter">[optional] Drive letter</param>
    /// <returns>[string] VolumeSerialNumber</returns>
    public string GetVolumeSerial(string strDriveLetter)
    {
        System.Diagnostics.Debug.WriteLine("[IN]", "GetVolumeSerial");

        if (strDriveLetter == "" || strDriveLetter == null) strDriveLetter = "C";
        ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter + ":\"");
        disk.Get();

        System.Diagnostics.Debug.WriteLine("[OUT]", "GetVolumeSerial");

        return disk["VolumeSerialNumber"].ToString();
    }
コード例 #23
0
        public static string GetHddSerialNumber(string drive)
        {
            if (string.IsNullOrEmpty(drive))
            {
                drive = "C";
            }

            ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");
            //bind our management object
            disk.Get();
            //return the serial number
            return disk["VolumeSerialNumber"].ToString();
        }
コード例 #24
0
ファイル: AntiDebug.cs プロジェクト: AtVirus/DarkAgent
        public static bool CheckParentProcess()
        {
            if(!Settings.SystemProcess_CheckParentProcess)
                return true;

            using (ManagementObject mo = new ManagementObject("win32_process.handle='" + Process.GetCurrentProcess().Id.ToString() + "'"))
            {
                mo.Get();
                if (Process.GetProcessById(Convert.ToInt32(mo["ParentProcessId"])).ProcessName.ToLower() != "explorer")
                    return false;
                return true;
            }
        }
コード例 #25
0
ファイル: HardwareInfo.cs プロジェクト: GorelH/QLicense
 /// <summary>
 /// Get volume serial number of drive C
 /// </summary>
 /// <returns></returns>
 private static string GetDiskVolumeSerialNumber()
 {
     try
     {
         ManagementObject _disk = new ManagementObject(@"Win32_LogicalDisk.deviceid=""c:""");
         _disk.Get();
         return _disk["VolumeSerialNumber"].ToString();
     }
     catch
     {
         return string.Empty;
     }
 }
コード例 #26
0
ファイル: AdeptMasterKeys.cs プロジェクト: 13xforever/DeDRM
 private static CpuInfo GetCpuInfo()
 {
     var result = new CpuInfo();
     string sig;
     using (var cpu = new ManagementObject(@"Win32_Processor.DeviceID=""CPU0"""))
     {
         cpu.Get();
         result.vendor = cpu["Manufacturer"].ToString();
         sig = cpu["ProcessorId"].ToString();
     }
     for (byte i = 0; i < 3; i++) result.familyModelStepping[i] = Convert.ToByte(sig.Substring(10 + i * 2, 2), 16);
     return result;
 }
コード例 #27
0
ファイル: SysInfo.cs プロジェクト: huanlin/YetAnotherLibrary
 /// <summary>
 /// 取得本機的網域或工作群組名稱。
 /// </summary>
 /// <returns></returns>
 public static string GetDnsName()
 {
     string result = "";
     string qry = "Win32_ComputerSystem.Name='" + System.Environment.MachineName + "'";
     ManagementObject cs;
     using (cs = new ManagementObject(qry))
     {
         cs.Get();
         if (cs["domain"] != null)
         {
             result = cs["domain"].ToString();
         }
     }
     return result;
 }
コード例 #28
0
 private static int GetParentProcessId(Process p)
 {
     int parentId = 0;
     try
     {
         ManagementObject mo = new ManagementObject("win32_process.handle='" + p.Id + "'");
         mo.Get();
         parentId = Convert.ToInt32(mo["ParentProcessId"]);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         parentId = 0;
     }
     return parentId;
 }
コード例 #29
0
ファイル: SecureLib.cs プロジェクト: AndrewEastwood/desktop
 /// <summary>
 /// method to retrieve the selected HDD's serial number
 /// </summary>
 /// <param name="strDriveLetter">Drive letter to retrieve serial number for</param>
 /// <returns>the HDD's serial number</returns>
 public static string GetHDDSerialNumber(string drive)
 {
     //check to see if the user provided a drive letter
     //if not default it to "C"
     if (drive == "" || drive == null)
     {
         drive = "C";
     }
     //create our ManagementObject, passing it the drive letter to the
     //DevideID using WQL
     ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");
     //bind our management object
     disk.Get();
     //return the serial number
     return disk["VolumeSerialNumber"].ToString();
 }
コード例 #30
0
ファイル: Class1.cs プロジェクト: NguyenManh94/CrawlerDataNP
 /// <summary>
 /// method to retrieve the HDD's size
 /// </summary>
 /// <param name="drive">Drive letter to get free space from (optional)</param>
 /// <returns>The free space of the selected HDD</returns>
 public double getHDDSize(string drive)
 {
     //check to see if the user provided a drive letter
     //if not default it to "C"
     if (drive == "" || drive == null)
     {
         drive = "C";
     }
     //create our ManagementObject, passing it the drive letter to the
     //DevideID using WQL
     ManagementObject disk = new ManagementObject("Win32_LogicalDisk.DeviceID=\"" + drive + ":\"");
     //bind our management object
     disk.Get();
     //return the HDD's initial size
     return Convert.ToDouble(disk["Size"]);
 }
コード例 #31
0
 private static void KillChild(int parentId, string processName)
 {
     foreach (var process in Process.GetProcessesByName(processName))
     {
         try
         {
             var mo = new ManagementObject("win32_process.handle='" + process.Id + "'");
             mo.Get();
             if (parentId == Convert.ToInt32(mo["ParentProcessId"]))
                 process.Kill();
         }
     // ReSharper disable once EmptyGeneralCatchClause
         catch
         {
         }
     }
 }