Windows Vista Sample Credential Providers Overview 中文翻译

开发瀚海电脑锁软件找到了这个文档,全是英文的,只翻译了一部分放上来。鸟语不好,将就看吧。

 

 

The SampleCredentialProvider Codebase

The SampleCredentialProvider project provides a working baseline credential provider. This sample is hardcoded to expose two accounts: Administrator and Guest.  The following screenshot shows what this might look like on a domain joined machine.

 

Project Structure

The SampleCredentialProvider project includes a small set of files, each with their own purpose:

 

SampleCredentialProvider项目包含了一小部分文件,每一文件都有它们自己的用途。

 

File[s](文件)

Purpose(用途)

common.h

Describes the UI and layout of the credentials. Edit this file to change the number and type of UI elements in each credential tile.

 

描述了凭据的界面和布局。编辑这个文件来改变每一个凭据块的UI元素的数据和类型

CSampleCredential.h/.cpp

Defines the behavior of a credential tile. Edit these files to change the way a tile responds to user input.

 

定义了凭据视窗的行为,编辑这些文件来改变视窗的样式以响应用户的输入

CSampleProvider.h/.cpp

Defines the behavior of the credential provider, which typically manages one or more CSampleCredentials. Edit this file to change the way credentials are enumerated.

 

定义了凭据提供程序的行为,通常管理一个或多个CSampleCredentials,编辑这个文件来改变列举凭据的方式。

dll.h/.cpp, samplecredentialprovider.def

Fulfills baseline support for COM server and DLL requirements. You shouldn’t need to edit these files.

 

COM服务和DLL必需的基础支持,你应不需要修改这些文件。

guid.h/.cpp

Defines the provider’s GUID. You’ll need to edit guid.h to reference your unique GUID.

 

定义了提供者的GUID,你需要编辑guid.h头文件来引用你唯一的GUID。

helpers.h/.cpp

Provides utility methods for working with UNICODE strings and auth packages. You shouldn’t need to edit these files.

 

为UNICODE字符串和auth packages提供了实用方法,你可能不需要修改这些文件。

 

Register.reg, Unregister.reg

Registers and unregisters the sample credential provider, respectively. You’ll need to edit these files to use the GUID from guid.h wherever a GUID appears. You’ll also need to edit the Register.reg file to reflect the name of your object (the first two registry keys) and the name of the DLL (the third registry key).

 

注册或注销这个凭据提供示例。用guid.h文件文件中的GUID来修改这些文件中任何使用的GUID.你还需要修改Register.reg文件来指名你项目的名称(前两个注册表项)和DLL(第三个注册表项)的名称。

 

resource.h, resources.rc

Manages provider resources, such as the tile image. Edit these files if you want to add more resources, such as images, to the credential provider.

 

管理提供程序的资源,例如视窗的图片,如果你需要添加更多的资源到凭据提供程序,那么就编辑这个文件

tileimage.bmp

The image to display on the credential tile. Edit this file (or add different images) to change the image that appears in the tile.

 

在凭据视窗显示这个图片,编辑这个图片(或者添加不同的图片)来改变出现在凭据视窗的图片。

Common Tasks For Extending SampleCredentialProvider

 

SampleCredentialProvider常见任务的扩展

 

 

Since SampleCredentialProvider provides a great baseline for developing custom providers, it is recommended that you customize it to meet your needs, rather than starting from scratch. The following steps will walk you through the process of customizing the SampleCredentialProvider project that is common to all extensions.

 

SampleCredentialProvider提供了一个开发自定义providers的基础,推荐你在这个基础上通过定制来满足你的需求,而不是从头开始。以下步骤将带领您完成整个定制过程samplecredentialprovider项目对于所有的扩展都是通用的

 

 

We’ll use “MyCredentialProvider” as the new project name, so be sure to change it to reflect the name you want to use. We’re also not going to rename any of the folders or files to reflect the name unless it is required to build successfully, so this may be something you choose to do once you’re comfortable with the codebase.

 

我们将使用MyCredentialProvider作为新项目的名称,所以请修改你想要使用的名字 ,我们也不会修改任何文件夹或文件的名字,除非为了编译成功而必须这样做,所以这可能是一次你选择的最安逸的代码库。

 

Please note that these samples are intended to be run against the RTM version of Windows Vista.  They should be compiled against the RTM version of the Windows Vista SDK.

 

请注意,这些示例是针对Windows Vista RTM版本,它们应该在RTM版本中Windows Vista SDK下编译

 

1.    Set up Visual Studio 2005 in Tools | Options to use the executables, includes, and libs from the SDK instead of the ones shipped with VS.  For more info on how to do this, see ReleaseNotes.Htm in the root of the SDK directory.

