Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

setting a static IP with a Batch File/vbs

Featured Replies

Hey guys,

Is it possible to set a static IP on a computer using a Batch File or VB script?

Basically I want to run a script, which will configure the machines IP, Gateway etc, would the batch or vbs edit the registry if so could you show me how?

Also could I retrive this information at a later stage in the same way??

Thanks in advance


Go to this Link and see if any of the scripts there will help you. Look for the Network section on the left side of the page.

Here is a script from there for static IP

strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & 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)
Next

Edited by gunsmokingman

  • Author

Thanks gunsmokingman! this was perfect :D thanks for digging it up for me!

Although I do have one question (A stupid one) for you :blushing:

How can the sql select statement work if I dont have sql installed on the machine, is there a "hidden / OS" sql service running?

Thanks!

You can also do it with the netsh.exe utility.

Thanks gunsmokingman! this was perfect :D thanks for digging it up for me!

Although I do have one question (A stupid one) for you :blushing:

How can the sql select statement work if I dont have sql installed on the machine, is there a "hidden / OS" sql service running?

Thanks!

Not really a full SQL, but a database that is accessed in much the same way.

How awsomely almost timely for me! We were having DSL problems and the ISP was having me switch between DHCP and static IPs (not a lot, but it's easier to run a script than right click/properties a bunch of times etc.).

I will have to remember this for later. Thanks phiban for the question that lead to gunsmokingman's answer!

Hey gun, thanks for the info, can you also add a bit to assign the dns also at the same time in the script?? It would be great for me to force the dns that I want coming out of dhcp. My domain setup gets a different dns from our dhcp server, different than when I statically assign ip's, as we have 2 different ISP's in the building..

Would it be a metter of just adding :

strDNSservers = Array ("192.168.177.200")

and add this :

errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNSServers)

Final Script including dns server entry??

strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & 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)
strDNSservers = Array("192.168.1.2")

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic( _
strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(_
strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(_
strDNSServers)
Next

Seemed to work, but I wanted someone to correct me if I am missing something.. :)

Edited by Stealth111

Is this your fianl code or did you want me to try and write what you wanted. Remeber I have no network to test the script on.

strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & 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)
strDNSservers = Array("192.168.1.2")

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic( _
strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(_
strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(_
strDNSServers)
Next

I guess I will stay with what I came up with, I tested it in 3 different enviornments in 3 different buildings and it seemed to work exactly as I needed it to, but thanks for the offer anyways!! :)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.