While testing
the implementation of my previous blog, Installshield Automation Using c#, a build error number -6017 occurred. This error states that COM information cannot be extracted from the COM server in the project. The only reason this could happen is because I ran the IS project without administrative privileges.
So this brought
me to my new blog topic ‘UAC’.
With the
arrival of Vista, windows 7 and Server 2008 and having developed applications that run on the those platforms, one thing that I have consistently dealt with
is, permissions to resources. Reason being the new technology namely, UAC, which
was introduced by Microsoft on the latest windows releases. The main purpose of
this feature is to protect the OS by running applications with
reduced privileges.
UAC has two
dialogs; A blue one which indicates that the application is trusted and
signed.
A yellow
dialog that show that your application is not digitally signed and it is not fully
trusted.
User Account Control prevent low
privilege applications from doing the following :
- Perform a window handle validation of higher process privilege.
- SendMessage or PostMessage to higher privilege application windows. These Application Programming Interfaces (APIs) return success but silently drop the window message.
- Use thread hooks to attach to a higher privilege process.
- Use Journal hooks to monitor a higher privilege process.
- Perform DLL injection to a higher privilege process.
In my development, how do I deal UAC it?
There are
several methods that can be used:
1. Including a UAC manifest that will
cause the application to request administrative privileges at start up:
a. To add a manifest file in VS2008,
just right click on your solution then from the menu choose add>new Item.
Now from the new Item dialog box select the “Application Manifest File”. Edit
the file as follows.
<?xml
version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<trustInfo
xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level=" requireAdministrator” uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
b. Under VS2010 it is a little
different. Right click the Project and select Properties. Select the
"Application" tab and then click "View Windows Settings".
This opens the manifest, and then you can make the changes you need. VS2008
procedure works too.
2. The second method is to isolate the
part of your code that requires elevated privileges into an application that
uses a UAC manifest to require administrator privileges. Your application does
not need to run as admin, when these privileges are required you should invoke
the external application. Here is some code prototype you could use.
If you would like your application to behave differently depending on if the current user has admin rights, you can use the code below;
using System.Security.Permissions;
using System.Diagnostics;
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.Verb = "runas";
processInfo.FileName = [Add filename here];
Process.Start(processInfo);
WindowsIdentity identity = WindowsIdentity.GetCurrent();
if (identity != null)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
The code will return true if administrative and false otherwise.
dude speak the Gwandaru english, lol
ReplyDeleteNice blog, Geeky cool i guess.
bravo. cool blog
ReplyDeleteYou are welcome buddies. There is more where that info came from.
ReplyDeleteHow to wrap multiple exe files into msi package with InstallShield at run time..Please help me creating msi package with code at run time instead of manually creating msi package with install shield.
ReplyDeleteHow to wrap multiple exe files into msi package with InstallShield at run time..Please help me creating msi package with code at run time instead of manually creating msi package with install shield.
ReplyDelete