Jump to content

Confused on FileExists(regRead())


 Share

Recommended Posts

I am having difficulty getting my head around the following:

If FileExists(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\10.0", "")) Then
    MsgBox(0, "WMP Version", "Version is 10")
Else
    MsgBox(0, "WMP Version", "Version is 9")
EndIf

It always returns a 9 even through the "Default" value exists. If I use If Not FileExists it returns a 9. Maybe my logic is flawed but it seems to me that the statement works like this:

If (the blank Default reg value exists under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\10.0) Then

Version is 10

If (the blank Default reg value does NOT exist under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\10.0) Then

Version is 9.

It seems to me that the logic is completely backwards. Obviously I am misinterpreting something. Can someone please help me understand? Or perhaps there is a better way to determine the existence of a reg value.

Edited by ksmith247

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

My guess would be that you'd want to set $value = RegRead ( "keyname", "valuename" ) and then do your If...Else...EndIf statement. I could be wrong, but that's what I'd try since the Help file says this:

FileExists

--------------------------------------------------------------------------------

Checks if a file or directory exists.

FileExists ( "path" )

RegRead

--------------------------------------------------------------------------------

Reads a value from the registry.

RegRead ( "keyname", "valuename" )

Link to comment
Share on other sites

  • Moderators

Edit... Dammit to all hell!

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

SmOke_N is right on the money with the question, "what are you trying to do". If its as simple as getting the version of Windows Media Player and making a decision based on that... maybe you'd like this code better. This will guard against registry complications. Note this assumes that the default settings were accepted during the WMP installations. Hope this helps, and good luck!

$version = FileGetVersion('C:\Program Files\Windows Media Player\wmplayer.exe')
MsgBox(0, "WMP Version", "Version is " & $version)
$ver = StringLeft($version,2)
If $ver == "10" Then 
    ; some code here
Else
    ; some code here
EndIf
Link to comment
Share on other sites

Thanks for the info Smoke, though I cant find the reg key you mentioned.

HKLM\SOFTWARE\Classes\Software\Microsoft\WindowsMedia\Setup\BlockingRefCounts\Version

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

SmOke_N is right on the money with the question, "what are you trying to do". If its as simple as getting the version of Windows Media Player and making a decision based on that... maybe you'd like this code better. This will guard against registry complications. Note this assumes that the default settings were accepted during the WMP installations. Hope this helps, and good luck!

$version = FileGetVersion('C:\Program Files\Windows Media Player\wmplayer.exe')
MsgBox(0, "WMP Version", "Version is " & $version)
$ver = StringLeft($version,2)
If $ver == "10" Then 
    ; some code here
Else
    ; some code here
EndIf

It is that simple ssubirias3, though I really wanted to understand the FileExists thing. Never used FileGetVersion before and it never crossed my mind to do so. This will go a long way. Thanks.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

  • Moderators

Thanks for the info Smoke, though I cant find the reg key you mentioned.

HKLM\SOFTWARE\Classes\Software\Microsoft\WindowsMedia\Setup\BlockingRefCounts\Version

I tried to edit the first with an example... that's kind of funny though, that was pulled off a work PC because I don't have Media player on here.... I would think that version was being blocked from being able to be used ;) (wonder if there is a bad windows install there :) )

I would use the last suggestion along with ssubirias3's suggestion about FileGetVersion()... This way you have the directory it was installed on, and you can check the file version.

I deleted the regkey info up there because when I went to edit with an example it was all garbled.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

It is that simple ssubirias3, though I really wanted to understand the FileExists thing. Never used FileGetVersion before and it never crossed my mind to do so. This will go a long way. Thanks.

:) I haven't used FileGetVersion until now either! I thought there had to be another way without getting bogged down in the registry. Along the lines of SmOke_N suggestion of pulling the correct install directory, this is what the code might look like if you choose to use this method on WinXP.

$wmpdir = RegRead("HKLM\SOFTWARE\Microsoft\MediaPlayer", "Installation Directory")
$version = FileGetVersion($wmpdir & "\wmplayer.exe")
MsgBox(0, "WMP Version", "Version is " & $version)
$ver = StringLeft($version,2)
If $ver == "10" Then 
    ; some code here
Else
    ; some code here
EndIf
Link to comment
Share on other sites

Thanks to both. All devices are imaged so the default location should be intact. Test just finished... all 30 patches installed correctly. w00t!

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

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
 Share

  • Recently Browsing   0 members

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