Esempio n. 1
0
        private static string ShellLinkToString(IShellLinkW shellLink)
        { 
            var pathBuilder = new StringBuilder(Win32Constant.MAX_PATH);
            shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH); 
 
            string title = null;
            // Need to use the property store to get the title for the link. 
            using (PROPVARIANT pv = new PROPVARIANT())
            {
                var propStore = (IPropertyStore)shellLink;
                PKEY pkeyTitle = PKEY.Title; 

                propStore.GetValue(ref pkeyTitle, pv); 
 
                // PKEY_Title should be an LPWSTR if it's not empty.
                title = pv.GetValue() ?? ""; 
            }

            var argsBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
            shellLink.GetArguments(argsBuilder, argsBuilder.Capacity); 

            // Path and title should be case insensitive. 
            // Shell treats arguments as case sensitive because apps can handle those differently. 
            return pathBuilder.ToString().ToUpperInvariant() + title.ToUpperInvariant() + argsBuilder.ToString();
        } 
Esempio n. 2
0
        private static JumpItem GetJumpItemForShellObject(object shellObject)
        { 
            var shellItem = shellObject as IShellItem2;
            var shellLink = shellObject as IShellLinkW; 
 
            if (shellItem != null)
            { 
                JumpPath path = new JumpPath
                {
                    Path = shellItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
                }; 
                return path;
            } 
 
            if (shellLink != null)
            { 
                var pathBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH);
                var argsBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetArguments(argsBuilder, argsBuilder.Capacity); 
                var descBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetDescription(descBuilder, descBuilder.Capacity); 
                var iconBuilder = new StringBuilder(Win32Constant.MAX_PATH); 
                int iconIndex;
                shellLink.GetIconLocation(iconBuilder, iconBuilder.Capacity, out iconIndex); 
                var dirBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetWorkingDirectory(dirBuilder, dirBuilder.Capacity);

                JumpTask task = new JumpTask 
                {
                    // Set ApplicationPath and IconResources, even if they're from the current application. 
                    // This means that equivalent JumpTasks won't necessarily compare property-for-property. 
                    ApplicationPath = pathBuilder.ToString(),
                    Arguments = argsBuilder.ToString(), 
                    Description = descBuilder.ToString(),
                    IconResourceIndex = iconIndex,
                    IconResourcePath = iconBuilder.ToString(),
                    WorkingDirectory = dirBuilder.ToString(), 
                };
 
                using (PROPVARIANT pv = new PROPVARIANT()) 
                {
                    var propStore = (IPropertyStore)shellLink; 
                    PKEY pkeyTitle = PKEY.Title;

                    propStore.GetValue(ref pkeyTitle, pv);
 
                    // PKEY_Title should be an LPWSTR if it's not empty.
                    task.Title = pv.GetValue() ?? ""; 
                } 

                return task; 
            }

            // Unsupported type?
            Debug.Assert(false); 
            return null;
        }