Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent an app from being pinned in Windows 7?

I am trying to prevent the user from pinning my .NET app to the taskbar. I've found some code on the Old New Thing that does just that. However, it is in C++.

#include <shellapi.h>
#include <propsys.h>
#include <propkey.h>

HRESULT MarkWindowAsUnpinnable(HWND hwnd)
{
 IPropertyStore *pps;
 HRESULT hr = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps));
 if (SUCCEEDED(hr)) {
  PROPVARIANT var;
  var.vt = VT_BOOL;
  var.boolVal = VARIANT_TRUE;
  hr = pps->SetValue(PKEY_AppUserModel_PreventPinning, var);
  pps->Release();
 }
 return hr;
}


BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
 MarkWindowAsUnpinnable(hwnd);
 return TRUE;
}

I am having very little luck converting it to c#. Can someone help?

like image 452
AngryHacker Avatar asked Jun 16 '11 20:06

AngryHacker


People also ask

How do I remove a pinned app from my desktop?

To pin apps to the taskbar Note: To remove a pinned app from the taskbar, right-click the app icon, then select Unpin from taskbar.

What is the use of pinning feature in Windows 7?

Windows 7 allows you to pin favorite programs to the Taskbar for quicker-easy access. The icons for programs pinned to the Taskbar can be arranged or rearranged by clicking and dragging them in any order you wish.


1 Answers

You can download the Windows API Code Pack which has the necessary p/invoke calls you need to translate the code in your post to C#.

Either use the library in whole or find the specific calls and definitions you require (search it for SHGetPropertyStoreForWindow and then its other dependencies).

like image 191
Andrei Avatar answered Sep 28 '22 08:09

Andrei