在Visual Studio 2005的工具|选项中设置使用的可执行文件,从SDK包含libs,而不是与VS运库。对于如何做到这一点的更多资讯,请参阅SDK目录的ReleaseNotes.Htm。,

 

2.    In the SampleCredentialProvider folder, double-click the SampleCredentialProvider.sln to open it in Visual Studio 2005.

在SampleCredentialProvider文件夹中双击SampleCredentialProvider.sln,使其在Visual Studio 2005打开。

 

3.    In the Solution Explorer, right-click the SampleCredentialProvider project node and select Rename. Change the name to “MyCredentialProvider” and press Enter to lock in.

在解决方案资源管理器中,右键点击SampleCredentialProvider工程节点,并选择重命名,将名称修改为MyCredentialProvider后,键入回车。

 

4.    In the Solution Explorer, right-click the MyCredentialProvider project node and select Properties. This will launch the MyCredentialProvider Property Pages dialog.

在解决方案资源管理器中,右键点击SampleCredentialProvider工程节点,并选择属性,这将打开MyCredentialProvider 属性页对话框。

 

5.    In the left tree view, select the Configuration Properties | C/C++ node.

在左边的树视图中,选择配置属性| C/C++ 节点.

6.    Make sure the path to your Vista SDK include directory is included in Additional Include Directories. On a default install it ends up at “C:\Program Files\Microsoft SDKs\Windows\v1.0\Include”.

确保你的Vista SDK include目录被添加到Additional Include Directories默认安装完成后在“C:\Program Files\Microsoft SDKs\Windows\v1.0\Include”。

 

7.    In the left tree view, select the Configuration Properties | Linker node to display the general properties of the linker configuration.

在左边的树视图中,选择配置属性| Linker 节点.显示链接配置的一般属性。

 

8.    Make sure the path to your Vista SDK library directory is included in Additional Library Directories. On a default install it ends up at “C:\Program Files\Microsoft SDKs\Windows\v1.0\Lib".

9.    确保你的Vista SDK library目录被包含Additional Library Directories.中,默认安装结束后,它们在“C:\Program Files\Microsoft SDKs\Windows\v1.0\Lib".

 

10. Press OK to dismiss the dialog.

 

点击确定退出对话框。

 

11. Open samplecredentialprovider.def. Change “SAMPLECREDENTIALPROVIDER.DLL” to “MYCREDENTIALPROVIDER.DLL”. Save samplecredentialprovider.def.

 

打开samplecredentialprovider.def文件,把“SAMPLECREDENTIALPROVIDER.DLL”修改为“MYCREDENTIALPROVIDER.DLL”,保存samplecredentialprovider.def文件。

 

12. Open guid.h. Replace the GUID in DEFINE_GUID with a unique one. You can generate a unique GUID from Tools | Create GUID. Be sure to remember it for later. Save guid.h.

打开guid.h文件,将 DEFINE_GUID替换为一个唯一的GUID,你可以使用Tools | Create GUID产生一个新的GUID,当然你要记住这个GUID为以后使用。保存guid.h。

 

13. Open Register.reg in notepad or Visual Studio (do not execute it in Explorer). Replace the GUIDs in each registry key with the one created in the last step. Also change “sampleprovider” to “MyCredentialProvider” as well as "SampleCredentialProvider.dll" to "MyCredentialProvider.dll". Save Register.reg.

使用记事本或Visual Studio (不要在Explorer(资源管理器中)执行这个文件)打开Register.reg.使用最后一步创建的GUID替换每一个注册表项的GUID,将“sampleprovider” 改为 “MyCredentialProvider”,以及"SampleCredentialProvider.dll" 改为 "MyCredentialProvider.dll",保存Register.reg.

 

14. Open Unregister.reg in notepad or Visual Studio (do not execute it in Explorer). Replace the GUID in the registry key with the one used in the Register.reg. Save Unregister.reg.

使用记事本或Visual Studio (不要在Explorer(资源管理器中)执行这个文件)打开Unregister.reg文件,使用在Register.reg文件使用的GUID替换注册表项。

15. Select Build | Build Solution. If there are any build errors, review the steps above.

选择Build | Build Solution.如果出现任何编译错误,请回顾以上的步骤。

 

16. Copy the freshly built MyCredentialProvider.dll to the System32 directory of the test machine.

将最新建立的MyCredentialProvider.dll复制到测试机的System32目录。

 

17. Copy Register.reg to the test machine and run it from Explorer to register the credential provider.

将Register.reg复制到测试用,使用Exploere(资源管理器)运行这个注册表以注册凭据提供程序。

 

18. From the Start Menu, select the option to switch users.

使用开始按钮,选择切换用户选项

 

19. The login screen should now have an extra Administrator and Guest account.  If all you see is one large tile, click Switch User to see the list of tiles.

