0

我正在使用以下代码创建 Internet 快捷方式。但是在桌面的情况下,我正在设置的快捷方式的图标没有显示出来。但是,如果我手动将快捷方式重命名为其他名称,它的工作正常(图标被加载为快捷方式图像)。

private String CreateDeskTopShortcut(String ApplicationStartupUrl, String IconFilePath)
{
    string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    String UrlPath = deskDir + "\\" + "Test" + ".url";

    using (StreamWriter writer = new StreamWriter(UrlPath))
    {
        writer.WriteLine("[InternetShortcut]");
        writer.WriteLine("URL=" + ApplicationStartupUrl);
        writer.WriteLine("IconFile=" + IconFilePath);
        writer.WriteLine("IconIndex=0");
        writer.Flush();
    }

    return UrlPath;
}

调用相同

CreateDeskTopShortcut("https://ipAddress/website/Login.aspx","E:\Setup_Local\Server.ico");
4

1 回答 1

1

看起来 Windows 缓存了图标路径,即使您删除了文件,这种情况仍然存在。我不知道这个缓存存储在哪里,或者它是否在重新启动后仍然存在。我的复制步骤如下:

  1. 调用 CreateDeskTopShortcut(" http://www.google.co.uk ", "\path\to.ico");
  2. 使用预期图标创建的快捷方式。
  3. 删除快捷方式并调用 CreateDeskTopShortcut(" http://www.google.co.uk ", "\other-path\to.ico");
  4. 已创建快捷方式,但带有步骤 1 中的图标。
  5. 将快捷方式名称从“Test”更改为“Test2”。重复步骤 3。
  6. 已创建快捷方式,带有预期的图标。

所以使用的图标似乎映射到快捷方式的名称。

于 2014-12-22T11:24:01.730 回答