您也可以使用类似这样的简单代码来实现您的目标。我已经修改了您的代码,并提供了一个合适的解决方案。如果您觉得它正确且方便,请将其作为可接受的解决方案进行检查。
Dim path1 As String
Dim path2 As String
path1 = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
path2 = "C:\Program Files\Google\Chrome\Application\chrome.exe"
If System.IO.File.Exists(path1) OrElse System.IO.File.Exists(path2) Then
ListBox1.Items.Add("Chrome.exe")
Dim shell As WshShell = New WshShell()
Dim shortcut As IWshShortcut = shell.CreateShortcut("C:\Users\Administrator\Desktop\chrome1.lnk")
If System.IO.File.Exists(path1) OrElse System.IO.File.Exists(path2) Then
shortcut.TargetPath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
shortcut.Save()
End If
End If