달력

42024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

 

 

간단한 통합 매소드

 

 

nicid : 레지스트리의 폴더 주소(즉 index)

newmac : Mac 어드레스 주소(예 : 00 B0 08 A0 C1 1B)

 

newmac 값이 있을땐 설정 null 일땐 초기화

 

 

using System.Management;

 

 public static bool SetMAC(string nicid, string newmac)
        {
            bool ret = false;
            string baseReg = @"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\";

            using (RegistryKey bkey = GetBaseKey())
            using (RegistryKey key = bkey.OpenSubKey(baseReg + nicid))
            {
                if (key != null)
                {
                   
                    RegistryKey rk = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\"+ nicid, RegistryKeyPermissionCheck.ReadWriteSubTree);
                   
                    if (rk != null)
                    {
                        if (newmac != null)
                        {
                            rk.SetValue("NetworkAddress", newmac);
                        }
                        else
                        {
                            rk.DeleteValue("NetworkAddress");
                        }
                       
                        rk.Close();
                    }


                    ManagementObjectSearcher mos = new ManagementObjectSearcher(new SelectQuery("SELECT * FROM Win32_NetworkAdapter WHERE Index = " + nicid));

                    foreach (ManagementObject o in mos.Get().OfType<ManagementObject>())
                    {
                        o.InvokeMethod("Disable", null);
                        o.InvokeMethod("Enable", null);
                        ret = true;
                    }
                }
            }

            return ret;
        }

 

 

 

'Dev Language > C#' 카테고리의 다른 글

외부에서 호스팅업체 MYSQL 접근하기(+ DLL 포함 컴파일)  (0) 2016.10.05
윈도우 플랫폼 체크  (0) 2015.12.31
.NET Decompile (닷텟 디컴파일)  (0) 2015.06.04
엑셀 exprot  (0) 2015.02.24
사운드 플레이,스톱  (0) 2015.02.24
Posted by 타카스 류지
|