4

I have a C# program that require SeSystemEnvironmentPrivilege to access the UEFI NVRAM.

I found a really long code, that uses Win32 API to get the privilege, but is there a .NET version to get it? In process class, or somewhere else?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Rabir
  • 59
  • 1
  • I don't know if it will work or not, so posting as a comment, but try using [PsExec](https://technet.microsoft.com/en-us/sysinternals/psexec.aspx) with the `-s -i` switches, that will run a interactive program as the SYSTEM user. `PsExec.exe -s -i YourApp.exe` – Scott Chamberlain Jan 25 '16 at 15:04

1 Answers1

4

If it is really necessary you can use the AdjustTokenPrivileges function. Something like this:

 [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

You can get more info here:

Daniel
  • 143
  • 11