0

您好,如果其中一个语句为假,我试图显示一个错误,但我收到一个错误:“从字符串“False\example.exe到类型布尔”的转换无效。

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

编辑:

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
4

1 回答 1

1

您的第二个条件不正确,因为您想将路径与文件名连接起来并用于FileSystem.Exists检查文件是否存在,但文件名不在方法调用中。而不是连接字符串来创建你应该使用的路径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
于 2013-04-23T11:13:44.323 回答