ceez Posted March 5, 2008 Posted March 5, 2008 Hello fellow msfn-ers!I have a task I am trying perform using good ol' batch file commands (i've yet to learn WMI scripting! ). What I want to do is for the script to check if the latest version of qtime is installed. In the registry the path is:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties]The key:"DisplayVersion"="7.4.0.91"How can I have an IF / THEN / GOTO command (or any other) incorporated to check this key?I was thinking about trying an export but an export cant check the value of the key (can it?)Thanks for your help...in the meanwhile I continue my google search!ceez:thumbup
ceez Posted March 5, 2008 Author Posted March 5, 2008 ok so far I can get DOS to output the version# with the following cmd:reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties /v DisplayVersionThe output is the following:C:\>reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties /v DisplayVersion! REG.EXE VERSION 3.0HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties DisplayVersion REG_SZ 7.4.0.91Now how can I make a line that says something like:If DisplayVersion not equal to 7.4.0.91 then install "c:\apps\QuickTime740Installer.exe"thanks again.
Yzöwl Posted March 5, 2008 Posted March 5, 2008 Try something like this:@Echo OffSetlocalSet "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData"Set "key=%key%\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA"Set "key=%key%\InstallProperties"For /f "tokens=3 delims= " %%# In ( 'Reg query %key% /v DisplayVersion^|Find "REG_" 2^>Nul') Do Set "rel=%%#"If Not [%rel%]==[7.4.0.91] Start "" /wait C:\apps\QuickTime740Installer.exeEndlocalGoto :EofWhere delims=<TAB>"
ceez Posted March 6, 2008 Author Posted March 6, 2008 @Yzowl, WOW how long did it take you to come up with that?!?! I am not at work so cant try it out but will tomorrow. could it be possible for you explain a little bit what each line does? I regards to the "delim" section you're saying that I should press the TAB key there and not just empty spaces? And where did you learn all this batch coding?Man thanks again, hope it works.ceez
Yzöwl Posted March 6, 2008 Posted March 6, 2008 Now aren't I glad I gave you a longer but easier to understand solution...Lines 1 & 2 turn off echoing to the console and ensure that all variables are locally set.Lines 3, 4 & 5 is my way of setting the key you gave for the registry data we're looking for. It is considered good practice when coding to maintain maximum character line lengths, in this case 80 characters; so I've split it across 3 lines for this reason.The For loop is where it gets interesting...I took your reg query command and put it inside the parentheses.because your output produced more than one line I needed to capture only the line containing your version data so I sent the result of the reg query through a find command to pick up the line containing REG_the output of the data is TAB delimited (delims=<TAB>) into distinct columns.the data you wanted was in the third column (tokens=3)Basically any data in third column of that key will be set to the local variable %rel%All we do then is a simple `if result of query is not our data then perform this task` line.For that line, i.e. your installation, you could see if you can use silent switches too, this would remove any end-user interaction!
ceez Posted March 6, 2008 Author Posted March 6, 2008 excellent explanation, thank you very much.I just tried it and it works perfectly! I tried it on my workstation which has that version and it does not run, if I modify the version number on my registry and try to run it again it will begin the setup. Yes, I will be adding the /q switch for a silent installation.Now I have the same thing to do with with Java 6.3... I should be able to follow the same concept thanks alot for your help!ceez
Xaneth Posted May 30, 2008 Posted May 30, 2008 I'm trying to do the same thing, but I'm still not seeing how you're setting tab as the delimiter. Do you put spaces in, or just hit tab, or use "delims=<tab>"? I'm just trying to update our Adobe Flash player, and looking for version 9.0.124.0 under the key hklm\software\microsoft\active setup\installed components\{d27cdb6e-ae6d-11cf-96b8-444553540000}. When I run the command by hand, I'm also getting %%# was not expected at this time.
Yzöwl Posted May 31, 2008 Posted May 31, 2008 You just use the Tab key, I needed to explain in that way because the forum software sometimes converts the tab I input into a series of spaces.When you run the command manually in a console window, you'll need to replace all instances of %%# with %#.
Xaneth Posted June 2, 2008 Posted June 2, 2008 (edited) ===== Post Nº 1 =====Thanks for that. The tab and %# work for me now, but I get an error in my reg query syntax now. I'm essentially trying to perform the following with my query:reg query %key% /s | find "Version"I try to pass it the way you wrote:'Reg query %key% /v DisplayVersion^|Find "REG_" 2^>Nul'But I'm getting the same error, Type "REG QUERY /?" for usage. I've tried it multiple ways as well since it doesn't seem to understand the pipe too well, I tried'Reg query %key% /s DisplayVersion^|Find "Version" 2^>Nul''Reg query %key% /v DisplayVersion^|Find "Version" 2^>Nul''Reg query %key% /s Version^|Find "Version" 2^>Nul''Reg query %key% /s Version^|Find "reg_" 2^>Nul'None of which seem to work.===== Post Nº 2 =====OK, I managed to get it working somewhat with:reg query "%key%" /v Version^|find "REG_"This is because my registry path has spaces in it. I am still not getting the results intended however, as the executable is not launching. Not sure what I'm doing wrong here but still pounding away at it. What is returned after typing that command is: Version REG_SZ 9.0.124.0In fact the full command I'm trying to execute is:for /f "tokens=3 delims= " %# In ('reg query "%key%" /v Version^|find "REG_" 2^>Nul') do set "rel=%#" if not [%rel%]==[9.0.115.0] start "" /wait "fileservershareflash.msi"Since I have version 9.0.124.0, the installer should run for me but it's not. Edited June 12, 2008 by Yzöwl
Yzöwl Posted June 12, 2008 Posted June 12, 2008 Apologies for not answering his sooner Xaneth, I've no idea how I missed your question.Here are two solutions, one for each key, (I'd suggest the latter)Uninstall key version@Echo Off&SetlocalSet "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"Set "key=%key%\Adobe Flash Player Plugin"For /f "tokens=3 delims= " %%# In ( 'Reg query "%key%" /v DisplayVersion^|Find "REG_" 2^>Nul') Do Set "rel=%%#"If Not [%rel%]==[9.0.115.0] Start "" /wait \\fileserver\share\flash.msiEndlocal&Goto :Eofplugins key version@Echo Off&SetlocalSet "key=HKLM\SOFTWARE\MozillaPlugins\@adobe.com/FlashPlayer"For /f "tokens=3 delims= " %%# In ( 'Reg query %key% /v Version^|Find "REG_" 2^>Nul') Do Set "rel=%%#"If Not [%rel%]==[9.0.115.0] Start "" /wait \\fileserver\share\flash.msiEndlocal&Goto :EofNoteDon't forget that delims=<tab>" in both versionsI hope this helps!I'll leave it to you to explain, if you wish, why you'd attempt to install 9.0.115.0 over 9.0.124.0
Xaneth Posted June 13, 2008 Posted June 13, 2008 (edited) Thanks a lot, I'll give it a try as soon as I get some time! The reason I was doing it this way, was to test the installation to make sure it would kick off, since I don't want to downgrade just to test this out. I'll be replacing:If Not [%rel%]==[9.0.115.0] Start "" /wait \\fileserver\share\flash.msiwith If Not [%rel%]==[9.0.124.0] Start "" /wait \\fileserver\share\flash.msi Edited June 13, 2008 by Xaneth
Yzöwl Posted June 13, 2008 Posted June 13, 2008 Just remember to get time quickly because I've already seen leaked versions of flash v10.0.1.218 circulating the net
jxhzhang Posted June 19, 2008 Posted June 19, 2008 Hello, I'm new but I'm trying to do the exact same thing but there is a twist to this.I'm trying to do an uninstall for Adobe Reader 7.0.9 or Reader 7.1.0. The thing is 7.0.9 uses this key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A70900000002} while 7.1.0 use this HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A71000000002}. How would I check if 7.0.9 doesn't exist then check 7.1.0?Right now REG would return an error while checking for 7.0.9 (because it doesn't exist on a machine with 7.1.0 installed). How would I go about to get around that?Thanks,James
Yzöwl Posted June 19, 2008 Posted June 19, 2008 Here's a quick stab at what I think you want:@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') Do Start "" /wait "%%~#"The intention is that it'll uninstall either version 7.0.9 or 7.1.0 if either one of them exist!Let us know how it goes.NoteRemember when you paste it in that delims=<tab>" in the last 'For loop'.
jxhzhang Posted July 9, 2008 Posted July 9, 2008 Here's a quick stab at what I think you want:@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') Do Start "" /wait "%%~#"The intention is that it'll uninstall either version 7.0.9 or 7.1.0 if either one of them exist!Let us know how it goes.NoteRemember when you paste it in that delims=<tab>" in the last 'For loop'.Thank you for a quick response! Took me a bit of time to understood what the code does. You are taking the UninstallString from registry and running it, but I need it to be silent (using the /x and end with -qb instead of /i). Also when I ran the batch you've created, I get this Not sure why it gives you that error because I executed the UninstallString with Run and works fine. So is it possible to do the batch above and silent uninstall (with progress window)? Thanks again!
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now