转换

2013-04-23 42 views
0

你好,我想显示一个错误,如果语句的一个是假的,但我得到一个错误:错误\ 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

“\ example.exe”是外界的存在()调用,它需要去括号内 – 2013-04-23 11:06:50

+0

谢谢,但这并没有帮助“My.Computer.FileSystem.FileExists(My.Computer.Registry.GetValue(”HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ EXAMPLE“,”InstallLocation“,”ERROR“&”\ example.exe“))然后“ – VeilSide 2013-04-23 12:32:03

回答

1

,因为要连接的路径与文件名,并使用你的第二个条件是不正确检查文件是否存在,但文件名不在方法调用内。而不将字符串创建的路径,你应该使用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 
+0

非常感谢蒂姆,但现在当我尝试更改注册表项时,我得到另一个错误,而不是该自定义对话框 ”值不能为空“。 “参数名称:path1”。 – VeilSide 2013-04-23 11:43:32

+0

然后你必须显示代码。你确定这个错误与这个问题有关吗?如果它不相关,你应该问另一个问题。 – 2013-04-23 11:52:04

+0

我发布了编辑后的代码。 – VeilSide 2013-04-23 12:11:32