0

ユーザーがプロファイルをデバイスに追加したときにプログラムが作成するフォルダーへのショートカットを作成しようとしています。フォルダーへのショートカット リンクは、ユーザーのお気に入り (Windows 7 エクスプローラーの横にあるライブラリ) に表示され、プロジェクトの logo.ico を持っているはずです。IWshRuntimeLibrary を使用する必要があると思いましたが、コードがランダムに停止し、エラーが返されません...助けはありますか?

注: profilePath、profileName、および executablePath はすべて正しいデータを返し、アクセスして変更しようとしているアイテムの正しい場所を指します。

public static bool CreateProfileShortcut(string profilePath, string profileName, string executablePath)
{
    bool success = false;
    string favoritesPath = "";
    IWshRuntimeLibrary.IWshShell wsh;
    IWshRuntimeLibrary.IWshShortcut shortcut;

    try
    {
        if (!String.IsNullOrWhiteSpace(profilePath) && Directory.Exists(profile.Path))
        {
            favoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            if (!File.Exists(favoritesPath + "\\Links\\" + profileName + ".lnk"))
            {
                wsh = new IWshRuntimeLibrary.WshShell();
                shortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(favoritesPath + "\\Links\\" + profileName + ".lnk");
                shortcut.TargetPath = profilePath;
                shortcut.IconLocation = executablePath + "\\Icons\\logo.ico";
                shortcut.Save();
            }
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(MessageBoxError(new string[] { e.TargetSite.Name, e.Message, "MinorError" }));
        success = false;
    }

    return success;
}
4

1 に答える 1

0

この質問この質問の両方を見てみてください。ご理解いただければ、Windows 7 の「お気に入り」エリアにショートカットを作成できるようにしてほしいと思います。

于 2012-11-06T14:49:32.093 に答える