我想使用反射來執行下面的代碼行。在運行時投射物體
IWshRuntimeLibrary.IWshShortcut desktopShortCut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.SpecialFolder.Desktop.ToString()+"\\Max Y+Y.lnk");
我已經成功地獲得了表達的正確部分。
WshShell.CreateShortcut(....)
通過使用
this.assembly = Assembly.LoadFrom(Environment.CurrentDirectory + "\\Interop.IWshRuntimeLibrary.dll");
AppDomain.CurrentDomain.Load(assembly.GetName());
this.WshShellClass = assembly.GetType("IWshRuntimeLibrary.WshShellClass");
object classInstance = Activator.CreateInstance(this.WshShellClass, null);
object[] parameters = new object[1];
parameters[0] = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Max Y+Y.lnk";
MethodInfo methodInfo = this.WshShellClass.GetMethod("CreateShortcut");
object result = methodInfo.Invoke(classInstance, parameters);
現在我想將它轉換類型的反對IWshRuntimeLibrary.IWshShortcut
結果在上述情況下,並將其分配給。
IWshRuntimeLibrary.IWshShortcut desktopShortCut,
這怎麼可能?
到底什麼是做這個晚點?只需添加對c:\ windows \ system32 \ wshom.ocx的引用 –
我正在開發安裝程序項目安裝屏蔽2011(限制版)。並將此代碼作爲exe自定義action.For由於某些原因,我無法添加參考。 –