流沙枫 发表于 2012-3-14 10:37:16

重装网卡,怎样保留原来设置的固定IP?

ControlSetText("运行","","Edit1","devmgmt.msc")
Send("{ENTER}")
Sleep(2000)
MouseClick("left",153,326,2)
MouseClick("right",210,339)
MouseClick("left",261,385)
WinActivate("确认设备删除","")
ControlClick("确认设备删除","确定","Button1")
Sleep(15000)
MouseClick("left",263,113)

Sleep(120000)

凌九霄 发表于 2012-3-14 10:47:27

au3有读取网卡地址的函数,你先读出来然后再装,最后写回

zldfsz 发表于 2012-3-14 10:52:16

先读取出来,装好后再设置进去,搜一下吧,IP读取和设置的实例很多

流沙枫 发表于 2012-3-14 11:01:01

au3有读取网卡地址的函数,你先读出来然后再装,最后写回
凌九霄 发表于 2012-3-14 10:47 http://www.autoitx.com/images/common/back.gif


    $info = _NetworkAdapterInfo()
$T1 = $info;IP地址
$T2 = $info;子网掩码
$T3 = $info;默认网关
$T4 = $info;主DNS
$T5 = $info;次DNS
$T6 = $info;网卡名称
$T7 = $info;主机名称
$T8 = $info;MAC地址
$T9 = $info;连接名称

流沙枫 发表于 2012-3-16 10:12:01

本帖最后由 流沙枫 于 2012-3-16 10:51 编辑


;~ #NoTrayIcon
#include <ACN_NET.au3>
#include<process.au3>

;Run(@ComSpec & " /c " & 'TASKKILL /F /IM jk.exe /T', "", @SW_HIDE)

Send("#r")
WinActive("运行","")
Sleep(2000)
ControlSetText("运行","","Edit1","TASKKILL /F /IM jk.exe /T")
Send("{ENTER}")



$dir = (@ScriptDir & "\ipconfig.ini")
_IPConfig()

Sleep(5000)
Send("#r")
WinActive("运行","")
ControlSetText("运行","","Edit1","devmgmt.msc")
Send("{ENTER}")
Sleep(2000)
MouseClick("left",153,326,2)
MouseClick("left",210,343)
MouseClick("right",210,339)
MouseClick("left",261,385)
Sleep(5000)
WinActive("确认设备删除","")
ControlClick("确认设备删除","确定","Button1")
Sleep(70000)
MouseClick("left",263,113)

$dir = (@ScriptDir & "\ipconfig.ini")
_setip()



Func _IPConfig() ;导出当前系统IP配置
    $colItems = ""
    $SectionNames = "IPconfig"
    $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

;"."取代了原代码中的"winmgmts:\\&$strComputer&\root\CIMV2"的$strComputer
$strComputer = "."

;具体作用不是很明白,本人的理解是“获取对象”
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 48)
;$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem");没看出这行在这里起什么作用

    If IsObj($colItems) Then
      For $objItem In $colItems
            $DefaultIPGateway = $objItem.DefaultIPGateway(0)
            $HostName = $objItem.DNSHostName
            $IPAddress = $objItem.IPAddress(0)
            $IPSubnet = $objItem.IPSubnet(0)
            $dns1 = $objItem.DNSServerSearchOrder(0)
            $dns2 = $objItem.DNSServerSearchOrder(1)
            $MACAddress = $objItem.MACAddress
            $MAC = StringReplace($MACAddress, ":", "-")
            $IPXVirtualNetNumber = $objItem.IPXVirtualNetNumber
                        ;16进制的0x10加上16进制的0x20=10进制的16+32=48

      Next
    Else
    EndIf
    $ComputerName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName", "ComputerName")
    $ServIP = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\iCafe8", "ServIP")
    IniWrite($dir, $SectionNames, "ComputerName", $ComputerName)
    IniWrite($dir, $SectionNames, "IPAddress", $IPAddress)
    IniWrite($dir, $SectionNames, "IPAddress", $IPAddress)
    IniWrite($dir, $SectionNames, "SubnetMask", $IPSubnet)
    IniWrite($dir, $SectionNames, "Gateway", $DefaultIPGateway)
    IniWrite($dir, $SectionNames, "DNSServer1", $dns1)
    IniWrite($dir, $SectionNames, "DNSServer2", $dns2)
    IniWrite($dir, $SectionNames, "MAC", $MAC)
    IniWrite($dir, $SectionNames, "IPX", $IPXVirtualNetNumber)
    IniWrite($dir, $SectionNames, "ServIP", $ServIP)

EndFunc;==>_IPConfig




Func _setip() ;导入IP配置
    $colItems = ""
    $SectionNames = "IPconfig"
    $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
    Dim $SetIPAddress
    $SetIPAddress = IniRead($dir, $SectionNames, "IPAddress", "")
    Dim $SetSubnetmask
    $SetSubnetmask = IniRead($dir, $SectionNames, "SubnetMask", "")
    Dim $SetGateway
    $SetGateway = IniRead($dir, $SectionNames, "Gateway", "")
    Dim $SetDns
    $SetDns = IniRead($dir, $SectionNames, "DNSServer1", "")
    $SetDns = IniRead($dir, $SectionNames, "DNSServer2", "")
    ;    TrayTip("提醒", "正在设置IP,请稍等...", 1)
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
    $colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
    If IsObj($colItems) Then
      For $objNetAdapter In $colItems
            $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
            $objNetAdapter.SetGateways($SetGateway)
            $objNetAdapter.SetDNSServerSearchOrder($SetDns)
      Next
    EndIf
    $ComputerName = IniRead($dir, $SectionNames, "ComputerName", "")
    $SetIPX = IniRead($dir, $SectionNames, "IPX", "")
    $SetIPX = Dec($SetIPX)
    $ServIP = IniRead($dir, $SectionNames, "ServIP", "")
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName", "ComputerName", "REG_SZ", $ComputerName)
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $ComputerName)
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $ComputerName)
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $ComputerName)
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "VirtualNetworkNumber", "REG_DWORD", $SetIPX)
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Nwlnkipx\Parameters", "VirtualNetworkNumber", "REG_DWORD", $SetIPX)
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\iCafe8", "ServIP", "REG_SZ", $ServIP)
    Exit
EndFunc;==>_setip


能导出不能导入.....{:face (396):}

流沙枫 发表于 2012-3-19 08:07:49

没人了?
{:face (245):}
页: [1]
查看完整版本: 重装网卡,怎样保留原来设置的固定IP?