Yzöwl Posted July 9, 2008 Share Posted July 9, 2008 Initially to fix the supplied script, try this:@Echo off&SetlocalSet "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 More sharing options...
jxhzhang Posted July 9, 2008 Share Posted July 9, 2008 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 More sharing options...
Yzöwl Posted July 9, 2008 Share Posted July 9, 2008 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 Link to comment Share on other sites More sharing options...
jxhzhang Posted July 9, 2008 Share Posted July 9, 2008 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 /qbWell I feel a bit dumb You are great help. Thanks again! Link to comment Share on other sites More sharing options...
pmuir Posted October 1, 2008 Share Posted October 1, 2008 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....SetlocalSet "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.exeJust 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.. ThanksPaul Link to comment Share on other sites More sharing options...
Yzöwl Posted October 1, 2008 Share Posted October 1, 2008 @pmuir, something like this should do you!@Echo off&SetlocalSet 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.exewhere delims=<TAB><DOT> Link to comment Share on other sites More sharing options...
jaclaz Posted October 1, 2008 Share Posted October 1, 2008 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.htmlThen 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 %%AECHO %%BECHO %%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 More sharing options...
luppybob Posted October 31, 2008 Share Posted October 31, 2008 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 DisplayVersionOutput is:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1 DisplayVersion REG_SZ 3.1.3I 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 installedThanks in advance for anyone's assistance. Link to comment Share on other sites More sharing options...
Yzöwl Posted October 31, 2008 Share Posted October 31, 2008 @ luppybobFirst 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&SetlocalSet "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 More sharing options...
luppybob Posted November 1, 2008 Share Posted November 1, 2008 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 More sharing options...
Yzöwl Posted November 1, 2008 Share Posted November 1, 2008 You just need to add your commands into the parentheses!@Echo off&SetlocalSet "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 More sharing options...
luppybob Posted November 3, 2008 Share Posted November 3, 2008 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 DestinationMy output is such:HKEY_LOCAL_MACHINE\SOFTWARE\Intervade Software\Audit\Network Destination REG_SZ 127.0.0.1Then, 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 /fThanks again in advance for your help. Link to comment Share on other sites More sharing options...
Yzöwl Posted November 3, 2008 Share Posted November 3, 2008 For example, in a batch file, if I run the following command:reg query "HKLM\SOFTWARE\Intervade Software\Audit\Network" /v DestinationMy output is such:HKEY_LOCAL_MACHINE\SOFTWARE\Intervade Software\Audit\Network Destination REG_SZ 127.0.0.1Then, 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 /fJust 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 More sharing options...
jaclaz Posted November 3, 2008 Share Posted November 3, 2008 (edited) 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.htmlhttp://www.robvanderwoude.com/ntfortokens.htmlThe 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=DestinationFOR /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% /fPAUSEthis should work as well:Set mykey="HKLM\SOFTWARE\Intervade Software\Audit\Network"set myvalue=DestinationFOR /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% /fPAUSEBy default delims are already [sPACE] and [TAB] so you do not need to specify them.jaclaz Edited November 3, 2008 by jaclaz Link to comment Share on other sites More sharing options...
luppybob Posted November 3, 2008 Share Posted November 3, 2008 Thank you again, I will give it a try.The lines I used was just an example. I plan to use the IP address in a different command, just wanted to give you something quick and fast.Best regards. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now