Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

800A000D - Type mismatch in Select 1

Status
Not open for further replies.

slint

Technical User
Jul 2, 2006
48
SE
I found markdmac's logonscript faq that retrives dhcp address and do some things with it. Now i'm trying to do the same but with static address. I get an error in select row. Select Case Left (ActiveIPAddress, 10)

Error: 800A000D - Type mismatch
Source: Microsoft VBScript runtime error.

pls help..


Code:
OPTION EXPLICIT
Dim oReg
Dim WSHShell
Dim strKeyPath
Dim arrSubKeys
Dim subkey
Dim IPAddr
Dim ActiveIPAddress

'On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")

Set WSHShell = wscript.CreateObject("Wscript.Shell")
strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys

    IPAddr = WSHShell.RegRead("HKLM\" & strKeyPath & subkey & "\IPAddress")

        ActiveIPAddress = IPAddr    
  
Next

Select Case Left (ActiveIPAddress, 10)
    Case "192.168.1."
        msgbox "Your subnet is 192.168.1.x"	
    Case "192.168.2."
        msgbox "Your subnet is 192.168.2.x"
    Case "192.168.3."
        msgbox "Your subnet is 192.168.3.x"
End Select
 
One more thing, is there a way to check both dhcp and static address. First check dhcp address and if it dont get the ip then try look for static.
 
Slint,

In copying and modifying my sample script you have removed an important part:
Code:
If DHCPAddress <> "0.0.0.0" And Left(DHCPAddress,3) <> "169" Then
        ActiveDHCPIPAddress = DHCPAddress    
End If

There will undoubtably be more than one registry key to enumerate and if you check your registry I am sure you will find interfaces with the IPAddress key you are searching, and you will find entries that are blank or 0.0.0.0. So you will want to check for that and strip out such entries to find the real IP, otherwise the last interface is set as the IPAddress.

The reason however that you are getting the Type mismatch is that the IPAddress field in the registry is of type Reg_Multi_Sz where the DHCP address is stored as Reg_Sz.
A Reg_Multi_Sz is returned as an array and you will therefore need to treat it as such.

Note that there is no way for the script to decide if there is more than one NIC which one to report so please be advised that I really don't like this as a scritpign solution. In fact, other than servers (and maybe some very rare extreme circumstances) I contend that you should NEVER use static IP addresses. Use DHCP Reservations instead!

Anyway, here is sample code that checks for a static IP address.

Code:
strComputer = "."
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")

Set WSHShell = wscript.CreateObject("Wscript.Shell")
strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

    
For Each subkey In arrSubKeys
    IPAddr = WSHShell.RegRead("HKLM\" & strKeyPath & subkey & "\IPAddress")
	For Each octetSTR In IPAddr
		If octetSTR <> "0.0.0.0" Then
			StaticIP = octetSTR
		End If
	Next
Next
WScript.Echo StaticIP




I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
thnx markdmac.

I'm on the run again...

 
Important to note that if a NIC was configred with multiple IPs, then the last one enumerated is going to win with the Static IP code I posted above.

I've provided this for educationl purposes and do not recommend using this method in production as results may be too unpredictable.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top