VeilSide
VeilSide

Reputation: 1

Conversion from string error

Hello I'm trying to show an error if one of the statement is false, but I get an error: "Conversion from string "False\example.exe" to type 'Boolean' is not valid."

If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\EXAMPLE", "InstallLocation", "") <> "" And
        My.Computer.FileSystem.FileExists(My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\EXAMPLE", "InstallLocation", "ERROR")) & "\example.exe" Then
    Else
        System.Threading.Thread.Sleep(1000)
        example_error.ShowDialog()
    End If

EDIT:

Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim ExecutablePath = IO.Path.Combine(CStr(My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MYAPP", "InstallLocation", "ERROR")), "myapp.exe")
    If Not String.IsNullOrEmpty(CStr(My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MYAPP", "InstallLocation", ""))) _
        AndAlso My.Computer.FileSystem.FileExists(ExecutablePath) Then
    Else
        System.Threading.Thread.Sleep(1000)
        GUI_Error.ShowDialog()
    End If
End Sub

Upvotes: 0

Views: 230

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460018

Your second condition is incorrect since you want to concatenate a path with the filename and use FileSystem.Exists to check if the file exists, but the filename is not inside of the method-call. Instead of concatenating string to create a path you should use Path.Combine:

Dim filePath = Path.Combine(CStr(My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\EXAMPLE", "InstallLocation", "ERROR")),
                            "example.exe")
If Not String.IsNullOrEmpty(CStr(My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\EXAMPLE", "InstallLocation", ""))) _
    AndAlso File.Exists(filePath) Then
Else
    System.Threading.Thread.Sleep(1000)
    example_error.ShowDialog()
End If

Upvotes: 1

Related Questions