[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 840
  • Last Modified:

Batch file to compare ip address with registry key


i have software that puts ip address in registry key such as:


Key has ip address:

I want to compare the 'network' portion of the ip address in this key to a 'static network portion' such as 192.168.1  (/24) for this part i can set variable such as staticnetwork=192.168.1 and if registry contains this string as a positive match then i need to make an action such as install.exe

If the ip address in the key matches the correct network portion, then i need to perform action. and if not then i take separate action.

can you show me how this is accomplished??
1 Solution
Please refine your description of the registry part, because it's not quite clear currently.
Do you have a key (a "folder" in regedit) as in "HKLM\Software\Acme\", with some values in there, or dou you have a key like "HKLM\Software\Acme" with a value "IPAddress" and the data ""?
Could you post a regedit export or a screenshot (with sensitive information removed, of course)?
Brad GrouxCommented:
This should be possible with PowerShell and WMI (Get-WmiObject Win32_NetworkAdapterConfiguration).

The Lonely Administrator has a great write up about how to get IP data using a function - http://jdhitsolutions.com/blog/2011/03/get-ip-data/

You can then use PowerShell's conditional logic to perform the if/then tasks - http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/

Get-ItemProperty Cmdlet looks like to be the right track - http://technet.microsoft.com/en-us/library/ee176852.aspx

To learn more about PowerShell check out Microsoft Virtual Academy's fantastic free courses -
Steve KnightIT ConsultancyCommented:
You can do something like this in batch.... change the key/value to the one you want:


@echo off
SET Key="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SystemInformation"
Set Value="SystemProductName"
for /f "tokens=3" %%a in ('reg query %Key% /v %Value%^| find %value%') do set IPAddress=%%a
echo IP Address found is %ipaddress%

if "%ipaddress:~0,10%"=="192.168.1." (
  ECHO On subnet 192.168.1
  ECHO do something here

REM check any more subnets here etc.

Open in new window

zequestionerAuthor Commented:
I apologize for not being as specific, it is a registry key of type REG_SZ.

Steve, when I put in the key path and set the value to the 'Value Name' of the key and the Value Data is the IP address, the ip does not match the subnet even though it does. I think i figure it out b/c your ip has 10 cahracters and mine has 12 so now i got it to work just fine. thank you for the help.

Brad thank you for your help but steve solution is very easy and straightforward to figure out.

Thank you steve this is exactly what i need and is perfect solution.
Steve KnightIT ConsultancyCommented:
No problem, glad to help.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now