DESKTOP

Windows 7 : ADDING UAC SUPPORT TO YOUR APPLICATION (part 3) - Executing as a Separate Process - Creating the Secondary Project , Configuring the Secondary Project

1/27/2014 1:45:15 AM

2. Executing as a Separate Process

Setting an entire application to execute in administrator mode is uncommon and unsafe. The more common scenario is to separate the application into pieces that can execute at one of three levels:

  • With the rights used to invoke them

  • With the highest privileges that the user natively has

  • Administrator mode

The .NET Framework currently executes each level as a separate process, rather than using threads or some other convenient method. The following sections show one scenario that uses separate processes to execute in standard mode and in administrator mode.

2.1. Defining the Separate Process Application

The example begins with a Windows Forms template application named Modify Permission that has a single button, btnChange. You can give the solution and project the same name, if desired. You don't need to add any special references for the example, but you do need to add the following using statement:

using System.Diagnostics;

2.2. Creating the Secondary Project

You add the second process as a separate project. Use the following steps to create the secondary project:

  1. Right-click the solution entry in Solution Explorer and choose Add => New Project from the Context menu. You'll see the Add New Project dialog box shown in Figure 5.

    Figure 5. Add a console application to the current solution.
  2. Highlight the Console Application template.

  3. Type SetPermission (no spaces) in the Name field and click OK. Visual Studio adds the SetPermission project to the Modify Permission solution. You also see the SetPermission.CS file opened for editing.

2.3. Configuring the Secondary Project

As a console application, SetPermission doesn't include any controls or other special interface needs. You also won't need to add any references to it. However, you do need to add the following using statements:

using System.Security.AccessControl;
using System.Security.Principal;
using System.IO;

The project needs a special setup as well. You want the output of the build process to appear with the Modify Permission.EXE file to make it easier for Modify Permission.EXE to find it. Use the following steps to configure the build output:

  1. Right-click the SetPermission project entry in Solution Explorer and choose Properties from the Context menu. You see the SetPermission properties window.

  2. Highlight the Build tab.

  3. Select Debug in the Configuration drop-down list box.

  4. Type ..\Modify Permission\bin\Debug\ in the Output Path field. Your Build tab should look like the one shown in Figure 6.

    Figure 6. Make sure you configure the build to place the output with Modify Permission.EXE.
  5. Select Release in the Configuration drop-down list box.

  6. Type ..\Modify Permission\bin\Release\ in the Output Path field.

You also want to be sure that the correct project executes when you debug the application. Right-click the Modify Permission project in Solution Explorer and choose Set as StartUp Project from the context menu. The Modify Permission entry will appear in bold type to indicate that it's the startup project.

Other  
  •  Parallels Desktop 9 For Mac - The Best Of Both Worlds
  •  Windows Server 2008 and Windows Vista : Benefits of Group Policy Preferences (part 2) - Working with Any Organizational Unit Design
  •  Windows Server 2008 and Windows Vista : Benefits of Group Policy Preferences (part 1) - User-Friendly Interface
  •  Windows Server 2008 and Windows Vista : Creating Custom ADMX and ADML Files (part 4) - Using ADMX File Language
  •  Windows Server 2008 and Windows Vista : Creating Custom ADMX and ADML Files (part 3) - Core ADMX File Concepts
  •  Windows Server 2008 and Windows Vista : Creating Custom ADMX and ADML Files (part 2) - Core ADMX File Concepts
  •  Windows Server 2008 and Windows Vista : Creating Custom ADMX and ADML Files (part 1) - ADMX Schema , ADMX File Structure , ADML File Structure
  •  Windows 7 : Custom Libraries and Saved Searches (part 2) - Using Saved Searches
  •  Windows 7 : Custom Libraries and Saved Searches (part 1) - Creating Custom Libraries
  •  Windows 7 : Visualization and Organization - How to Make the Windows Shell Work for You - The Organizational Advantage of Libraries
  •  
    Top 10
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS