Datamation Logo

Configure Static IP Address

November 18, 2004
Datamation content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Want to share a script? Click here to contribute!

Author: Shane Boudreaux – sboudrea [at] tulane [dot] edu

Platform:

Windows

Type:
Windows Script

Description:

If you normally have a static IP address but have to use DHCP at home or in other places, it is quite frustrating to have to go through all of the screens to acomplish this goal.

I’ve written this script, which will change to a static IP address quickly. There are 2 options when you execute the script: 1) assign an address that is hard-coded in the script, OR 2) prompt you for the address, mask, and GW.

If you commonly use the same static address, it’s very easy to simply double-click the script and change your IP to your normal address!

Scroll down to view the script.


Configure Static IP Address


strComputer = "."
strAnswer=msgbox ("Use 192.168.1.141 / 24?" & vbcrlf & vbcrlf & "If not, you''ll be prompted to specify", vbYesNoCancel)

if strAnswer = vbYes then

	Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")
	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

elseif strAnswer = vbNo then

	Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")
	Set colNetAdapters = objWMIService.ExecQuery _
			("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
	strIPAddress = array(inputbox("IP Address"))
			'' Array("192.168.1.141")
	strSubnetMask = array(inputbox("Mask"))
			'' Array("255.255.255.0")
	strGateway = array(inputbox("GW"))
			'' 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


else
	
	msgbox ("Operation Cancelled by User")

end if

Disclaimer: We hope that the information in these pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided “as – is”, without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by me. I shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

  SEE ALL
APPLICATIONS ARTICLES
 

Subscribe to Data Insider

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more.

Datamation Logo

Datamation is the leading industry resource for B2B data professionals and technology buyers. Datamation's focus is on providing insight into the latest trends and innovation in AI, data security, big data, and more, along with in-depth product recommendations and comparisons. More than 1.7M users gain insight and guidance from Datamation every year.

Advertisers

Advertise with TechnologyAdvice on Datamation and our other data and technology-focused platforms.

Advertise with Us

Our Brands


Privacy Policy Terms & Conditions About Contact Advertise California - Do Not Sell My Information

Property of TechnologyAdvice.
© 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.