(view source code of checkkindleupdate.vbs as plain text)
Option ExplicitDim arrCurrentVersion, arrLatestVersionDim blnQuiet, blnUpdateRequiredDim i, intRCDim colMatches, objFSO, objRE, wshShellDim strCurrentVersion, strDownloadURL, strExecPath, strInstallFolder, strLatestVersion, strRegKey, strVersionText, strVersionURLblnQuiet = False
blnUpdateRequired = False
intRC = 0
If WScript.Arguments.Unnamed.Count > 0 Then Syntax
Select Case WScript.Arguments.Named.Count
Case 0:
' No action requiredCase 1:
If WScript.Arguments.Named.Exists( "Q" ) Then
blnQuiet = True
ElseSyntax
End If
Case Else:
Syntax
End Select
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set wshShell = CreateObject( "WScript.Shell" )
Set objRE = New RegExp
strCurrentVersion = ""
' Read the Kindle Reader installation folder from the registrystrRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Amazon\Kindle\Install\InstallDir"
On Error Resume Next
strInstallFolder = wshShell.RegRead( strRegKey )
If Err Then
' Try again, now for 64-bit systemsstrRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Amazon\Kindle\Install\InstallDir"
strInstallFolder = wshShell.RegRead( strRegKey )
End If
On Error Goto 0
' Get the Kindle Reader executable's full pathstrExecPath = objFSO.BuildPath( strInstallFolder, "kindle.exe" )
' Check if the Kindle Reader executable file can be foundIf objFSO.FileExists( strExecPath ) Then
' Get the Kindle Reader executable file versionstrCurrentVersion = objFSO.GetFileVersion( strExecPath )
End If
strDownloadURL = "https://www.amazon.com/kindlepcdownload/ref=klp_hz_win"
' Read a Kindle Reader web page stating the latest available versionstrVersionURL = "https://www.amazon.com/gp/help/customer/display.html?nodeId=201245960"
strVersionText = GetURLContent( strVersionURL )
strLatestVersion = ""
' Use a RegExp to extract the latest available version from the web pageobjRE.Pattern = "The latest version of Kindle for PC, (\d+(\.\d+)+), includes the following:"
objRE.Global = False
objRE.IgnoreCase = False
If objRE.Test( strVersionText ) Then
Set colMatches = objRE.Execute( strVersionText )
If colMatches.Count > 0 Then
strLatestVersion = colMatches(0).SubMatches(0)
End If
Set colMatches = Nothing
End If
' Prepare version strings for comparisonarrCurrentVersion = Split( strCurrentVersion, "." )
arrLatestVersion = Split( strLatestVersion, "." )
If Not CheckIfEmpty( arrCurrentVersion ) And Not CheckIfEmpty( strLatestVersion ) Then
If UBound( arrCurrentVersion ) > 0 and UBound( arrLatestVersion ) > 0 Then
If UBound( arrCurrentVersion ) > UBound( arrLatestVersion ) Then
ReDim Preserve arrCurrentVersion( UBound( arrLatestVersion ) )
ElseIf UBound( arrCurrentVersion ) < UBound( arrLatestVersion ) Then
ReDim Preserve arrLatestVersion( UBound( arrCurrentVersion ) )
End If
End If
' Check if latest version exceeds currently installed versionFor i = 0 To UBound( arrCurrentVersion )
If CInt( arrLatestVersion(i) ) > CInt( arrCurrentVersion(i) ) Then
blnUpdateRequired = True ' assuming current version can never exceed latest version
End If
Next ' Display update status and start download if requiredIf blnUpdateRequired Then
' Display installed and latest versionsWScript.Echo "Kindle Reader for PC update check" & vbCrLf & vbCrLf _
& "Currently installed version" & vbTab & ":" & vbTab & strCurrentVersion & vbCrLf _
& "Latest available version " & vbTab & ":" & vbTab & strLatestVersion & vbCrLf & vbCrLf _
& "An update is available, please download and install it..."
intRC = 1
wshShell.Run strDownloadURL
ElseIf Not blnQuiet Then
WScript.Echo "Kindle Reader for PC update check" & vbCrLf & vbCrLf _
& "Currently installed version" & vbTab & ":" & vbTab & strCurrentVersion & vbCrLf _
& "Latest available version " & vbTab & ":" & vbTab & strLatestVersion & vbCrLf & vbCrLf _
& "You have the latest version, no update required."
intRC = 0
End If
End If
ElseWScript.Echo "Kindle Reader for PC update check" & vbCrLf & vbCrLf _
& "Unable to compare versions."
intRC = -1
End If
Set objRE = Nothing
Set wshShell = Nothing
Set objFSO = Nothing
Function CheckIfEmpty( myVar )
CheckIfEmpty = IsEmpty( myVar )
If IsNull( myVar ) Then CheckIfEmpty = True
If IsArray( myVar ) Then
If UBound( myVar ) = -1 Then CheckIfEmpty = True
ElseIf Trim( myVar ) = "" Then CheckIfEmpty = True
End If
End Function
Function GetURLContent( strURL )
Dim objRequestGetURLContent = ""
Set objRequest = CreateObject( "Microsoft.XMLHTTP" )
objRequest.open "GET", strURL, False
objRequest.send vbNull
If objRequest.status = 200 Then GetURLContent = objRequest.responseText
Set objRequest = Nothing
End Function
Sub Syntax Dim strMsgstrMsg = "CheckKindleUpdate.vbs, Version 1.02" _
& vbCrLf _& "Check if an update is available for Amazon's Kindle Reader for PC" _
& vbCrLf & vbCrLf _
& "Usage:" & vbTab & "CheckKindleUpdate.vbs [ /Q ]" _
& vbCrLf & vbCrLf _
& "Where:" & vbTab & "/Q" & vbTab & "Hides results unless an update is required" _
& vbCrLf & vbCrLf _
& "Return codes:" & vbTab & " 0" & vbTab & "the latest version is installed" _
& vbCrLf _& " " & vbTab & vbTab & " 1" & vbTab & "an update is available" _
& vbCrLf _& " " & vbTab & vbTab & "-1" & vbTab & "an error occurred" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit 1
End Sub
page last modified: 2025-10-11; loaded in 0.0106 seconds