I need your help again :)
What I want to do:
I have a c# program which runs with normal user permissions - those can't be raised - and I want to change the system date (not time) from that program.
[EDIT] To be a bit more specific: I do have administrator credentials which could be embedded to the program (yikes, I know), but I want to avoid an UAC prompt.
When I launch cmd
from outside Visual Studio and try to change the date, it fails with "missing client permission" (roughly translated from German). When I launch cmd
as administrator, confirm the UAC prompt the same command succeeds.
I am writing from home, so I cant provide running code at the moment. But all my tries did compile and run without error but the date wasn't changed.
What I've tried:
Created a
Process
instance, applied admin credentials toProcessStartInfo
, set theFileName
toc:\windows\system32\cmd.exe
and the argument to/C date {thedate}
. I redirectedStandardOutput
andStandardError
and after executionStandardError
contains the same message as stated above: "missing client permission"I've modified this example MSDN: WindowsIdentity.Impersonate using PInvoke with
AdvAPI32.LogonUser
to raise permissions andKernel32.SetSystemTime
to change the system time.AdvAPI32.LogonUser
succeeds andWindowsIdentity.GetCurrent().Name
returns the admin name, but callingKernel32.SetSystemTime
fails with "missing client permission".I've tried opening the current process
AdvApi32.OpenCurrentProcess
and adjusting the permissions usingAdvApi32.AdjustTokenPrivileges
following this example StackOverflow: Change system time programmaticaly using datetimepeaker and the code runs totally fine butKernel32.SetSystemTime
fails...
[EDIT] Solution:
I ended up writing a small program with an embedded app.manifest that requests administrator privilegs. This app is called from the main program so this can still be run by a normal user.