바로가기에 링크된 실행파일명 바꾸기
void ModifyShortcutTargetName(string shortcutFilename)
{
WshShell shell = new WshShell();
FileInfo LinkFile = new FileInfo(shortcutFilename);
if (LinkFile.Exists)
{
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(LinkFile.FullName);
link.TargetPath = link.TargetPath.Replace("AAA.exe", "BBB.exe");
link.Save();
}
// 아래 코드는 Windows XP 에서 실행되지 않는다
/*if (File.Exists(shortcutFilename) == false)
return;
var pathOnly = Path.GetDirectoryName(shortcutFilename);
var filenameOnly = Path.GetFileName(shortcutFilename);
var shell = new Shell32.Shell();
var folder = shell.NameSpace(pathOnly);
if (folder == null)
return;
var folderItem = folder.ParseName(filenameOnly);
if (folderItem == null)
return;
if (folderItem.IsLink == false)
return;
var link = (Shell32.ShellLinkObject)folderItem.GetLink;
link.Path = link.Path.Replace("AAA.exe", "BBB.exe");
link.Save();*/
}