2 yanghao988 yanghao988 于 2014.12.19 17:21 提问

win7下登录屏蔽系统登录凭据

//cpp
//功能:实现自定义win7登录替换原有的window登录凭据,并屏蔽原来的登录.
#pragma once
#include "MyCredentailProviderFilter.h"
#include "Log.h"
CMyCredentailProviderFilter::CMyCredentailProviderFilter(void)
{
}

CMyCredentailProviderFilter::~CMyCredentailProviderFilter(void)
{
}

HRESULT CMyCredentailProviderFilter::Filter(
CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
DWORD dwFlags,
GUID* rgclsidProviders,
BOOL* rgbAllow, DWORD cProviders)
{
dwFlags;
WriteFileLog(L"CMyCredentailProviderFilter::Filter() called.");
MessageBox(NULL,"Filter called","Filter",MB_OK|MB_TOPMOST);
switch(cpus)
{
case CPUS_LOGON:
case CPUS_UNLOCK_WORKSTATION:
{
for(DWORD i = 0;i<cProviders;i++)
{
if(IsEqualGUID(rgclsidProviders[i],CLSID_PasswordCredentialProvider))
rgbAllow[i] = FALSE;
}
return S_OK;
}
break;
case CPUS_CHANGE_PASSWORD:
return E_NOTIMPL;
default:
return E_INVALIDARG;
}
}

HRESULT CMyCredentailProviderFilter::UpdateRemoteCredential(
const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsIn,
CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsOut)
{
pcpcsOut;
pcpcsIn;
return E_NOTIMPL;
}

//h
#pragma once
#include "common.h"
#include
class CMyCredentailProviderFilter : public ICredentialProviderFilter
{

public:
CMyCredentailProviderFilter();
__override ~CMyCredentailProviderFilter();
public:
//This section contains some COM boilerplate code

    // IUnknown
STDMETHOD_(ULONG, AddRef)()
{
    return _cRef++;
}

STDMETHOD_(ULONG, Release)()
{
    LONG cRef = _cRef--;
    if (!cRef)
    {
        delete this;
    }
    return cRef;
}

STDMETHOD (QueryInterface)(REFIID riid, void** ppv)
{
    HRESULT hr;
    if (IID_IUnknown == riid ||
        IID_ICredentialProviderFilter == riid)
    {
        *ppv = this;
        reinterpret_cast<IUnknown*>(*ppv)->AddRef();
        hr = S_OK;
    }
    else
    {
        *ppv = NULL;
        hr = E_NOINTERFACE;
    }
    return hr;
}

public:
friend HRESULT CSampleProvider_CreateInstance(REFIID riid, __deref_out void** ppv);

//Implementation of ICredentialProviderFilter
IFACEMETHODIMP Filter(
    CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 
    DWORD dwFlags,
    GUID* rgclsidProviders, 
    BOOL* rgbAllow, DWORD cProviders);

IFACEMETHODIMP UpdateRemoteCredential(
    const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsIn,
    CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsOut);

private:
LONG _cRef;

};
//dll.cpp
STDMETHOD (CreateInstance)(IUnknown* pUnkOuter, REFIID riid, void** ppv)
{
HRESULT hr;
if (!pUnkOuter)
{
if (IID_ICredentialProvider == riid)
{
hr = CSampleProvider_CreateInstance(riid, ppv);
WriteFileLog(L"IID_ICredentialProvider");
}
else
{
if (IID_ICredentialProviderFilter == riid)
{
hr = CSampleProvider_CreateInstance(riid, ppv);
WriteFileLog(L"IID_ICredentialProviderFilter");
}
else
{
hr = CSampleProvider_CreateInstance(riid, ppv);
WriteFileLog(L"IID_DEFAULT:CSampleProvider_CreateInstance");
}
}
}
else
{
hr = CLASS_E_NOAGGREGATION;
}
return hr;
}
//register.reg
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers{ACFC407B-266C-4085-8DAE-F3E276336E4B}]
@="SampleWrapExistingCredentialProvider"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Provider Filters{A5DA53F9-D475-4080-A120-910C4A739880}]
@="SampleWrapExistingCredentialProvider"

[HKEY_CLASSES_ROOT\CLSID{ACFC407B-266C-4085-8DAE-F3E276336E4B}]
@="SampleWrapExistingCredentialProvider"

[HKEY_CLASSES_ROOT\CLSID{ACFC407B-266C-4085-8DAE-F3E276336E4B}\InprocServer32]
@="SampleWrapExistingCredentialProvider.dll"
"ThreadingModel"="Apartment"
//问题1:
我的filter没有被调用.
//问题2:
STDMETHOD (CreateInstance)(IUnknown* pUnkOuter, REFIID riid, void** ppv)这个中我的两个IID_ICredentialProvider和IID_ICredentialProviderFilter需要在头文件中做改动马?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!