代码之家  ›  专栏  ›  技术社区  ›  jani

检查安装了哪些浏览器,然后在其桌面上创建快捷方式

  •  0
  • jani  · 技术社区  · 1 年前

    我们可以在以下代码的帮助下检查用户计算机上安装的浏览器。

         If File.Exists("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") OrElse File.Exists("C:\Program Files\Google\Chrome\Application\chrome.exe") Then
            ListBox1.Items.Add("Chrome.exe")
        End If
    
        If File.Exists("C:\Program Files (x86)\Mozilla Firefox\firefox.exe") OrElse File.Exists("C:\Program Files\Mozilla Firefox\firefox.exe") Then
            ListBox1.Items.Add("Firefox.exe")
        End If
    

    在检查了已经安装的任何浏览器后,我们如何在任何浏览器的桌面上创建快捷方式。请引导。

    1 回复  |  直到 1 年前
        1
  •  0
  •   Best Thinking    1 年前

    您也可以使用类似这样的简单代码来实现您的目标。我已经修改了您的代码,并提供了一个合适的解决方案。如果您觉得它正确且方便,请将其作为可接受的解决方案进行检查。

         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