Jump to content

batch file that check version in registry


Recommended Posts

Initially to fix the supplied script, try this:

@Echo off&Setlocal
Set "kb_=HKLM\SOFTWARE\Adobe\Acrobat Reader"
Set "ke_=Installer\{AC76BA86-7AD7-"
Set "uk_=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
For /f "tokens=2 delims={" %%# In (
'Reg query "%kb_%" /s^|find "%ke_%" 2^>Nul') Do Call :_ {%%#
Endlocal&Goto :Eof
:_
Set "t_=%uk_%\%1"
Reg query %t_% /v DisplayVersion|Findstr "7.0.9 7.1.0">Nul 2>&1||(Set "t_="
Goto :Eof)
For /f "tokens=3 delims= " %%# In (
'Reg query %t_% /v UninstallString^|Find "REG_"') Do Start "" /wait %%#

Link to comment
Share on other sites


Yes it fixed the issue. Thank you!

So I've looked around for string manipulation in batch files but the results came up pretty dry. Any idea on how to change the UninstallString from "MsiExec.exe /I{AC76BA86-7AD7-1033-7B44-A71000000002}" to "MsiExec.exe /x {AC76BA86-7AD7-1033-7B44-A71000000002} -qb"?

Cheers!

Link to comment
Share on other sites

Instead of using the 'For loop' at the bottom of the script, change it to just something like this:
Start "" /wait MsiExec.exe /x %1 /qb

Well I feel a bit dumb :rolleyes:

You are great help. Thanks again! :thumbup

Link to comment
Share on other sites

  • 2 months later...

Hi Yzowl, sorry to bring a post that was practically dead back to life but i was wondering if you would be able to help me.

Iv been working on a batch file to try and automate the new XP SP3 upgrade, amongst other things. I have found your code and have been trying to alter it to find the IE version. I have had no luck so far and was wondering if you could have a look at it and let me know what I was doing wrong.

Thanks in advance for any and all help (not just from Yzowl of course)

Here is what I have done so far....

Setlocal
Set "key=HKLM\SOFTWARE\Microsoft\Internet Explorer\Version Vector"
For /f "tokens=3 delims= " %# In (
'Reg query %key% /v IE ^|Find "7.0000" 2^>Nul') Do Set "rel=%#"
If Not [%rel%]==[7.0000] Start ""/w IE7\IE7-WindowsXP-x86-enu.exe

Just a bit of background, im using a USB pen to try to make the installation as easy as possible which is why the .exe is where it is..

If you need any more information about it please dont hesitate to ask..

Thanks

Paul

Link to comment
Share on other sites

@pmuir, something like this should do you!

@Echo off&Setlocal
Set k_="HKLM\SOFTWARE\Microsoft\Internet Explorer"
For /f "skip=3 tokens=3 delims= ." %%# In ('Reg query %k_% /v Version') Do Set v_=%%#
If %v_% Lss 7 Start "" /w IE7\IE7-WindowsXP-x86-enu.exe

where delims=<TAB><DOT>

Link to comment
Share on other sites

Apart the as always good solution by Yzöwl, a general advice is:

Do it in steps.

First thing read this:

http://www.robvanderwoude.com/ntfortokens.html

Then simply run:

Reg query "HKLM\SOFTWARE\Microsoft\Internet Explorer\Version Vector"

Then try with something like:

SET KEY="HKLM\SOFTWARE\Microsoft\Internet Explorer\Version Vector"
FOR /F "tokens=1,2,3 delims= " %%A in ('Reg query %KEY%' ) DO (
ECHO %%A
ECHO %%B
ECHO %%C
)

Then try with:

FOR /F "tokens=1,2,3 delims=	" %%A in ('Reg query %KEY%^|FIND "IE"' ) DO (
ECHO %%C
)

...and then refine it a bit more, adding the check, etc.....

(Usually I prefer to use the FIND for the line instead of the skip, but it is just a matter of tastes in this case)

jaclaz

Link to comment
Share on other sites

  • 5 weeks later...

I am trying to do a similar thing, but my Reg Query output starts off with 4 spaces and also has a delimiter of 4 spaces, as shown below. Any idea how I can get this to work?

Input is:

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1" /v DisplayVersion

Output is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1

DisplayVersion REG_SZ 3.1.3

I tried these lines in the batch file, but it did not work:

For /f "tokens=3 delims= " %%# In (

