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
Processinstance, applied admin credentials toProcessStartInfo, set theFileNametoc:\windows\system32\cmd.exeand the argument to/C date {thedate}. I redirectedStandardOutputandStandardErrorand after executionStandardErrorcontains the same message as stated above: "missing client permission"I've modified this example MSDN: WindowsIdentity.Impersonate using PInvoke with
AdvAPI32.LogonUserto raise permissions andKernel32.SetSystemTimeto change the system time.AdvAPI32.LogonUsersucceeds andWindowsIdentity.GetCurrent().Namereturns the admin name, but callingKernel32.SetSystemTimefails with "missing client permission".I've tried opening the current process
AdvApi32.OpenCurrentProcessand adjusting the permissions usingAdvApi32.AdjustTokenPrivilegesfollowing this example StackOverflow: Change system time programmaticaly using datetimepeaker and the code runs totally fine butKernel32.SetSystemTimefails...
[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.