找回密码
 加入
搜索
查看: 3317|回复: 6

[系统综合] 重装网卡,怎样保留原来设置的固定IP?

  [复制链接]
发表于 2012-3-14 10:37:16 | 显示全部楼层 |阅读模式
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有读取网卡地址的函数,你先读出来然后再装,最后写回
发表于 2012-3-14 10:52:16 | 显示全部楼层
先读取出来,装好后再设置进去,搜一下吧,IP读取和设置的实例很多
 楼主| 发表于 2012-3-14 11:01:01 | 显示全部楼层
au3有读取网卡地址的函数,你先读出来然后再装,最后写回
凌九霄 发表于 2012-3-14 10:47



    $info = _NetworkAdapterInfo()
$T1 = $info[1][4];IP地址
$T2 = $info[1][7];子网掩码
$T3 = $info[1][2];默认网关
$T4 = $info[1][5];主DNS
$T5 = $info[1][6];次DNS
$T6 = $info[1][1];网卡名称
$T7 = $info[1][3];主机名称
$T8 = $info[1][8];MAC地址
$T9 = $info[1][9];连接名称

 楼主| 发表于 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[1]
    $SetIPAddress[0] = IniRead($dir, $SectionNames, "IPAddress", "")
    Dim $SetSubnetmask[1]
    $SetSubnetmask[0] = IniRead($dir, $SectionNames, "SubnetMask", "")
    Dim $SetGateway[1]
    $SetGateway[0] = IniRead($dir, $SectionNames, "Gateway", "")
    Dim $SetDns[2]
    $SetDns[0] = IniRead($dir, $SectionNames, "DNSServer1", "")
    $SetDns[1] = 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
能导出不能导入.....
 楼主| 发表于 2012-3-19 08:07:49 | 显示全部楼层
没人了?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-23 09:22 , Processed in 0.088264 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表