登陆界面现在应该显示额外的Administrator Guest帐户。如果你看到一个大的用户框。点击切换用户显示用户框列表。

20. You should be able to log in using the newly created Administrator account tile. The Guest account may or may not be enabled due to the security settings of your system.

你应该能够使用新创建的Administrator帐户框登陆系统。由于系统的安全设置Guest帐户可能不会被激活,

21. If you want to remove the sample, copy Unregister.reg to the test machine and run it to unregister the credential provider.

如果你想要移除这个示例,复制Unregister.reg文件到测试机,运行它将会卸载凭据提供程序。

Tips & Tricks方法与技巧

The following are some tips & tricks that can help you during the development cycle. These are useful to keep in mind when reviewing the other samples covered later in this document.

下面的一些方法与技巧能够在开发期间帮助到你。记住这些是有用处的。这涵盖了这个文档中后面的其它示例

Automating The Deployment Process自动部署过程

If you are developing on a test machine to begin with, you can automate the DLL deployment process of by adding a Post-Build Event that automatically copies the output DLL to the System32 directory. For example, you can go to the Configuration Properties | Build Events | Post-Build Event tab of the project’s Property Pages dialog and set the following for Command Line:

 

copy "$(OutDir)\$(ProjectName).dll" %systemroot%\system32 /Y

 

However, be careful when performing a second build since the Post-Build Event only occurs after a successful build, and Visual C++ will skip the build process if the binaries are already up-to-date.

 

如果你开始在一个测试机开发,你可以自动部署DLL通过添加Post-Build Event(生成后事件),那会DLL复制到System32目录。例如,你可以去配置属性|生成事件|生成后事件项目的属性页“对话框的”选项卡,并设置以下命令行:

copy "$(OutDir)\$(ProjectName).dll" %systemroot%\system32 /Y

 

然后要小心,Post-Build Event(生成后事件)复制文件到指定目录成功后,当在次执行Post-Build Event(生成后事件)时如果二进制文件已经是最新的,Visual C++ 将跳过复制过程,

Developing With CredUI开发CredUI

Although you may not want to support the CredUI scenario in your final credential provider, you may wish to use it during development and debugging if you are developing on the test machine. Since the CredUI scenario runs from a normal desktop session, you’ll be able to attach the Visual Studio debugger to it at runtime, drastically simplifying the process of development and testing.

 

虽然在你最终的凭据提供方案中,你可能不需要支持CredUI,在测试机中你可以希望在开发和调试中使用它,因为CredUI方案是在一个标准的桌面会话中运行,无法断点等。你可以使用CredUI在运行时附加Visual Studio的调试信息。这会大在的简化你的开发测试过程。

To do this:

像这样做:

1.    Create a new Win32 console project in Visual Studio.

使用Visual Studio创建一个新的Win32控制台工程。

2.    Update the main function of your new project to make a call to CredUIPromptForWindowsCredentials, such as:

如果你的新工程要调用CredUIPromptForWindowsCredentials,则修改main函数,例如:

 

#include "stdafx.h"

#include <windows.h>

#include <WinCred.h>

 

int _tmain(int argc, _TCHAR* argv[])

{

  BOOL save = false;

  DWORD authPackage = 0;

  LPVOID authBuffer;

  ULONG authBufferSize = 0;

  CREDUI_INFO credUiInfo;

 

  credUiInfo.pszCaptionText = TEXT("My caption");

  credUiInfo.pszMessageText = TEXT("My message");

  credUiInfo.cbSize = sizeof(credUiInfo);

  credUiInfo.hbmBanner = NULL;

  credUiInfo.hwndParent = NULL;

 

  CredUIPromptForWindowsCredentials(&(credUiInfo), 0, &(authPackage),

    NULL, 0, &authBuffer, &authBufferSize, &(save), 0);

}

 

3.    Update the project to link against CredUI.lib. You may need to update your “Additional Include Directories” and “Additional Library Directories” to point to the Windows Vista SDK from the project’s property pages dialog.

更新项目对CredUI.lib的链接,你可能需要在工程属性页中更新“Additional Include Directories” and “Additional Library Directories”,(附加包含目录附加库目录)使其指向Windows Vista SDK

 

4.    Add your credential provider project to the solution.

添加你的凭据提供程序到解决方案。

5.    Build the credential provider and make sure the latest version is deployed to the System32 directory and is registered as a credential provider.

编译凭据提供程序并确保最新版本与部署到System32目录和注册的凭据提供程序一致

6.    Set breakpoints, etc, and then run the console app in debug mode. Your breakpoints should get hit as appropriate after CredUIPromptForWindowsCredentials is called from the console app.

设置断点、等等、然后在DEBUG模式下运行控制台程序,当然从控制台程序中调用CredUIPromptForWindowsCredentials时,你的断点应该会被命中。

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值