public static string GetAppUserModelIdPropertyForHandle(IntPtr hWnd) { string aumid = string.Empty; IPropertyStore propStore; PropVariant prop; var g = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"); SHGetPropertyStoreForWindow(hWnd, ref g, out propStore); PROPERTYKEY PKEY_AppUserModel_ID = new PROPERTYKEY { fmtid = new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), pid = 5 }; if (propStore != null) { propStore.GetValue(PKEY_AppUserModel_ID, out prop); try { aumid = prop.Value.ToString(); } catch { } prop.Clear(); } return(aumid); }
public int OnPropertyValueChanged(string deviceId, PROPERTYKEY key) { var friendlyName = PROPERTYKEY.DeviceProperties.FriendlyName; if (key.Guid == friendlyName.Guid && (key.Id == friendlyName.Id || key.Id == PROPERTYKEY.DeviceProperties.Description.Id)) { this.NameChanged?.Invoke(deviceId); return(0); } var iconPath = PROPERTYKEY.DeviceProperties.IconPath; if (key.Guid == iconPath.Guid && key.Id == iconPath.Id) { this.IconPathChanged?.Invoke(deviceId); return(0); } var format = PROPERTYKEY.DeviceProperties.DeviceFormat; if (key.Guid == format.Guid && key.Id == format.Id) { this.FormatChanged?.Invoke(deviceId); } return(0); }
public void Initialize() { string shortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "Intelligent Naval Gun.lnk"); if (!File.Exists(shortcut)) { // Find the path to the current executable string exePath = Process.GetCurrentProcess().MainModule.FileName; var newShortcut = (IShellLinkW) new CShellLink(); // Create a shortcut to the exe newShortcut.SetPath(exePath); newShortcut.SetArguments(""); // Open the shortcut property store, set the AppUserModelId property var newShortcutProperties = (IPropertyStore)newShortcut; using (var appId = new PROPVARIANT(aumid)) { var AUMID_KEY = new PROPERTYKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5); newShortcutProperties.SetValue(AUMID_KEY, appId); newShortcutProperties.Commit(); } // Commit the shortcut to disk var newShortcutSave = (IPersistFile)newShortcut; newShortcutSave.Save(shortcut, true); } ToastNotificationManager.History.Clear(aumid); }
int IShellFolder2.GetDetailsEx(IntPtr pidl, PROPERTYKEY pkey, out object pv) { // If we have no pidl, we cannot get details. if (pidl == IntPtr.Zero) { pv = null; return(WinError.E_INVALIDARG); } // todo If the item is not a folder and the property key is PKEY_PropList_PreviewDetails // we need to return a string like: // "prop:Microsoft.SDKSample.AreaSize;Microsoft.SDKSample.NumberOfSides;Microsoft.SDKSample.DirectoryLevel"); // to indicate what to show in the details pane. /* * if (!pfIsFolder && IsEqualPropertyKey(*pkey, PKEY_PropList_PreviewDetails)) * { * // This proplist indicates what properties are shown in the details pane at the bottom of the explorer browser. * pv->vt = VT_BSTR; * pv->bstrVal = SysAllocString(L"prop:Microsoft.SDKSample.AreaSize;Microsoft.SDKSample.NumberOfSides;Microsoft.SDKSample.DirectoryLevel"); * hr = pv->bstrVal ? S_OK : E_OUTOFMEMORY; * }*/ // Get the detail todo rename pv = GetItemColumnValue(pidl, pkey); // We're done. return(WinError.S_OK); }
/// <summary>Initializes a new instance of the <see cref="PropertyDescription"/> class.</summary> /// <param name="propkey">A valid <see cref="PROPERTYKEY"/>.</param> public PropertyDescription(PROPERTYKEY propkey) { key = propkey; if (PSGetPropertyDescription(propkey, typeof(IPropertyDescription).GUID, out var ppv).Succeeded) { iDesc = (IPropertyDescription)ppv; } }
internal void SetExpected(EDataFlow dataflow, ERole role, string deviceId, int newState, PROPERTYKEY propertyKey) { _dataFlow = dataflow; _role = role; _deviceId = deviceId; _newState = newState; _propertyKey = propertyKey; }
public PropVariant GetPropertyValue(PROPERTYKEY pkey) { //TODO: Remove Parameter Type var pvar = new PropVariant(); var isi2 = (IShellItem2)ComInterface; isi2.GetProperty(ref pkey, pvar); return(pvar); }
/// <summary>Tries to create a <see cref="PropertyDescription"/> instance from a specified property key.</summary> /// <param name="propkey">The property key.</param> /// <param name="desc"> /// An associated instance of <see cref="PropertyDescription"/> or <see langword="null"/> if the PROPERTYKEY does not exist in the /// schema subsystem cache. /// </param> /// <returns><see langword="true"/> if the supplied property key exists; otherwise <see langword="false"/>.</returns> public static bool TryCreate(PROPERTYKEY propkey, out PropertyDescription desc) { if (PSGetPropertyDescription(propkey, typeof(IPropertyDescription).GUID, out var ppv).Succeeded) { desc = new PropertyDescription((IPropertyDescription)ppv, propkey); return(true); } desc = null; return(false); }
private static IShellLink CreateShellLink(string title, string path, string arguments, string icon_path, int icon_pos) { try { IShellLink shell_link = (IShellLink)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID.ShellLink)); shell_link.SetPath(path); if (!string.IsNullOrEmpty(arguments)) { shell_link.SetArguments(arguments); } if (!string.IsNullOrEmpty(icon_path)) { shell_link.SetIconLocation(icon_path, icon_pos); } IntPtr pps; Guid ipsiid = CLSID.IPropertyStore; Marshal.QueryInterface(Marshal.GetIUnknownForObject(shell_link), ref ipsiid, out pps); IPropertyStore property_store = (IPropertyStore)Marshal.GetTypedObjectForIUnknown(pps, typeof(IPropertyStore)); PROPVARIANT propvar = new PROPVARIANT(); propvar.SetString(title); // PKEY_Title PROPERTYKEY PKEY_Title = new PROPERTYKEY(); PKEY_Title.fmtid = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"); PKEY_Title.pid = 2; property_store.SetValue(ref PKEY_Title, ref propvar); property_store.Commit(); IntPtr psl; Guid psliid = CLSID.IShellLinkW; Marshal.QueryInterface(Marshal.GetIUnknownForObject(shell_link), ref psliid, out psl); IShellLink link = (IShellLink)Marshal.GetTypedObjectForIUnknown(psl, typeof(IShellLink)); propvar.Clear(); Marshal.ReleaseComObject(property_store); property_store = null; Marshal.ReleaseComObject(shell_link); shell_link = null; return(link); } catch (COMException e) { Logger.Error("Error createing shell link: {0}\n{1}", e.Message, e.StackTrace); } return(null); }
/// <summary> /// Factory to create <see cref="Collumns"/> (All it does is assign values) /// </summary> /// <param name="column">Collumns.Name = column.pszText</param> /// <param name="pkey"></param> /// <param name="type">Collumns.pkey = pkey</param> /// <param name="isColumnHandler">Collumns.IsColumnHandler = isColumnHandler</param> /// <param name="minWidth">Collumns.MinWidth = minWidth</param> /// <returns>The new Collumns</returns> public static Collumns ToCollumns(this LVCOLUMN column, PROPERTYKEY pkey, Type type, Boolean isColumnHandler, Int32 minWidth) { return(new Collumns { pkey = pkey, Name = column.pszText, Width = minWidth, IsColumnHandler = isColumnHandler, CollumnType = type, MinWidth = minWidth }); }
public void PSGetNameFromPropertyKeyTest() { var pkey = new PROPERTYKEY { fmtid = new Guid("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"), pid = 5 }; var hr = PSGetNameFromPropertyKey(ref pkey, out var str); Assert.That(hr.Succeeded); Assert.That(str, Is.Not.Null); TestContext.WriteLine(str); }
public PropVariant GetPropertyValue(PROPERTYKEY pkey) { var pvar = new PropVariant(); var isi2 = (IShellItem2)this.ComInterface; if (isi2 == null) { return(PropVariant.FromObject(null)); } isi2.GetProperty(ref pkey, pvar); return(pvar); }
private string GetItemColumnValue(IntPtr pidl, PROPERTYKEY propertyKey) { // Get the value for the property key. var item = GetChildItem(PidlManager.PidlToIdlist(pidl)); var column = ((DefaultNamespaceFolderView)lazyFolderView.Value).Columns.FirstOrDefault(c => { var key = c.PropertyKey.CreateShellPropertyKey(); return(key.fmtid == propertyKey.fmtid && key.pid == propertyKey.pid); }); var detail = ((DefaultNamespaceFolderView)lazyFolderView.Value).GetItemDetail(item, column); return(detail.ToString()); }
private object GetPropertyValue(IPropertyStore propertyStore, PROPERTYKEY propertyKey) { object returnObj = null; PROPVARIANT propVariant; var result = propertyStore.GetValue(ref propertyKey, out propVariant); AssertCoreAudio.IsHResultOk(result); var vType = (VarEnum)propVariant.vt; if (vType == VarEnum.VT_EMPTY) { return(null); } switch (vType) { case VarEnum.VT_BOOL: returnObj = propVariant.Data.AsBoolean; break; case VarEnum.VT_UI4: returnObj = propVariant.Data.AsUInt32; break; case VarEnum.VT_LPWSTR: case VarEnum.VT_CLSID: returnObj = Marshal.PtrToStringUni(propVariant.Data.AsStringPtr); break; case VarEnum.VT_BLOB: returnObj = propVariant.Data.AsFormatPtr; break; } if (propertyKey.fmtid == PropertyKeys.PKEY_AudioEngine_DeviceFormat || propertyKey.fmtid == PropertyKeys.PKEY_AudioEngine_OEMFormat) { Assert.AreEqual(VarEnum.VT_BLOB, vType, "The device format property was not of varient type VT_BLOB."); var format = (WAVEFORMATEX)Marshal.PtrToStructure((IntPtr)returnObj, typeof(WAVEFORMATEX)); if (format.nChannels != 0 && format.nSamplesPerSec != 0 && format.wBitsPerSample != 0) { Assert.AreEqual(format.nChannels * format.nSamplesPerSec * format.wBitsPerSample, format.nAvgBytesPerSec * 8, "The wave format was not valid."); } } return(returnObj); }
public PropVariant GetPropertyValue(PROPERTYKEY pkey, Type type) { var pvar = new PropVariant(); var comObject = this.ComInterface; var isi2 = (IShellItem2)comObject; if (isi2 == null) { return(PropVariant.FromObject(null)); } isi2.GetProperty(ref pkey, pvar); Marshal.ReleaseComObject(comObject); return(pvar); }
private string GetProperty(ref PROPERTYKEY key) { string prop = null; try { device.OpenPropertyStore(STGM.READ, out IPropertyStore store); if (store != null) { store.GetValue(ref key, out PROPVARIANT propvariant); prop = propvariant.GetPwszValAsString(); } } catch {} return(prop ?? string.Empty); }
public static string?GetString(this IPropertyStore propertyStore, PROPERTYKEY key) { if (propertyStore.GetValue(key, out var value).Failed) { return(null); } try { return(Marshal.PtrToStringUni(value.pwszVal)); } finally { PInvoke.PropVariantClear(ref value); } }
public string GetDeviceName(IMMDevice device) { IPropertyStore device_prop; device.OpenPropertyStore(0, out device_prop); PROPERTYKEY prop_key = new PROPERTYKEY(); prop_key.pid = 2; prop_key.fmtid = PropertyKeys.PKEY_DeviceInterface_FriendlyName; PROPVARIANT prop_value; device_prop.GetValue(ref prop_key, out prop_value); string device_name = Marshal.PtrToStringAuto(prop_value.Data.AsStringPtr); return(device_name); }
internal ShellPropertyDescription(PROPERTYKEY propertyKey) { Contract.Requires <ArgumentNullException>(propertyKey != null); this.propertyKey = propertyKey; var guid = new Guid(PropertySystemIID.IPropertyDescription); var hr = PropertySystemNativeMethods.PSGetPropertyDescription(ref this.propertyKey, ref guid, out this.propertyDescriptionNative); if (HRESULT.Failed(hr)) { throw new ShellException( String.Format(ErrorMessages.ShellPropertyDescriptionError, propertyKey), hr); } }
public int OnPropertyValueChanged(string deviceId, PROPERTYKEY key) { PROPERTYKEY friendlyName = PROPERTYKEY.DeviceProperties.FriendlyName; if (key.Guid == friendlyName.Guid) { this.NameChanged?.Invoke(deviceId); return(0); } PROPERTYKEY iconPath = PROPERTYKEY.DeviceProperties.IconPath; if (key.Guid == iconPath.Guid) { this.IconPathChanged?.Invoke(deviceId); } return(0); }
int IShellFolder2.MapColumnToSCID(uint iColumn, out PROPERTYKEY pscid) { // Get the detail columns. var columns = ((DefaultNamespaceFolderView)lazyFolderView.Value).Columns; // If we've been asked for a column we don't have, return failure. if (iColumn >= columns.Count) { pscid = new PROPERTYKEY(); return(WinError.E_FAIL); } // Get the column property id. pscid = columns[(int)iColumn].PropertyKey.CreateShellPropertyKey(); // We've mapped the column. return(WinError.S_OK); }
public static string[] GetStringArray(this IPropertyStore propertyStore, PROPERTYKEY key) { if (propertyStore.GetValue(key, out var value).Failed) { return(Array.Empty <string>()); } try { return(Enumerable.Range(0, (int)value.calpwstr.cElems) .Select(x => Marshal.PtrToStringUni(Marshal.ReadIntPtr(value.calpwstr.pElems, x * IntPtr.Size)) !) .ToArray()); } finally { PInvoke.PropVariantClear(ref value); } }
void IMMNotificationClient.OnPropertyValueChanged(string pwstrDeviceId, PROPERTYKEY key) { TraceLine($"OnPropertyValueChanged {pwstrDeviceId} {key.fmtid},{key.pid}"); if (_devices.TryFind(pwstrDeviceId, out IAudioDevice dev)) { if (PropertyKeys.PKEY_AudioEndPoint_Interface.Equals(key)) { // We're racing with the system, the device may not be resolvable anymore. try { ((AudioDevice)dev).DevicePropertiesChanged(_enumerator.GetDevice(dev.Id)); } catch (Exception ex) { TraceLine($"{ex}"); } } } }
private double GetDoubleProperty(ILocationReport report, PROPERTYKEY propkey) { double val = double.NaN; PROPVARIANT pv = new PROPVARIANT(); using (pv) { if (0 == report.GetValue(ref propkey, pv)) { if (pv.vt == VarEnum.VT_R8) { val = (double)pv.GetValue(); } } } return(val); }
public static T GetValue <T>(this IPropertyStore propStore, PROPERTYKEY key) { PropVariant pv = default(PropVariant); try { pv = propStore.GetValue(ref key); switch (pv.varType) { case VarEnum.VT_LPWSTR: return((T)Convert.ChangeType(Marshal.PtrToStringUni(pv.pwszVal), typeof(T))); default: throw new NotImplementedException(); } } finally { Ole32.PropVariantClear(ref pv); } }
private string GetStringProperty(ILocationReport report, PROPERTYKEY propkey) { string val = String.Empty; PROPVARIANT pv = new PROPVARIANT(); using (pv) { int hr = report.GetValue(ref propkey, pv); if (0 == hr) { if (pv.vt == VarEnum.VT_LPWSTR) { val = (string)pv.GetValue(); } } } return(val); }
public ImageSource GetIconSource() { ImageSource icon = null; PROPERTYKEY iconPathKey = PROPERTYKEY.DeviceProperties.IconPath; string iconPath = this.GetProperty(ref iconPathKey); if (string.IsNullOrEmpty(iconPath)) { return(null); } //try to extract the icon from DLL first since it's the most common location of the icons try { string[] endpointIconPath = iconPath.Split(","); if (endpointIconPath.Length < 2) { throw new Exception("Resource path is invalid"); } string path = endpointIconPath[0]; int id = int.Parse(endpointIconPath[1], CultureInfo.InvariantCulture); App.Current.Dispatcher.Invoke(() => icon = IconHelper.GetFromDll(path, id)); } catch { } //try to extract the icon from file path if (icon == null) { try { App.Current.Dispatcher.Invoke(() => icon = IconHelper.GetFromFilePath(iconPath)); } catch (Exception e) { Logger.Error($"Failed to extract device icon from the file path: [{iconPath}]", e); } } return(icon); }
/// <summary> /// Get the item type from the specified <see cref="IShellItem2" />. /// </summary> /// <param name="shellItem"><see cref="IShellItem2" />.</param> /// <returns>Item type string.</returns> private static string GetItemType(IShellItem2 shellItem) { Contract.Requires(shellItem != null); Contract.Ensures(Contract.Result <string>() != null); var itemTypeKey = new PROPERTYKEY(new Guid("28636AA6-953D-11D2-B5D6-00C04FD918D0"), 11); string result; var hr = shellItem.GetString(ref itemTypeKey, out result); if (HRESULT.Failed(hr)) { try { result = Path.GetExtension(GetParsingName(shellItem)); } catch (Exception) { result = String.Empty; } } return(result); }
public void GetGroupColInfo(out PROPERTYKEY pk, out bool Asc) { try { IFolderView2 ifv2 = GetFolderView2(); ifv2.GetGroupBy(out pk, out Asc); } catch (Exception) { pk = new PROPERTYKEY(); Asc = false; } }
internal static extern uint PSGetNameFromPropertyKey( ref PROPERTYKEY propkey, [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppszCanonicalName);
private static extern int GetColumnInfobyPK(IShellView view, bool isAll, PROPERTYKEY pk, out CM_COLUMNINFO res);
private static extern void GetColumnbyIndex(IShellView view, bool isAll, int index, out PROPERTYKEY res);
public void SetColInView(PROPERTYKEY pk, bool Remove) { if (!Remove) { PROPERTYKEY[] pkk = new PROPERTYKEY[AvailableVisibleColumns.Length + 1]; for (int i = 0; i < AvailableVisibleColumns.Length; i++) { pkk[i] = AvailableVisibleColumns[i].pkey; } pkk[AvailableVisibleColumns.Length] = pk; SetColumnInShellView(GetShellView(), AvailableVisibleColumns.Length + 1, pkk); AvailableVisibleColumns = AvailableColumns(GetShellView(), false); } else { PROPERTYKEY[] pkk = new PROPERTYKEY[AvailableVisibleColumns.Length - 1]; int j = 0; for (int i = 0; i < AvailableVisibleColumns.Length; i++) { if (!(AvailableVisibleColumns[i].pkey.fmtid == pk.fmtid && AvailableVisibleColumns[i].pkey.pid == pk.pid)) { pkk[j] = AvailableVisibleColumns[i].pkey; j++; } } SetColumnInShellView(GetShellView(), AvailableVisibleColumns.Length - 1, pkk); AvailableVisibleColumns = AvailableColumns(GetShellView(), false); } }
/// <summary>Creates a <see cref="PropertyDescription"/> instance from a specified property key.</summary> /// <param name="propkey">The property key.</param> /// <returns>An associated instance of <see cref="PropertyDescription"/> or <see langword="null"/> if the PROPERTYKEY does not exist in the schema subsystem cache.</returns> public static PropertyDescription Create(PROPERTYKEY propkey) => PSGetPropertyDescription(propkey, typeof(IPropertyDescription).GUID, out var ppv).Succeeded ? new PropertyDescription((IPropertyDescription)ppv, propkey) : null;
/// <summary>Initializes a new instance of the <see cref="PropertyDescription"/> class.</summary> /// <param name="propertyDescription">The property description.</param> /// <param name="pkey">The associated property key.</param> protected internal PropertyDescription(IPropertyDescription propertyDescription, PROPERTYKEY?pkey = null) { iDesc = propertyDescription; key = pkey ?? iDesc.GetPropertyKey(); }
/// <summary> /// Sets the column in which will be sorted /// </summary> /// <param name="pk">The propertykey that identifies column</param> /// <param name="Order">The sort order</param> public void SetSortCollumn(PROPERTYKEY pk, SORT Order) { IFolderView2 ifv2 = GetFolderView2(); SORTCOLUMN sc = new SORTCOLUMN(); sc.propkey = pk; sc.direction = Order; IntPtr scptr = Marshal.AllocHGlobal(Marshal.SizeOf(sc)); Marshal.StructureToPtr(sc, scptr, false); ifv2.SetSortColumns(scptr, 1); Marshal.FreeHGlobal(scptr); }
internal PropertyStoreProperty(PROPERTYKEY key, PropVariant value) { _PropertyKey = key; _PropValue = value; }
/// <summary> /// Sets the column in which current view will be grouped /// </summary> /// <param name="pk">The propertykey that identifies column</param> /// <param name="Asc">true-ascesing order; false- descesing order</param> public void SetGroupCollumn(PROPERTYKEY pk, bool Asc) { IFolderView2 ifv2 = GetFolderView2(); IntPtr scptr = Marshal.AllocHGlobal(Marshal.SizeOf(pk)); Marshal.StructureToPtr(pk, scptr, false); ifv2.SetGroupBy(scptr, Asc); Marshal.FreeHGlobal(scptr); }