Windows 7 Development: UAC data Redirection-Win32 Native
Goal
In this hands-on experiment, you will learn how to:
• Troubleshooting a file redirection issue
• Use Process Monitor to find the root cause of the problem
System Requirements
You must meet the following criteria to complete this experiment:
Microsoft Visual Studio 2008
Microsoft Windows 7
Windows 7 SDK
Microsoft Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) on TechNet
Exercise: Experience user Account Control virtualization
In this exercise, you will diagnose a corrupted native (Win32) C + + application that shows the file redirection to the Virtualstore folder.
You will then add a UAC manifest file and compile the application so that it supports UAC. You will notice that it is not redirected, but will be blocked and cause an "Access denied" error when writing to the program files file.
Finally, you will modify the application to address this problem by storing the file in the application data (ProgramData) folder.
Task-No inventory files run the application
In this task, you will run the application without a manifest file to mimic an old application and trigger the UAC virtualization engine. When you create a new application in Visual Studio 2008, a manifest file that includes the UAC node is also automatically embedded by default.
1. Make sure your hands-on labs are running on a UAC-enabled system:
A. In the Start Menu
I. Open Search
II. Enter UAC
III. Click "Change user Account Control Settings" in the search list
B. The User Account Control Settings dialog box appears. Make sure that UAC is not disabled.
I. Set the UAC slider in the default location (see)
II. Click OK
2. Go to the folder that contains the Dataredirection solution
3. Open the solution in Visual Studio
A. Make sure that you are not running visual Studio with Administrator privileges
B. If Visual Studio is running with administrator privileges, "Visual Studio (Administrator)" appears on the title bar
4. Set the Brokenappnative project as the start Project:
A. Right-click on the project in the Solution window and select Set as Startup Project
5. Set the build target to x86 (Debug or Release; Debug recommended):
Help
The reason for this is that for x64 applications, no manifest file virtualization is turned off.
6. Right-click on the Brokenappnative project in the Solution window and select Properties:
A. By default, Visual Studio 2008 configures the project in one node of UAC, and we will turn off this setting to show how a lagged application is running.
7. In the properties:
A. Expand Configuration Properties
B. Expand linker
C. Selecting a manifest file
D. Change the Enable User Account Control (UAC) option to No
E. Click OK
8. Go to the BrokenAppNative.cpp file and view the SaveFile and LoadFile methods
9. Notice how the path is generated in the Makedatafilepath:
A. The data file path is saved under the Program Files folder
B.shgetknownfolderpath the Folderid_programfiles parameter to get the path to the program Files folder
C. If there are no subfolders , you will first create a subfolder under the program Files file
D. A file is then created under this subfolder (SomeFile.txt)
10. Build the project and run it. Once again, make sure you are not running as an administrator.
11. Open Task Manager and click on the Processes tab.
A. In the View menu, choose Select Columns
B. Pop-up Select Process Page Columns dialog box
C. Select the user account Control (UAC) virtualization in the check box, as shown in the red box (make sure you have selected that option)
D. Click OK
12. Note The UAC Virtualization column to determine that your process is enabled:
13. Enter something in the edit box and save it. This operation should succeed, that is, you will not get an error.
14. Try to go to the point where the path points (for example, 64-bit Windows 7 C:\Program Files (x86) \brokenapp or 86-bit C:\Program files\brokenapp on Windows)
Attention
You must not find Brokenapp in program files because the action to write to the file is redirected to the Virtualstore folder .
Task to find out the problem
In this task, you will use different steps to determine that your application is applying UAC virtualization.
1. Download and unzip the process Manager (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) from the Microsoft TechNet website .
2. Start the Process Manager
3. Launch the Brokenappnative application
4. Click the Third toolbar button to determine that the process manager is capturing. You can also turn capture on/off by pressing CTRL-E.
5. In the Brokenappnative application, enter some text in the text box.
6.??? Click Save in the Brokenappnative application.
7. You can stop capturing (or press CTRL-E) by clicking the Third button in the Process Manager's toolbar.
8. In the process manager, on the Tools menu, click Process Tree. The Process Tree dialog box will pop up as follows:
9. Locate the BrokenAppNative.exe in the tree and double-click.
10. Click Close to close the Process Tree dialog box.
11. Right-click the brokenappnative process name in the process manager
12. Click Include brokenappnative. This will filter out all other events:
Help
You can see brokenappnative trying to create a C:\ProgramFiles (x86) \brokenapp\somefile.txt file. This file is redirected to the Virtualstore folder , which is where the data files are eventually stored.
Note the result column. The "reparse" line is the most primitive operation. The "SUCCESS" line is the redirect operation.
Task 3– Add a UAC manifest file
In this task, you will add a manifest file to enable the application to support UAC. To mark your application as a UAC-enabled application, you want to declare that the application does not require write access to the protected location. UAC virtualization will not be applied to your application .
1. Right-click the Brokenappnative project in the Project window and select Properties.
2. Expand Configuration Properties.
3. Expand Linker.
4. Select the manifest file.
5. Change Enable user Account Control (UAC) to Yes
6. Click OK.
7. Rebuild the application.
8. Run the application
9. Review the Task Manager and you will notice that virtualization is now disabled:
Help
This is because the UAC node in the current manifest file marks the application in order to support UAC.
10. Enter some text in the edit box and click Save. You should get the following error:
Help
Because UAC virtualization is turned off, you receive an error when writing to a protected location.
Task 4– Modify access Denied error
By including the UAC node in the manifest file, you declare that your application supports UAC in Windows 7 , so you can prevent write operations in protected areas. In this task you will change where the text file is stored and fix the access denied error.
1. Back to Visual Studio
2. Find the Makedatafilepath method in BrokenAppNative.cpp
3. Comment out the line of code that contains folderid_programfiles at the top of the method.
4. Uncomment the line of code that contains the Folderid_programdata.
5. Rebuild and run the application.
You have now fixed the redirect problem and saved your data file to the correct place.
Help
In order to implement redirection in Visual Studio 2008, you must turn off UAC in the manifest file. To do this:
C # projects in Visual Studio:
1. Click on the Project menu
2. Click Project Properties
3. On the Application tab, on the Resources tab, select Picture and manifest file.
4. Choose not to include the manifest file to create the application.
5. Click OK.
C + + projects in Visual Studio:
1. Click on the Project menu
2. Click Project Properties
3. Expand Configuration Properties
4. Expand Linker.
5. Select the manifest file.
5. Change Enable user Account Control (UAC) to No
6. Click OK.
This turns off UAC only for illustrative purposes. All executables should be included in the UAC node in the manifest file. If the manifest file contains a UAC node, Windows will not treat the application as a lagged application and will not enable redirection. Writing to the Program Files folder will cause an Access denied error.
Summarize
In this experiment you used the process Management tool to analyze a problem with UAC redirection and resolved it by modifying the code and saving the file to the correct location (ProgramData).
Http://www.shangxueba.com/jingyan/99752.html
Windows 7 Development: UAC data Redirection-Win32 Native