Hello,
I've created a COM exe with a method that implements
CreateProcess. And successfully call this from an IE7
app while running in Protected Mode.
In this case, the app that you run from CreateProcess should also be running
in IE7 protected mode, unless you are using the new interface in IE7 that
prompts the user for consent in order to "break out" of protected mode.
Vista is designed so that apps running in different privilege levels are
seperated, and whenever a lower-privileged application wants to start or
interact with a higher-privileged one, user consent is required. I.E.
protected-mode IE requires user consent to launch a non-protected-mode app
or access things that are restricted from protected-mode.
In the same vein, when a user wants to start a program that requires admin
permission, user consent is required unless the program that is wanting to
start the elevated program is an elevated program itself.
So, following this abstraction, the correct way to implement your
application, assuming it only needs admin permission to do certain, specific
tasks and can be run without admin permission most of the time (kind of like
windows explorer), is to seperate out the chunks that need admin permission
into seperate COM components or exe's, and only call/launch them when
necessary.
When launching these secondary processes, you will need to programatically
specify that they need admin permission (or in the case of an EXE, you can
embed a special manifest that tells Windows it needs admin) and then it will
prompt the user for permission and elevate the COM/exe so that it can do its
admin tasks.
Or, if your entire application is say a systems utility that needs admin
permission just to run, you should embed a manifest into the app specifying
that it always needs admin access, and the system will automatically prompt
the user for permission and give the app admin access every time it is run,
without you needing to do anything programatically (more on that later).
Here's a good document that explains this sort of thing:
http://msdn.microsoft.com/windowsvi...l=/library/en-us/dnlong/html/AccProtVista.asp
Now, the other situation you may encounter, is where you need your program
to be able to perform a task that in and of itself should not need admin
permssion, but the task must have admin permission to be implemented. For
example, the act of virus scanning should not require admin permission, but
implementing the virus scan itself does.
To do this sort of thing, you should implement a windows service that
performs these high-level tasks. Your application, running as a standard
user via UAC, should then call this service using some IPC mechanism to
perform these high-level tasks.
NOTE, however, that when implementing a service in this manner, you should
NOT be allowing your program to specifically do admin-related tasks; I.E.
you shouldn't make a mechanism using this service to allow your application
to write to restricted registry keys.
Your application should NOT be able to "break out of its security box" when
using your service - and you should take great care to ensure that this is
not possible. The service ITSELF should be able to do admin-related things
in order to implement whatever tasks that it needs to do, but this power
should not 'leak' back out to the application.
For example, the service may need to access security-restricted things to
perform its duties (for example, the virus scanner needs to access all files
regardless of security permissions). But in doing so the service must ensure
that it does not leak such power to the lower-privileged application using
its services (i.e. the virus scanner UI running as a standard user should
NOT be able to use the virus scanning interface to access files it does not
normally have access to - it should only be able to do abstract virus
scanning related functions)
I know this is a very fine distinction, and I hope I have explained it well
OK more info on manifests:
A manifest is simply a Win32 resource that is linked into a program module.
It is not limited to .NET exe's. The manifest tells Vista how much
permission your program needs.
This does not 'bypass' Vista's permission dialogs in any way - it tells
Windows Vista how much access your program needs to the computer.
If your program always requires administrator permission, for example, Vista
will ask the user for permission to start your program every time it is
started, because the only way for programs to run with admin permissions in
Vista is thru user consent.
If your program requires 'as much permission as the user has', then your
program will NOT prompt the user for permission if they are a standard user
and will have only standard user permission, but WILL prompt if the user is
an admin and will have admin permission (again, because apps that use admin
permission must get user consent).
Or, if your app never requires admin permission, then it will never prompt
at all, and never have admin permission.
More info on manifests:
http://blogs.msdn.com/shawnfa/archive/2006/04/06/568563.aspx
(note that step 3 gives instruction on how to embed the .res file into a
..net exe - instead of this, use the C++ method of doing this)
http://msdn.microsoft.com/windowsvi...l=/library/en-us/dnlong/html/AccProtVista.asp