how to get location of installed products in Add and Remove using c#? (2023)

Archived Forums 421-440

>

Visual C#

  • Question

  • how to get location of installed products in Add and Remove using c#? (1)

    Sign in to vote

    Hi all,

    i want to fetch the location of installed products which are listed in "ADD and REMOVE" i tried to fetch using Windows Registry and also WMI query but both are returning location of few products only.

    plz tell me how to get installed location of all products?

    TIA

    sumitk

    (Video) What Are DLLs?

    Thursday, November 16, 2017 11:38 AM

All replies

  • how to get location of installed products in Add and Remove using c#? (3)

    (Video) Does This Connector Even Do Anything? - DisplayPort Explained

    Sign in to vote

    You can query the PKEY_Software_InstallLocation key with IShellFolder2.GetDetailsEx(), but it gets the same value as what is displayed in Explorer.

    For example, I get nothing for "Adobe Flash Player 27 NPAPI", either with Explorer or in C# :

    (I tested on Windows 10, VS 2015)

    how to get location of installed products in Add and Remove using c#? (5)


    • Edited by Castorix31 Thursday, November 16, 2017 5:57 PM
    • Proposed as answer by Wendy ZangMicrosoft contingent staff Friday, November 17, 2017 8:27 AM

    Thursday, November 16, 2017 5:56 PM

  • how to get location of installed products in Add and Remove using c#? (6)

    Sign in to vote

    (Video) No Crank No Start-Misdiagnosed! Almost. 2014 Jeep Grand Cherokee 5.7 Hemi

    hi,

    can you provide me the c# code for writing query forPKEY_Software_InstallLocation

    sumitk

    Monday, November 20, 2017 4:19 AM

    (Video) How to properly configure the SSD as boot drive and HDD as storage drive
  • how to get location of installed products in Add and Remove using c#? (8)

    Sign in to vote

    can you provide me the c# code for writing query forPKEY_Software_InstallLocation

    For example (returns all items in x64) =>

    object ObjpsfPrograms = null;IntPtr pidlPrograms;uint psfgaoOut = 0;HRESULT hr = SHParseDisplayName("shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5}", IntPtr.Zero, out pidlPrograms, 0, out psfgaoOut);if (hr == HRESULT.S_OK){ IShellFolder pshDesktop; hr = SHGetDesktopFolder(out pshDesktop); Guid IID_IShellFolder = new Guid("000214E6-0000-0000-C000-000000000046"); hr = pshDesktop.BindToObject(pidlPrograms, IntPtr.Zero, IID_IShellFolder, out ObjpsfPrograms); if (hr == HRESULT.S_OK) { IEnumIDList ppenum; IntPtr pidlChild = IntPtr.Zero; int celtFetched = 0; IShellFolder psfPrograms = (IShellFolder)ObjpsfPrograms; hr = psfPrograms.EnumObjects(IntPtr.Zero, SHCONTF.SHCONTF_ENABLE_ASYNC | SHCONTF.SHCONTF_FLATLIST | SHCONTF.SHCONTF_FOLDERS | SHCONTF.SHCONTF_INCLUDEHIDDEN | SHCONTF.SHCONTF_NONFOLDERS, out ppenum); if (hr == HRESULT.S_OK) { int nCpt = 0; hr = ppenum.Next(1, out pidlChild, out celtFetched); while (hr == HRESULT.S_OK && (celtFetched) == 1) { nCpt++; IntPtr pFolderName = IntPtr.Zero; STRRET strretFolderName; hr = psfPrograms.GetDisplayNameOf(pidlChild, SHGDNF.SHGDN_INFOLDER, out strretFolderName); string sDisplayName = null; StringBuilder sbDisplayName = default(StringBuilder); sbDisplayName = new StringBuilder(256); StrRetToBuf(ref strretFolderName, pidlChild, sbDisplayName, (uint)sbDisplayName.Capacity); sDisplayName = sbDisplayName.ToString(); IShellFolder2 psf2 = (IShellFolder2)psfPrograms; object vVariantInstallLocation = null, vVariantItemName = null, vVariantInstallDate = null; PROPERTYKEY pk = PROPERTYKEY.PKEY_Software_InstallLocation; //-2147023288 0x80070648 ERROR_UNKNOWN_PROPERTY hr = psf2.GetDetailsEx(pidlChild, ref pk, out vVariantInstallLocation); pk = PROPERTYKEY.PKEY_ItemNameDisplay; hr = psf2.GetDetailsEx(pidlChild, ref pk, out vVariantItemName); pk = PROPERTYKEY.PKEY_Software_InstallDate; hr = psf2.GetDetailsEx(pidlChild, ref pk, out vVariantInstallDate); Console.WriteLine(string.Format("Name : {0} - Install Location: {1} - Install Date: {2}", sDisplayName, vVariantInstallLocation, vVariantInstallDate)); hr = ppenum.Next(1, out pidlChild, out celtFetched); } } }}

    Declarations :

    [DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]public static extern HRESULT SHParseDisplayName([MarshalAs(UnmanagedType.LPWStr)] string name, IntPtr bindingContext, [Out()] out IntPtr pidl, uint sfgaoIn, [Out()] out uint psfgaoOut);[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]public static extern HRESULT SHGetDesktopFolder([MarshalAs(UnmanagedType.Interface)] out IShellFolder ppshf);[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "StrRetToBufW")]public static extern HRESULT StrRetToBuf(ref STRRET pstr, IntPtr pidl, StringBuilder pszBuf, [MarshalAs(UnmanagedType.U4)] uint cchBuf);public enum HRESULT : int{ S_OK = 0, S_FALSE = 1, E_FAIL = unchecked((int)0x80004005),}[Flags]public enum SHCONTF : ushort{ SHCONTF_CHECKING_FOR_CHILDREN = 0x0010, SHCONTF_FOLDERS = 0x0020, SHCONTF_NONFOLDERS = 0x0040, SHCONTF_INCLUDEHIDDEN = 0x0080, SHCONTF_INIT_ON_FIRST_NEXT = 0x0100, SHCONTF_NETPRINTERSRCH = 0x0200, SHCONTF_SHAREABLE = 0x0400, SHCONTF_STORAGE = 0x0800, SHCONTF_NAVIGATION_ENUM = 0x1000, SHCONTF_FASTITEMS = 0x2000, SHCONTF_FLATLIST = 0x4000, SHCONTF_ENABLE_ASYNC = 0x8000}[Flags]public enum SFGAO : uint{ CANCOPY = 0x00000001, CANMOVE = 0x00000002, CANLINK = 0x00000004, STORAGE = 0x00000008, CANRENAME = 0x00000010, CANDELETE = 0x00000020, HASPROPSHEET = 0x00000040, DROPTARGET = 0x00000100, CAPABILITYMASK = 0x00000177, ENCRYPTED = 0x00002000, ISSLOW = 0x00004000, GHOSTED = 0x00008000, LINK = 0x00010000, SHARE = 0x00020000, READONLY = 0x00040000, HIDDEN = 0x00080000, DISPLAYATTRMASK = 0x000FC000, STREAM = 0x00400000, STORAGEANCESTOR = 0x00800000, VALIDATE = 0x01000000, REMOVABLE = 0x02000000, COMPRESSED = 0x04000000, BROWSABLE = 0x08000000, FILESYSANCESTOR = 0x10000000, FOLDER = 0x20000000, FILESYSTEM = 0x40000000, HASSUBFOLDER = 0x80000000, CONTENTSMASK = 0x80000000, STORAGECAPMASK = 0x70C50008, PKEYSFGAOMASK = 0x81044000}public enum SHGDNF{ SHGDN_NORMAL = 0, SHGDN_INFOLDER = 0x1, SHGDN_FOREDITING = 0x1000, SHGDN_FORADDRESSBAR = 0x4000, SHGDN_FORPARSING = 0x8000}[StructLayout(LayoutKind.Explicit, Size = 264)]public struct STRRET{ [FieldOffset(0)] //One of the STRRET_* values public uint uType; [FieldOffset(4)] //must be freed by caller of GetDisplayNameOf public IntPtr pOleStr; // <FieldOffset(4)> Public pStr As IntPtr 'NOT USED [FieldOffset(4)] //Offset into SHITEMID public uint uOffset; [FieldOffset(4)] //Buffer to fill in (ANSI) public IntPtr cString;}[StructLayout(LayoutKind.Sequential, Pack = 4)]public struct PROPERTYKEY{ private readonly Guid _fmtid; private readonly uint _pid; public PROPERTYKEY(Guid fmtid, uint pid) { _fmtid = fmtid; _pid = pid; } public static readonly PROPERTYKEY PKEY_Software_InstallLocation = new PROPERTYKEY(new Guid("841E4F90-FF59-4D16-8947-E81BBFFAB36D"), 9); public static readonly PROPERTYKEY PKEY_ItemNameDisplay = new PROPERTYKEY(new Guid("B725F130-47EF-101A-A5F1-02608C9EEBAC"), 10); public static readonly PROPERTYKEY PKEY_Software_InstallDate = new PROPERTYKEY(new Guid("841E4F90-FF59-4D16-8947-E81BBFFAB36D"), 11);}[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public struct SHELLDETAILS{ int fmt; int cxChar; STRRET str;}[Flags]public enum SHCOLSTATEF{ SHCOLSTATE_DEFAULT = 0, SHCOLSTATE_TYPE_STR = 0x1, SHCOLSTATE_TYPE_INT = 0x2, SHCOLSTATE_TYPE_DATE = 0x3, SHCOLSTATE_ONBYDEFAULT = 0x10, SHCOLSTATE_SLOW = 0x20, SHCOLSTATE_EXTENDED = 0x40, SHCOLSTATE_SECONDARYUI = 0x80, SHCOLSTATE_HIDDEN = 0x100, SHCOLSTATE_PREFER_VARCMP = 0x200, SHCOLSTATE_PREFER_FMTCMP = 0x400, SHCOLSTATE_NOSORTBYFOLDERNESS = 0x800, SHCOLSTATE_VIEWONLY = 0x10000, SHCOLSTATE_BATCHREAD = 0x20000, SHCOLSTATE_NO_GROUPBY = 0x40000, SHCOLSTATE_FIXED_WIDTH = 0x1000, SHCOLSTATE_NODPISCALE = 0x2000, SHCOLSTATE_FIXED_RATIO = 0x4000,}[ ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214F2-0000-0000-C000-000000000046"),]public interface IEnumIDList{ [PreserveSig()] HRESULT Next(uint celt, out IntPtr rgelt, out int pceltFetched); [PreserveSig()] HRESULT Skip(uint celt); void Reset(); [return: MarshalAs(UnmanagedType.Interface)] IEnumIDList Clone();}[ ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214E6-0000-0000-C000-000000000046"),]public interface IShellFolder{ HRESULT ParseDisplayName(IntPtr hwnd, // IBindCtx pbc, IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName, [In, Out] ref uint pchEaten, out IntPtr ppidl, [In, Out] ref SFGAO pdwAttributes); HRESULT EnumObjects(IntPtr hwnd, SHCONTF grfFlags, out IEnumIDList ppenumIDList); HRESULT BindToObject(IntPtr pidl, //IBindCtx pbc, IntPtr pbc, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); HRESULT BindToStorage(IntPtr pidl, IntPtr pbc, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); HRESULT CompareIDs(IntPtr lParam, IntPtr pidl1, IntPtr pidl2); HRESULT CreateViewObject(IntPtr hwndOwner, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); HRESULT GetAttributesOf(uint cidl, IntPtr apidl, [In, Out] ref SFGAO rgfInOut); HRESULT GetUIObjectOf(IntPtr hwndOwner, uint cidl, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.SysInt, SizeParamIndex = 1)] IntPtr apidl, [In] ref Guid riid, [In, Out] ref uint rgfReserved, [MarshalAs(UnmanagedType.Interface)] out object ppv); HRESULT GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName); HRESULT SetNameOf(IntPtr hwnd, IntPtr pidl, [MarshalAs(UnmanagedType.LPWStr)] string pszName, SHGDNF uFlags, out IntPtr ppidlOut);}[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)][Guid("93F2F68C-1D1B-11d3-A30E-00C04F79ABD1")]public interface IShellFolder2 : IShellFolder{ #region IShellFolder overrides for COM/C# compatibility. [PreserveSig] new HRESULT ParseDisplayName(IntPtr hwnd, IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName, [In, Out] ref uint pchEaten, out IntPtr ppidl, [In, Out] ref SFGAO pdwAttributes); [PreserveSig] new HRESULT EnumObjects(IntPtr hwnd, SHCONTF grfFlags, out IEnumIDList ppenumIDList); [PreserveSig] new HRESULT BindToObject(IntPtr pidl, IntPtr pbc, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); [PreserveSig] new HRESULT BindToStorage(IntPtr pidl, IntPtr pbc, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); [PreserveSig] new HRESULT CompareIDs(IntPtr lParam, IntPtr pidl1, IntPtr pidl2); [PreserveSig] new HRESULT CreateViewObject(IntPtr hwndOwner, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); [PreserveSig] new HRESULT GetAttributesOf(uint cidl, IntPtr apidl, [In, Out] ref SFGAO rgfInOut); [PreserveSig] new HRESULT GetUIObjectOf(IntPtr hwndOwner, uint cidl, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.SysInt, SizeParamIndex = 1)] IntPtr apidl, [In] ref Guid riid, [In, Out] ref uint rgfReserved, [MarshalAs(UnmanagedType.Interface)] out object ppv); [PreserveSig] new HRESULT GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName); [PreserveSig] new HRESULT SetNameOf(IntPtr hwnd, IntPtr pidl, [MarshalAs(UnmanagedType.LPWStr)] string pszName, SHGDNF uFlags, out IntPtr ppidlOut); #endregion /// <summary> /// Returns the globally unique identifier (GUID) of the default search object for the folder. /// </summary> /// <param name="pguid">The GUID of the default search object.</param> /// <returns>Returns S_OK if successful, or a COM error value otherwise.</returns> [PreserveSig] HRESULT GetDefaultSearchGUID(out Guid pguid); /// <summary> /// Requests a pointer to an interface that allows a client to enumerate the available search objects. /// </summary> /// <param name="ppenum">The address of a pointer to an enumerator object's IEnumExtraSearch interface.</param> /// <returns>Returns S_OK if successful, or a COM error value otherwise.</returns> [PreserveSig] HRESULT EnumSearches([MarshalAs(UnmanagedType.Interface)] out object ppenum); /// <summary> /// Gets the default sorting and display columns. /// </summary> /// <param name="dwRes">Reserved. Set to zero.</param> /// <param name="pSort">A pointer to a value that receives the index of the default sorted column.</param> /// <param name="pDisplay">A pointer to a value that receives the index of the default display column.</param> /// <returns>Returns S_OK if successful, or a COM error value otherwise.</returns> [PreserveSig] HRESULT GetDefaultColumn(uint dwRes, out uint pSort, out uint pDisplay); /// <summary> /// Gets the default state for a specified column. /// </summary> /// <param name="iColumn">An integer that specifies the column number.</param> /// <param name="pcsFlags">A pointer to a value that contains flags that indicate the default column state. This parameter can include a combination of the following flags.</param> /// <returns>Returns S_OK if successful, or a COM error value otherwise.</returns> [PreserveSig] HRESULT GetDefaultColumnState(uint iColumn, out SHCOLSTATEF pcsFlags); /// <summary> /// Gets detailed information, identified by a property set identifier (FMTID) and a property identifier (PID), on an item in a Shell folder. /// </summary> /// <param name="pidl">A PIDL of the item, relative to the parent folder. This method accepts only single-level PIDLs. The structure must contain exactly one SHITEMID structure followed by a terminating zero. This value cannot be NULL.</param> /// <param name="pscid">A pointer to an SHCOLUMNID structure that identifies the column.</param> /// <param name="pv">A pointer to a VARIANT with the requested information. The value is fully typed. The value returned for properties from the property system must conform to the type specified in that property definition's typeInfo as the legacyType attribute.</param> /// <returns>Returns S_OK if successful, or a COM error value otherwise.</returns> [PreserveSig] HRESULT GetDetailsEx(IntPtr pidl, ref PROPERTYKEY pscid, [MarshalAs(UnmanagedType.Struct)] out object pv); /// <summary> /// Gets detailed information, identified by a column index, on an item in a Shell folder. /// </summary> /// <param name="pidl">PIDL of the item for which you are requesting information. This method accepts only single-level PIDLs. The structure must contain exactly one SHITEMID structure followed by a terminating zero. If this parameter is set to NULL, the title of the information field specified by iColumn is returned.</param> /// <param name="iColumn">The zero-based index of the desired information field. It is identical to the column number of the information as it is displayed in a Windows Explorer Details view.</param> /// <param name="psd">The zero-based index of the desired information field. It is identical to the column number of the information as it is displayed in a Windows Explorer Details view.</param> /// <returns>Returns S_OK if successful, or a COM error value otherwise.</returns> [PreserveSig] HRESULT GetDetailsOf(IntPtr pidl, uint iColumn, out SHELLDETAILS psd); /// <summary> /// Converts a column to the appropriate property set ID (FMTID) and property ID (PID). /// </summary> /// <param name="iColumn">The column ID.</param> /// <param name="pscid">A pointer to an SHCOLUMNID structure containing the FMTID and PID.</param> /// <returns>Returns S_OK if successful, or a COM error value otherwise.</returns> [PreserveSig] HRESULT MapColumnToSCID(uint iColumn, out PROPERTYKEY pscid);}


    • Edited by Castorix31 Monday, November 20, 2017 8:15 AM
    • Proposed as answer by Zhanglong WuMicrosoft contingent staff Thursday, November 30, 2017 9:51 AM

    Monday, November 20, 2017 8:10 AM

    (Video) How To Add An Outlet To A Finished Wall

Videos

1. How to Edit 🔥 Football Videos that STAND OUT
(Peter Sarellas)
2. How to remove and replace the battery in your AirTag — Apple Support
(Apple Support)
3. Mysql not showing in services solved | Install/remove of service denied
(United Top Tech)
4. How to set up and use your AirTag — Apple Support
(Apple Support)
5. How to use Find My on iPhone, iPad, and iPod touch | Apple Support
(Apple Support)
6. 3 Easy Ways To Make Your Air Conditioner Quieter
(The DIY HVAC Guy)

References

Top Articles
Latest Posts
Article information

Author: Virgilio Hermann JD

Last Updated: 08/10/2023

Views: 6067

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Virgilio Hermann JD

Birthday: 1997-12-21

Address: 6946 Schoen Cove, Sipesshire, MO 55944

Phone: +3763365785260

Job: Accounting Engineer

Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio

Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.