我运行以下代码:
Dim strComputer As String = "."
Dim objWMIService As Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim colNetAdapters As Object = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration " & "where IPEnabled=TRUE")
Dim ipAdd As String = "83.185.88.205"
Dim ipMask As String = "255.255.255.255"
For Each objNetAdapter In colNetAdapters
If objNetAdapter.Index = 458755 Then
objNetAdapter.EnableStatic(ipAdd, ipMask)
End If
当我跑步时,我开始行:
objNetAdapter.EnableStatic(ipAdd,ipMask)
“类型不匹配”错误代码
任何想法为什么?该接口是由我使用的移动宽带附带的软件建立的PPP接口。
MSDN指定:
uint32 EnableStatic( [in] string IPAddress [], [in] string SubnetMask [] );
[in]表示什么,我相信我必须以某种方式将变量转换为数组?
答案 0 :(得分:0)
尝试将声明更改为:
Dim ipAdd As String() = {"83.185.88.205"}
Dim ipMask As String() = {"255.255.255.255"}
修改强>
了解更多,我找到的每个解决方案都使用System.Management
托管命名空间。看看这段代码:
答案 1 :(得分:0)
我知道这是一个旧线程,但发现了一些问题并重新编写了脚本以执行具有影响的子网掩码更改 我为代码设置了一个变量来保存ip地址,网关等... 希望这有帮助
' Script name: Subnet Mask Adjuster
' Date: April 2014
'
' VBscript that will change the subnet mask
' Description
' Changing the subnet mask on a list of computers and logging the success per machine
' Script Requirements
' Script needs to record the current IP, Gateway, Gateway metric prior to changing the subnet mask
' When changing the subnet mask the script will once again reinstall the gathered information
' to ensure that the system is still addressable
'
' Access reqquirements
' Admin level access across all computers being targeted
'
' Script needs to be invoked as cscript.exe
' example: Cscript.exe CSNMIPBLOC.vbs "xx.xx.xx.xx"
' where the xx.xx.xx.xx is the ip address of the subnet
' global variables declaration
' --- Strings ---
Dim strCurrentDirectory, strDateTime, strInputFile
Dim strGateway, strGatewayMetric
Dim strSubnetMask
' --- File system objects ---
Dim objFSO, objLog, objTextFile
' --- Shell Objects ---
Dim objWSH
' --- File System Contants ---
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
' Create an instance of the file System object and shell object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSH = CreateObject("Wscript.Shell")
' Get the path of the script
strCurrentDirectory = objWSH.CurrentDirectory
' retrieve the time for the log file name
strDatetime = funcGetDatetime
' Get the path to the input file
strInputFile = strCurrentDirectory & "\Servers.txt"
' Create the log file
Set objLog = objFSO.CreateTextFile(strCurrentDirectory & "\SubnetChanger_" & strDateTime & ".log", ForWriting)
' Write the entry into the log file
subRprtProg "Subnet Mask Adjuster Script"
subRprtProg "Date/Time: " & strDateTime
subRprtProg "-------------------------------"
' Open the input file
Set objTextFile = objFSO.OpenTextFile(strInputFile, ForReading)
subRprtProg "Opening input file " & strInputFile
subRprtProg "----------------------------------------------------"
' Read the contents of the file one line at a time and perform the function
Do Until objTextFile.AtEndOfStream
' Read a line form the file and remove the spaces from the beginning and end
strComputer = Trim(objTextFile.ReadLine)
subRprtProg " "
subRprtProg "Connecting to computer " & strComputer
subRprtProg " "
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' Enable Error Handling
'On Error Resume Next
' Get the list on Network adapters from the Computer
subRprtProg "Retrieving the Network adapters"
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strSubnetMask = Array("255.255.255.192")
strSNMDisplay = strSubnetMask(i)
subRprtProg "SubnetMask is: " & strSNMDisplay
' Go through the configured adaptors and nics
For Each objNetAdapter In colNetAdapters
If Not IsNull (objNetAdapter.IPAddress) Then
strIPAddress = objNetAdapter.IPAddress(i)
objIPaddress = objNetAdapter.IPAddress
subRprtProg "Current IP Address is: " & strIPAddress
strGateway = objNetAdapter.DefaultIPGateway(i)
objDefIPGW = objNetAdapter.DefaultIPGateway
subRprtProg "Current Default IP Gateway: " & strGateway
strGatewayMetric = objNetAdapter.GateWayCostMetric(i)
objGWMetric = objNetAdapter.GateWayCostMetric
subRprtProg "Current Gateway Metric: " & strGatewayMetric
' Setting the subnet and resetting IP, Gateway and GatewayMetric
errEnable = objNetAdapter.EnableStatic(objIPaddress, strSubnetMask)
subRprtProg "Setting IP Address to: " & strIPaddress
subRprtProg "Setting Subnetmask to: " & strSNMDisplay
errGateways = objNetAdapter.SetGateways(objDefIPGW, objGWMetric)
subRprtProg "Setting IPGateway to: " & strGateway
subRprtProg "Setting GateWay Metric to: " & strGatewaymetric
Select Case errEnable
Case 0
subRprtProg "Successful completion, no reboot required."
Case 1
subRprtProg "Successful completion, reboot required."
Case 64
subRprtProg "Method not supported on this platform."
Case 65
subRprtProg "Unknown failure."
Case 66
subRprtProg "Invalid subnet mask."
Case 67
subRprtProg "An error occurred while processing an instance that was returned."
Case 68
subRprtProg "Invalid input parameter."
Case 69
subRprtProg "More than five gateways specified."
Case 70
subRprtProg "Invalid IP address."
Case 71
subRprtProg "Invalid gateway IP address."
Case 72
subRprtProg "An error occurred while accessing the registry for the requested information."
Case 73
subRprtProg "Invalid domain name."
Case 74
subRprtProg "Invalid host name."
Case 75
subRprtProg "No primary or secondary WINS server defined."
Case 76
subRprtProg "Invalid file."
Case 77
subRprtProg "Invalid system path."
Case 78
subRprtProg "File copy failed."
Case 79
subRprtProg "Invalid security parameter."
Case 80
subRprtProg "Unable to configure TCP/IP service."
Case 81
subRprtProg "Unable to configure DHCP service."
Case 82
subRprtProg "Unable to renew DHCP lease."
Case 83
subRprtProg "Unable to release DHCP lease."
Case 84
subRprtProg "IP not enabled on adapter."
Case 85**************************** script *******************************
subRprtProg "IPX not enabled on adapter."
Case 86
subRprtProg "Frame or network number bounds error."
Case 87
subRprtProg "Invalid frame type."
Case 88
subRprtProg "Invalid network number."
Case 89
subRprtProg "Duplicate network number."
Case 90
subRprtProg "Parameter out of bounds."
Case 91
subRprtProg "Access denied."
Case 92
subRprtProg "Out of memory."
Case 93
subRprtProg "Already exists."
Case 94
subRprtProg "Path, file, or object not found."
Case 95
subRprtProg "Unable to notify service."
Case 96
subRprtProg "Unable to notify DNS service."
Case 97
subRprtProg "Interface not configurable."
Case 98
subRprtProg "Not all DHCP leases could be released or renewed."
Case 100
subRprtProg "DHCP not enabled on adapter."
End Select
Else
subRprtProg "No IP address detected on Adapter"
End If
Next
subRprtProg "Completed for computer " & strComputer
subRprtProg "Moving to next computer"
subRprtProg "----------------------------------------------------------------"
' Close Error Handling
'On Error Goto 0
Loop
subRprtProg "Script completed at: " & Now()
subRprtProg "Script will now exit, see log files for details"
WScript.Quit
' Function to return the date and time in file name friendly format
' -----------------------------------------------------------------
Function funcGetDateTime
' Variable Declaration
' --- Integers ---
Dim intYear, intMonth, intDay, intHour, intMin, intSec
' --- Strings ---
Dim strFileName
' Get the date
intYear = Year(Now())
intMonth = Month(Now())
intDay = Day(Now())
' Get the time
intHour = Hour(Now()): If intHour < 10 Then intHour = "0" & intHour
intMin = Minute(Now()): If intMin < 10 Then intMin = "0" & intMin
intSec = Second(Now()): If intSec < 10 Then intSec = "0" & intSec
' Build the filename
strFileName = intYear & intMonth & intDay & "_" & intHour & intMin & intSec
' Return the filename
funcGetDateTime = strFileName
End Function
' SubRouotine to display in a cscript a message and
' simultaneously write into the log file
' ---------------------------------------------------
Sub subRprtProg(strMessage)
WScript.Echo strMessage
objLog.WriteLine strMessage
End Sub