views:

465

answers:

3

I have a Windows service that runs as a logged-in user (local admin). During start-up, I get a message along the lines: "Unable to generate a temporary class (result=1)". So, I went to windows/temp folder and was prompted by UAC to elevate my privileges -- after I did this, the service would start up fine. So, how do I deal with this UAC prompt from the perspective of a Windows Service?

Thanks!

A: 

I solved my problem even though I still don't know how to answer my question. Basically, my service was inheriting the temp directory from the bootstrapping process, so I changed it to use current's users' temp dir. You will need to do something along these lines:

myProcess.StartInfo.EnvironmentVariables.Add("TempPath", "C:\Temp")

Lenik
A: 

Why not have the Windows Service run as LocalSystem?

MattH
+2  A: 

Regarding the original question - beyond the specific problem of event order that fixed your symptoms.

When an user who is a member of the Local Administrators group logs on to a machine under UAC, two security tokens are granted - one with limited rights, and one with the higher permission set. By default, the lower permissions are used - unless the higher is actively specified. The primary means of specifying is through the UI - as you did. The other method is to use an application manifest: an XML file that specifies how the OS is to treat this application. The manifest file should be placed in the same folder as the executable, and named using the following format: "my_application_name.exe.manifest"

The XML in the manifest will look something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" name="MY_APPLICATION_NAME" type="win32"/> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator"/> </requestedPrivileges> </security> </trustInfo> </assembly>
I'm sure you can find a bunch more specific info by googling "UAC Manifest" ...

Hope this is useful ...

DragonsRightWing