Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What parts of .NET require administrative privileges to be executed?

Which parts of the framework require a user to be more than a Standard User? The reason I'm asking is because I'm trying to compile a list of possible issues with our existing applications when migrating to Windows 7.

Now, I can think of a few things myself:

  • Writing to Eventlog
  • Writing to Registry Keys outside of Current_User scope
  • Getting an Environment variable
  • etc...

I really would like a more complete list and so far I've not come across a decent resource in which all this stuff is listed.

Note that I'm not looking for ways of elevating the privileges for the existing apps (which can be done by using a manifest), I'm simply identifying actions in code that might cause issues.

like image 669
Ruben Steins Avatar asked Apr 09 '10 14:04

Ruben Steins


3 Answers

Well, your examples don't really have anything to do with Windows 7 or .NET. Actually they were already part of the "Designed for Windows NT 4.0" logo requirements. If you have written your application in a way that non-admin users were able to run it on NT, Win2k or XP, it will just work fine on Vista/Win7.

There is another common pitfall when you run your software on x64 systems (however this too isn't specific to Win7 but is true e. g. for Win2003 Server x64 or Win XP x64 as well): If you are working with native 32-bit code, like calls to a native DLL or COM interop with a in-process component), make sure to select "x86" as the platform target in Visual Studio project settings instead of "Any CPU". Otherwise your application will run as a 64 bit process, and you can't mix 32 and 64 bit code in the same process, so you would run into errors.

And of course, as it always has been best practice, use Environment.GetSpecialFolders instead of hard-coded paths.

like image 144
realMarkusSchmidt Avatar answered Dec 07 '22 22:12

realMarkusSchmidt


Thinking of it as "What library calls" is going to lead you down the wrong path. Think about anything that writes to a file. If that file is under Program Files (among other places), you need admin privs. If it's under AppData, you don't. Same library call, different outcomes. Ditto for writing to the registry - HKLM you need admin, HKCU you don't. Writing to Event Log is generally ok but creating your event source is not. And so on. It's not about what method you call, it's more about the params (eg path) you pass to it.

like image 26
Kate Gregory Avatar answered Dec 08 '22 00:12

Kate Gregory


I don't believe getting environment variables need elevating privledges. At least I've never run into it, are there really cases where that's true?

like image 20
Alex Avatar answered Dec 08 '22 00:12

Alex