Batch file to compare ip address with registry key

hello,

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

HKLM\Software\Key

Key has ip address: 192.168.1.158

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??
LVL 1
zequestionerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
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\192.168.1.158", with some values in there, or dou you have a key like "HKLM\Software\Acme" with a value "IPAddress" and the data "192.168.1.158"?
Could you post a regedit export or a screenshot (with sensitive information removed, of course)?
0
Brad GrouxSenior Manager (Wintel Engineering)Commented:
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 -
http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start
http://www.microsoftvirtualacademy.com/training-courses/advanced-tools-scripting-with-powershell-3-0-jump-start
0
Steve KnightIT ConsultancyCommented:
You can do something like this in batch.... change the key/value to the one you want:

Steve

@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
  EXIT /B
)

REM check any more subnets here etc.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
0
Steve KnightIT ConsultancyCommented:
No problem, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.