using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Shell32
{
/// Specifies option settings. Used with IShellLinkDataList::GetFlags and IShellLinkDataList::SetFlags.
[PInvokeData("Shlobj.h", MSDNShortId = "bb762540")]
[Flags]
public enum SHELL_LINK_DATA_FLAGS : uint
{
/// Default value used when no other flag is explicitly set.
SLDF_DEFAULT = 0x00000000,
/// The Shell link was saved with an ID list.
SLDF_HAS_ID_LIST = 0x00000001,
///
/// The Shell link was saved with link information to enable distributed tracking. This information is used by .lnk files to
/// locate the target if the targets's path has changed. It includes information such as volume label and serial number, although
/// the specific stored information can change from release to release.
///
SLDF_HAS_LINK_INFO = 0x00000002,
/// The link has a name.
SLDF_HAS_NAME = 0x00000004,
/// The link has a relative path.
SLDF_HAS_RELPATH = 0x00000008,
/// The link has a working directory.
SLDF_HAS_WORKINGDIR = 0x00000010,
/// The link has arguments.
SLDF_HAS_ARGS = 0x00000020,
/// The link has an icon location.
SLDF_HAS_ICONLOCATION = 0x00000040,
/// Stored strings are Unicode.
SLDF_UNICODE = 0x00000080,
///
/// Prevents the storage of link tracking information. If this flag is set, it is less likely, though not impossible, that a
/// target can be found by the link if that target is moved.
///
SLDF_FORCE_NO_LINKINFO = 0x00000100,
/// The link contains expandable environment strings such as %windir%.
SLDF_HAS_EXP_SZ = 0x00000200,
/// Causes a 16-bit target application to run in a separate Virtual DOS Machine (VDM)/Windows on Windows (WOW).
SLDF_RUN_IN_SEPARATE = 0x00000400,
/// Not supported. Note that as of Windows Vista, this value is no longer defined.
SLDF_HAS_LOGO3ID = 0x00000800,
/// The link is a special Windows Installer link.
SLDF_HAS_DARWINID = 0x00001000,
/// Causes the target application to run as a different user.
SLDF_RUNAS_USER = 0x00002000,
/// The icon path in the link contains an expandable environment string such as such as %windir%.
SLDF_HAS_EXP_ICON_SZ = 0x00004000,
/// Prevents the use of ID list alias mapping when parsing the ID list from the path.
SLDF_NO_PIDL_ALIAS = 0x00008000,
/// Forces the use of the UNC name (a full network resource name), rather than the local name.
SLDF_FORCE_UNCNAME = 0x00010000,
///
/// Causes the target of this link to launch with a shim layer active. A shim is an intermediate DLL that facilitates
/// compatibility between otherwise incompatible software services. Shims are typically used to provide version compatibility.
///
SLDF_RUN_WITH_SHIMLAYER = 0x00020000,
/// Introduced in Windows Vista. Disable object ID distributed tracking information.
SLDF_FORCE_NO_LINKTRACK = 0x00040000,
/// Introduced in Windows Vista. Enable the caching of target metadata into the link file.
SLDF_ENABLE_TARGET_METADATA = 0x000800000,
/// Introduced in Windows 7. Disable shell link tracking.
SLDF_DISABLE_LINK_PATH_TRACKING = 0x00100000,
/// Introduced in Windows Vista. Disable known folder tracking information.
SLDF_DISABLE_KNOWNFOLDER_RELATIVE_TRACKING = 0x00200000,
/// Introduced in Windows 7. Disable known folder alias mapping when loading the IDList during deserialization.
SLDF_NO_KF_ALIAS = 0x00400000,
/// Introduced in Windows 7. Allow link to point to another shell link as long as this does not create cycles.
SLDF_ALLOW_LINK_TO_LINK = 0x00800000,
/// Introduced in Windows 7. Remove alias when saving the IDList.
SLDF_UNALIAS_ON_SAVE = 0x01000000,
///
/// Introduced in Windows 7. Recalculate the IDList from the path with the environmental variables at load time, rather than
/// persisting the IDList.
///
SLDF_PREFER_ENVIRONMENT_PATH = 0x02000000,
///
/// Introduced in Windows 7. If the target is a UNC location on a local machine, keep the local IDList target in addition to the
/// remote target.
///
SLDF_KEEP_LOCAL_IDLIST_FOR_UNC_TARGET = 0x04000000,
///
/// Introduced in Windows 8. Persist the target IDlist in its volume-ID-relative form to avoid a dependency on drive letters.
///
SLDF_PERSIST_VOLUME_ID_RELATIVE = 0x08000000,
}
/// Defines which data block is supported.
[PInvokeData("Shobjidl.h", MSDNShortId = "bb774916")]
public enum ShellDataBlockSignature : uint
{
/// The target name.
EXP_SZ_LINK_SIG = 0xA0000001,
/// Console properties
NT_CONSOLE_PROPS_SIG = 0xA0000002,
/// The console's code page.
NT_FE_CONSOLE_PROPS_SIG = 0xA0000004,
/// Special folder information.
EXP_SPECIAL_FOLDER_SIG = 0xA0000005,
/// The link's Windows Installer ID.
EXP_DARWIN_ID_SIG = 0xA0000006,
/// The icon path.
EXP_SZ_ICON_SIG = 0xA0000007,
/// Stores information about the Shell link state.
EXP_PROPERTYSTORAGE_SIG = 0xA0000009,
}
/// Action flags.
[PInvokeData("Shobjidl.h", MSDNShortId = "bb774952")]
[Flags]
public enum SLR_FLAGS
{
/// No action.
SLR_NONE = 0,
///
/// Do not display a dialog box if the link cannot be resolved. When SLR_NO_UI is set, the high-order word of fFlags can be set
/// to a time-out value that specifies the maximum amount of time to be spent resolving the link. The function returns if the
/// link cannot be resolved within the time-out duration. If the high-order word is set to zero, the time-out duration will be
/// set to the default value of 3,000 milliseconds (3 seconds). To specify a value, set the high word of fFlags to the desired
/// time-out duration, in milliseconds.
///
SLR_NO_UI = 0x1,
/// Not used.
SLR_ANY_MATCH = 0x2,
///
/// If the link object has changed, update its path and list of identifiers. If SLR_UPDATE is set, you do not need to call
/// IPersistFile::IsDirty to determine whether the link object has changed.
///
SLR_UPDATE = 0x4,
/// Do not update the link information.
SLR_NOUPDATE = 0x8,
/// Do not execute the search heuristics.
SLR_NOSEARCH = 0x10,
/// Do not use distributed link tracking.
SLR_NOTRACK = 0x20,
///
/// Disable distributed link tracking. By default, distributed link tracking tracks removable media across multiple devices based
/// on the volume name. It also uses the UNC path to track remote file systems whose drive letter has changed. Setting
/// SLR_NOLINKINFO disables both types of tracking.
///
SLR_NOLINKINFO = 0x40,
/// Call the Windows Installer.
SLR_INVOKE_MSI = 0x80,
/// Windows XP and later.
SLR_NO_UI_WITH_MSG_PUMP = 0x101,
///
/// Windows 7 and later. Offer the option to delete the shortcut when this method is unable to resolve it, even if the shortcut
/// is not a shortcut to a file.
///
SLR_OFFER_DELETE_WITHOUT_FILE = 0x200,
///
/// Windows 7 and later. Report as dirty if the target is a known folder and the known folder was redirected. This only works if
/// the original target path was a file system path or ID list and not an aliased known folder ID list.
///
SLR_KNOWNFOLDER = 0x400,
///
/// Windows 7 and later. Resolve the computer name in UNC targets that point to a local computer. This value is used with SLDF_KEEP_LOCAL_IDLIST_FOR_UNC_TARGET.
///
SLR_MACHINE_IN_LOCAL_TARGET = 0x800,
/// Windows 7 and later. Update the computer GUID and user SID if necessary.
SLR_UPDATE_MACHINE_AND_SID = 0x1000,
///
SLR_NO_OBJECT_ID = 0x2000
}
///
/// Exposes methods that allow an application to attach extra data blocks to a Shell link. These methods add, copy, or remove data blocks.
///
[SuppressUnmanagedCodeSecurity]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("45e2b4ae-b1c3-11d0-b92f-00a0c90312e1")]
[PInvokeData("Shobjidl.h", MSDNShortId = "bb774916")]
public interface IShellLinkDataList
{
/// Adds a data block to a link.
/// The data block structure. For a list of supported structures, see IShellLinkDataList.
void AddDataBlock(IntPtr pDataBlock);
/// Retrieves a copy of a link's data block.
///
/// The data block's signature. The signature value for a particular type of data block can be found in its structure reference.
/// For a list of supported data block types and their associated structures, see IShellLinkDataList.
///
///
/// The address of a pointer to a copy of the data block structure. If IShellLinkDataList::CopyDataBlock returns a successful
/// result, the calling application must free the memory when it is no longer needed by calling LocalFree.
///
SafeLocalHandle CopyDataBlock(ShellDataBlockSignature dwSig);
/// Removes a data block from a link.
///
/// The data block's signature. The signature value for a particular type of data block can be found in its structure reference.
/// For a list of supported data block types and their associated structures, see IShellLinkDataList.
///
void RemoveDataBlock(ShellDataBlockSignature dwSig);
/// Gets the current option settings.
/// Pointer to one or more of the SHELL_LINK_DATA_FLAGS that indicate the current option settings.
SHELL_LINK_DATA_FLAGS GetFlags();
/// Sets the current option settings.
/// One or more of the SHELL_LINK_DATA_FLAGS that indicate the option settings.
void SetFlags(SHELL_LINK_DATA_FLAGS dwFlags);
}
/// Exposes methods that create, modify, and resolve Shell links.
[SuppressUnmanagedCodeSecurity]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214F9-0000-0000-C000-000000000046"), CoClass(typeof(CShellLinkW))]
[PInvokeData("Shobjidl.h", MSDNShortId = "bb774950")]
public interface IShellLinkW
{
/// Gets the path and file name of the target of a Shell link object.
/// The address of a buffer that receives the path and file name of the target of the Shell link object.
///
/// The size, in characters, of the buffer pointed to by the pszFile parameter, including the terminating null character. The
/// maximum path size that can be returned is MAX_PATH. This parameter is commonly set by calling ARRAYSIZE(pszFile). The
/// ARRAYSIZE macro is defined in Winnt.h.
///
///
/// A pointer to a WIN32_FIND_DATA structure that receives information about the target of the Shell link object. If this
/// parameter is NULL, then no additional information is returned.
///
/// Flags that specify the type of path information to retrieve.
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath,
[In, Out] WIN32_FIND_DATA pfd, SLGP fFlags);
/// Gets the list of item identifiers for the target of a Shell link object.
/// When this method returns, contains the address of a PIDL.
PIDL GetIDList();
/// Sets the pointer to an item identifier list (PIDL) for a Shell link object.
/// The object's fully qualified PIDL.
void SetIDList(PIDL pidl);
/// Gets the description string for a Shell link object.
/// A pointer to the buffer that receives the description string.
/// The maximum number of characters to copy to the buffer pointed to by the pszName parameter.
void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxName);
/// Sets the description for a Shell link object. The description can be any application-defined string.
/// A pointer to a buffer containing the new description string.
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
/// Gets the name of the working directory for a Shell link object.
/// The address of a buffer that receives the name of the working directory.
///
/// The maximum number of characters to copy to the buffer pointed to by the pszDir parameter. The name of the working directory
/// is truncated if it is longer than the maximum specified by this parameter.
///
void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
/// Sets the name of the working directory for a Shell link object.
/// The address of a buffer that contains the name of the new working directory.
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
/// Gets the command-line arguments associated with a Shell link object.
/// A pointer to the buffer that, when this method returns successfully, receives the command-line arguments.
///
/// The maximum number of characters that can be copied to the buffer supplied by the pszArgs parameter. In the case of a Unicode
/// string, there is no limitation on maximum string length. In the case of an ANSI string, the maximum length of the returned
/// string varies depending on the version of Windows—MAX_PATH prior to Windows 2000 and INFOTIPSIZE (defined in Commctrl.h) in
/// Windows 2000 and later.
///
void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
/// Sets the command-line arguments for a Shell link object.
///
/// A pointer to a buffer that contains the new command-line arguments. In the case of a Unicode string, there is no limitation
/// on maximum string length. In the case of an ANSI string, the maximum length of the returned string varies depending on the
/// version of Windows—MAX_PATH prior to Windows 2000 and INFOTIPSIZE (defined in Commctrl.h) in Windows 2000 and later.
///
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
/// Gets the keyboard shortcut (hot key) for a Shell link object.
///
/// The address of the keyboard shortcut. The virtual key code is in the low-order byte, and the modifier flags are in the
/// high-order byte.
///
ushort GetHotKey();
/// Sets a keyboard shortcut (hot key) for a Shell link object.
///
/// The new keyboard shortcut. The virtual key code is in the low-order byte, and the modifier flags are in the high-order byte.
/// The modifier flags can be a combination of the values specified in the description of the IShellLink::GetHotkey method.
///
void SetHotKey(ushort wHotKey);
/// Gets the show command for a Shell link object.
///
/// A pointer to the command. The following commands are supported.
///
/// -
/// SW_SHOWNORMAL
///
/// Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and
/// position. An application should specify this flag when displaying the window for the first time.
///
///
/// -
/// SW_SHOWMAXIMIZED
/// Activates the window and displays it as a maximized window.
///
/// -
/// SW_SHOWMINIMIZED
/// Activates the window and displays it as a minimized window.
///
///
///
ShowWindowCommand GetShowCmd();
/// Sets the show command for a Shell link object. The show command sets the initial show state of the window.
///
/// SetShowCmd accepts one of the following ShowWindow commands.
///
/// -
/// SW_SHOWNORMAL
///
/// Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and
/// position. An application should specify this flag when displaying the window for the first time.
///
///
/// -
/// SW_SHOWMAXIMIZED
/// Activates the window and displays it as a maximized window.
///
/// -
/// SW_SHOWMINIMIZED
/// Activates the window and displays it as a minimized window.
///
///
///
void SetShowCmd(ShowWindowCommand iShowCmd);
/// Gets the location (path and index) of the icon for a Shell link object.
/// The address of a buffer that receives the path of the file containing the icon.
/// The maximum number of characters to copy to the buffer pointed to by the pszIconPath parameter.
/// The address of a value that receives the index of the icon.
void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath,
out int piIcon);
/// Sets the location (path and index) of the icon for a Shell link object.
/// The address of a buffer to contain the path of the file containing the icon.
/// The index of the icon.
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
/// Sets the relative path to the Shell link object.
///
/// The address of a buffer that contains the fully-qualified path of the shortcut file, relative to which the shortcut
/// resolution should be performed. It should be a file name, not a folder name.
///
/// Reserved. Set this parameter to zero.
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, [Optional] uint dwReserved);
/// Attempts to find the target of a Shell link, even if it has been moved or renamed.
///
/// A handle to the window that the Shell will use as the parent for a dialog box. The Shell displays the dialog box if it needs
/// to prompt the user for more information while resolving a Shell link.
///
/// Action flags.
void Resolve(HWND hwnd, SLR_FLAGS fFlags);
/// Sets the path and file name for the target of a Shell link object.
/// The address of a buffer that contains the new path.
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}
/// Class interface for IShellLinkW.
[ComImport, Guid("00021401-0000-0000-C000-000000000046"), ClassInterface(ClassInterfaceType.None)]
public class CShellLinkW { }
}
}