'Reg query "%key%" /v DisplayVersion^|Find "REG_" 2^>Nul') Do Set "rel=%%#"

If [%rel%]==[3.1.3] echo version 3.1.3 is installed

Thanks in advance for anyone's assistance.

Link to comment
Share on other sites

@ luppybob

First thing to note is that if your output contains spaces instead of tabs, (which it generally does in Vista), but none of your tokens do, then use both space and tab as your delimiters i.e. delims=<tab><space>

You may however be over-complicating your approach, since you are looking for a specific version number why not use that as your Find and ignore the For loop completely!

@Echo off&Setlocal
Set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1"
Reg query %key% /v DisplayVersion|Find "3.1.3">Nul&&(
Echo:version 3.1.3 is installed)

Link to comment
Share on other sites

Hello,

Thank you for your effort and prompt reply -- THIS DID WORK!

Can you help me with one additional thing in this script:

Basically, I want to do a couple of things if 3.1.3 is found. You had combined it in such a way, I am having difficulty inserting an "IF" statement.

Say I want to do this:

If [3.1.3] is found (

echo version 3.1.3 is installed

c:\install\Snare314.exe

c:\install\Snare314patch.exe

echo version 3.1.4 successfully installed

)

Thanks again for your great help!

Link to comment
Share on other sites

You just need to add your commands into the parentheses!

@Echo off&Setlocal
Set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1"
Reg query %key% /v DisplayVersion|Find "3.1.3">Nul&&(
Echo:version 3.1.3 is installed
Start "" /w %SystemDrive%\install\Snare314.exe||Goto :Eof
Start "" /w %SystemDrive%\Snare314patch.exe&&(
Echo:version 3.1.4 successfully installed))

Link to comment
Share on other sites

Hello,

This worked great, thanks again. Got another question along this topic ... do you know if there is away to capture a value in the registry and use it as a parameter in a command line, within the same batch file?

For example, in a batch file, if I run the following command:

reg query "HKLM\SOFTWARE\Intervade Software\Audit\Network" /v Destination

My output is such:

HKEY_LOCAL_MACHINE\SOFTWARE\Intervade Software\Audit\Network

Destination REG_SZ 127.0.0.1

Then, in the same batch file, I want to add "127.0.0.1" into the command line as such:

reg add "HKLM\SOFTWARE\Intervade Software\Audit\Network" /v Destination /t REG_SZ /d 127.0.0.1 /f

Thanks again in advance for your help.

Link to comment
Share on other sites

For example, in a batch file, if I run the following command:

reg query "HKLM\SOFTWARE\Intervade Software\Audit\Network" /v Destination

My output is such:

HKEY_LOCAL_MACHINE\SOFTWARE\Intervade Software\Audit\Network

Destination REG_SZ 127.0.0.1

Then, in the same batch file, I want to add "127.0.0.1" into the command line as such:

reg add "HKLM\SOFTWARE\Intervade Software\Audit\Network" /v Destination /t REG_SZ /d 127.0.0.1 /f

Just one question, why are you reading a key then writing the same data back to the same key?
Link to comment
Share on other sites

Just one question, why are you reading a key then writing the same data back to the same key?

Good point. :)

It seems pretty useless, however....

You need to understand a bit about tokens and delimiters (and skip):

http://www.robvanderwoude.com/ntfor.html

http://www.robvanderwoude.com/ntfortokens.html

The first line of your output can be skipped (or you can use the FIND pipeline to exclude it).

Set mykey="HKLM\SOFTWARE\Intervade Software\Audit\Network"
set myvalue=Destination


FOR /F "tokens=3" %%A IN ('reg query %mykey% /v %myvalue% ^|FIND "REG_SZ"') DO (
SET myvalueDATA=%%A
)

ECHO reg add "HKLM\SOFTWARE\Intervade Software\Audit\Network" /v %myvalue% /t REG_SZ /d %myvaluedata% /f

PAUSE

this should work as well:

Set mykey="HKLM\SOFTWARE\Intervade Software\Audit\Network"
set myvalue=Destination


FOR /F "skip=3 tokens=3" %%A IN ('reg query %mykey% /v %myvalue%') DO (
SET myvalueDATA=%%A
)

ECHO reg add "HKLM\SOFTWARE\Intervade Software\Audit\Network" /v %myvalue% /t REG_SZ /d %myvaluedata% /f

PAUSE

By default delims are already [sPACE] and [TAB] so you do not need to specify them.

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...