在目录中创建应用程序快捷方式如何在C#或使用.NET框架中创建应用程序快捷方式(.ink文件)?结果将是指向指定应用程序或URL的.ink文件。
3 回答
湖上湖
TA贡献2003条经验 获得超2个赞
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); //Windows Script Host Shell Objectdynamic shell = Activator.CreateInstance(t);try{ var lnk = shell.CreateShortcut("sc.lnk"); try{ lnk.TargetPath = @"C:\something"; lnk.IconLocation = "shell32.dll, 1"; lnk.Save(); }finally{ Marshal.FinalReleaseComObject(lnk); }}finally{ Marshal.FinalReleaseComObject(shell);}
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); //Windows Script Host Shell Objectobject shell = Activator.CreateInstance(t);try{ object lnk = t.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod, null, shell, new object[]{"sc.lnk"}); try{ t.InvokeMember("TargetPath", BindingFlags.SetProperty, null, lnk, new object[]{@"C:\whatever"}); t.InvokeMember("IconLocation", BindingFlags.SetProperty, null, lnk, new object[]{"shell32.dll, 5"}); t.InvokeMember("Save", BindingFlags.InvokeMethod, null, lnk, null); }finally{ Marshal.FinalReleaseComObject(lnk); }}finally{ Marshal.FinalReleaseComObject(shell);}
- 3 回答
- 0 关注
- 489 浏览
添加回答
举报
0/150
提交
取消