如何防止应用程序被固定在Windows 7中?

Ang*_*ker 5 .net c# c++ windows-7 pinning

我试图阻止用户将我的.NET应用程序固定到任务栏.我在Old New Thing上发现了一些代码.但是,它是在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;
}
Run Code Online (Sandbox Code Playgroud)

我很难将它转换为c#.有人可以帮忙吗?

And*_*rei 8

您可以下载Windows API代码包,该代码包具有将帖子中的代码转换为C#所需的必要p/invoke调用.

要么整体使用库,要么找到所需的特定调用和定义(搜索它SHGetPropertyStoreForWindow,然后搜索其他依赖项).