public void Save(string linkFileName) { if (null == linkFileName) { throw new ArgumentNullException("linkFileName", "A name of the link file cannot be null"); } new FileIOPermission(FileIOPermissionAccess.Write, linkFileName).Demand(); int showCmd = (int)this.showCmd; object sl = null; try { Type slType = Type.GetTypeFromCLSID(CLSID_ShellLink); sl = Activator.CreateInstance(slType); IShellLinkW shellLinkW = sl as IShellLinkW; if (null == shellLinkW) { IShellLinkA shellLinkA = sl as IShellLinkA; if (null == shellLinkA) { ThrowInvalidComObjectException(); } shellLinkA.SetArguments(Str(this.arguments)); shellLinkA.SetDescription(Str(this.description)); shellLinkA.SetHotkey(this.hotkey); shellLinkA.SetIconLocation(Str(this.iconPath), this.iconIndex); shellLinkA.SetPath(Str(this.path)); shellLinkA.SetShowCmd(showCmd); shellLinkA.SetWorkingDirectory(Str(this.workingDirectory)); } else { shellLinkW.SetArguments(Str(this.arguments)); shellLinkW.SetDescription(Str(this.description)); shellLinkW.SetHotkey(this.hotkey); shellLinkW.SetIconLocation(Str(this.iconPath), this.iconIndex); shellLinkW.SetPath(Str(this.path)); shellLinkW.SetShowCmd(showCmd); shellLinkW.SetWorkingDirectory(Str(this.workingDirectory)); } IPersistFile pf = sl as IPersistFile; pf.Save(linkFileName, true); } finally { if (null != sl) { Marshal.ReleaseComObject(sl); } } // This object is not eligible for the garbage collection during this method call GC.KeepAlive(this); }