User Interface Considerations


The most important security-related user interface change in Windows Vista is the addition of the shield icon. You can load the shield icon into your application with this code:

 #include "shellapi.h" SHSTOCKICONINFO si = {0}; si.cbSize = sizeof(si); HRESULT hr = SHGetStockIconInfo(                   SIID_SHIELD,                   SHGSI_ICON | SHGSI_LARGEICON,                   &si);

You can also load the small shield icon by setting the second argument to SHGSI_ICON | SHGSI_SMALLICON.

You should use the shield icon in user interface elements to indicate to the user which operations require elevation. For example, if an elevated action is to be performed after pressing a button, then the button should display the shield icon. If the process is already elevated, then there should be no shield icons displayed at all. The simplest way in a native application to mark a button as requiring elevation is to use the Button_SetElevationRequiredState macro:

 CWnd *pBtn = GetDlgItem(IDC_BACKUP_FILES); Button_SetElevationRequiredState(pBtn->GetSafeHwnd(),!IsElevated());

IsElevated is a function shown in the section “Determining if a Process Is Elevated,” earlier in this chapter. The last argument to Button_SetElevationRequiredState is a Boolean argument that determines whether or not to display the shield icon.

Figure 2-2 is a screen shot that shows the icon on a button.

image from book
Figure 2-2: A window showing the elevation shield. When the user clicks this button, she is prompted to elevate, and then an elevated process is launched.

When a user clicks a button that starts an elevated task, you can start the task as either an elevated process, or better yet, an elevated COM object that displays a dialog box.



Writing Secure Code for Windows Vista
Writing Secure Code for Windows Vista (Best Practices (Microsoft))
ISBN: 0735623937
EAN: 2147483647
Year: 2004
Pages: 122

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net