Windows Vista allows you to raise permissions of an application automatically if the application 'looks' like a Setup or configuration application. Or you can run 'As Administrator' which gives you Admin permissions. There's a problem with this though - when this elevation occurs it's essentially switching users, so your local user store - the Documents directory - is no longer pointing at your user store but at the elevated user store which can be problematic.

 

I have an application - West Wind Web Connection for Visual FoxPro - that's a Web dev tool for FoxPro pretty much requires Administrative rights for initial configuration. So this app needs to configure IIS which downright requires admin access. Understandable. Surprisingly enough with a few tweaks and the IIS 6 Metabase compatibility the configuration routines using the IISAdmin tools work just fine as long as an Admin account is used. So far so good.

 

The main configuration application is conveniently called Setup.exe so Windows Vista will automatically try to elevate permissions to run as Administrator which is also good. The main application configuration works just fine it copies installation files etc. into a common folder and writes various configuration files in the install folder as well as the IIS Web virtual folder. All still good…

 

But…

 

One of the things that happens is that the application installs a set of user templates in the Visual Studio folder. These templates typically gets stored in the users Documents folder. The Documents folder is user specific so that the user gets a data location where she has full access to files with full read/write access.

 

But the problem is that when my application level configuration routine runs it’s been elevates as Administrator, so if I query for the Documents folder with ShGetSpecialFolder API I get Administrator’s private directory not the logged on users actual directory.

 

Now I have a problem. How do I find the original user’s logon directory?

 

This is an awkard situation – you need to run as an administrator, but you need to copy files into a directory for another user.

 

I can’t really see a good way from my ‘configuration’ application to figure even out who the user is that I’m supposed to be dealing with because as soon as I elevate I show up as the elevated user account (Administrator in this case). So GetUserName (or Sys(0) in VFP) returns Administrator. So there’s not even an easy way to hack your way into the right directory tree by manually creating path strings.

 

Now you might say why doesn’t your installer do this for you – the problem is that I create customized configurations for each new application that gets installed so the templates that are generated are usually not run through an installer but rather through this configuration routine.

 

The way it stands right now the user has to run things twice:

 

Run as Admin to configure IIS

Run as a normal user to add the templates

 

And well, that kinda sucks <g>…

 

Anybody see a way around this?