Jump to content
Sign in to follow this  
xero

Subnet-Maske per vbs-Script ändern

Recommended Posts

Tach auch,

 

hier ein Script von MS. Hat bei mir funktioniert.

 

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

Set colNetAdapters = objWMIService.ExecQuery _

("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

 

strIPAddress = Array("192.168.1.141")

strSubnetMask = Array("255.255.255.0")

strGateway = Array("192.168.1.100")

strGatewayMetric = Array(1)

 

For Each objNetAdapter in colNetAdapters

errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

If errEnable = 0 Then

WScript.Echo "The IP address has been changed."

Else

WScript.Echo "The IP address could not be changed."

End If

Next

 

Gruß

THUMB

Share this post


Link to post

Hallo THUMB,

 

dieses Script ist mir schon bekannt - vielen Dank.

 

Das Script soll die bestehende IP-Adresse weiter übernehmen - ohne manuelle Vorgabe (strIPAddress = Array("192.168.1.141") ).

 

Einzige Eingabe durch das Script: strSubnetMask = Array("255.255.0.0").

 

Gruß

xero

Share this post


Link to post

Tach auch,

 

tja, wie wäre es, diese vorher auszulesen:

 

Set IPConfigSet = GetObject("winmgmts://.").ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each IPConfig In IPConfigSet

If Not IsNull(IPConfig.IPAddress) Then

For i=LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)

IPADDRESS = IPConfig.IPAddress(i)

MsgBox IPADDRESS

Next

End If

Next

 

Gruß

THUMB

Share this post


Link to post

Hallo THUMB,

 

das ist genau mein Problem - sorry. Ich kann beide Scripte nicht miteinander kombinieren :mad: . Nach dem Motto: Lies mir die (alle) IP-Adresse(n) und Subnet-Maske(n) aus. Danach ändere nur die Subnet-Maske(n) ...

# # # Script # # #

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

Set colNetAdapters = objWMIService.ExecQuery _

("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

 

Set IPConfigSet = GetObject("winmgmts://.").ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each IPConfig In IPConfigSet

If Not IsNull(IPConfig.IPAddress) Then

For i=LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)

IPADDRESS = IPConfig.IPAddress(i)

'MsgBox IPADDRESS

'Next

End If

'Next

 

strIPAddress = Array(IPADDRESS)

strSubnetMask = Array("255.255.0.0")

'strGateway = Array("192.168.1.100")

'strGatewayMetric = Array(1)

 

For Each objNetAdapter in colNetAdapters

errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

'errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

If errEnable = 0 Then

WScript.Echo "The IP address has been changed."

Else

WScript.Echo "The IP address could not be changed."

End If

Next

# # # Script-Ende # # #

 

Ergebnis: Fehlerabbruch in Zeile 15 - Anweisung erwartet (Fehler)

 

Gruß

xero

Share this post


Link to post

Hallo xero,

 

hmmm..., ich habe die Scripte ebenfalls zusammengeführt und bei verschiedenen Rechnern getestet, es funktioniert. Hier der verwendete Code:

 

# # # Script # # #

 

Set IPConfigSet = GetObject("winmgmts://.").ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each IPConfig In IPConfigSet

If Not IsNull(IPConfig.IPAddress) Then

For i=LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)

IPADDRESS = IPConfig.IPAddress(i)

 

Next

End If

Next

 

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

Set colNetAdapters = objWMIService.ExecQuery _

("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

 

strIPAddress = Array(IPADDRESS)

strSubnetMask = Array("255.255.255.0")

'strGateway = Array("192.168.1.100")

'strGatewayMetric = Array(1)

 

For Each objNetAdapter in colNetAdapters

errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

If errEnable = 0 Then

WScript.Echo "The IP address has been changed."

Else

WScript.Echo "The IP address could not be changed."

End If

Next

 

# # # Script-Ende # # #

 

Gruß THUMB

Share this post


Link to post

Hallo xero,

 

Du hast bei Deinem Script zweimal NEXT zuviel auskommentiert, das ist die Ursache des Abbruches. Guck, diese Stelle mein´ ich:

 

'MsgBox IPADDRESS

'Next

End If

'Next

 

Wenn Du die beiden NEXT wieder zulässt, geht´s.

 

Gruß

THUMB

Share this post


Link to post
Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte überlege Dir, ob es nicht sinnvoller ist ein neues Thema zu erstellen.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...