Question How do I run c# application as published user within UAC dialog

Kamen

Active member
Joined
Nov 30, 2020
Messages
28
Programming Experience
1-3
You can read from Program Files without admin rights.

You can change Time Zones without being an admin. Do you really need to change the time when modern Windows actually synchronizes itself with NTP servers which use atomic clocks to keep time?

The correct thing to do is to get the UAC only at the time when you are trying to do something that actually requires admin rights, at the time when you need it. You don't want to always be running as admin. By always running as admin, you open up the attack surface for viruses. A virus will just have to inject itself into app instead of trying to inject itself into other more will known apps/processes which are more actively monitored by AV software and/or Windows Defender.

Please follow the Windows Guidelines with regards to UAC:
Hello.
Thanks for your kind help.
I made my c# app to run as an administrator using process reference instead of requireAdministrator excutionLevel . So my app run in startup and I can write file and change system time.
By the way my app has some problem still now. It seems to be UAC problem.
Whenever my app start on windows 10 64bit, "unknown publisher ..." message popup now.
I attached the message screen now. If I set UAC level to lowest(never notify) in UAC setting, I never get this message but I want to keep the level and prevent this message.
Can you help me in this section?
 

Attachments

  • 2021-01-07_00h33_28.png
    2021-01-07_00h33_28.png
    44.2 KB · Views: 49
Solution
I understand now. Nowhere in this thread or in your original thread did you ever mention that your app would be running on an offline PC and that it would never sync online. How were we supposed to figure out that you had those 1990's style constraints on a modern app running on Windows 10?

Anyway, so I am guessing that the reason why you want to be able to set the time is because the machine is locked down, and so you want a way for the user to update the time when the clock does drift, but without having to enter the admin password required by the UAC dialog.

My suggestion is to break up your app into two parts. Part runs as Windows service which gets installed and runs with system rights, or as user with admin rights. Windows...
Hello, Thanks for your time.
By the way, I want to prevent the windows UAC dialog itself.
Is it possible?
Looking forward to hearing from you as soon.
Regards.
 
I want to prevent the windows UAC dialog itself.
Don't run app as administrator/elevated. Don't do anything that requires administrator permissions.
 
Why?

As I mentioned above, you don't really need to change the time, and you don't need admin rights to change time zones.

What files do you need to write that need admin rights?
 
My app run with communication through COM port and should work with registry. And also need to write and delete log data file in place where app is installed in C:/program files folder.
In my work experience in this project, such operation requires administrator permission.
So I tried to do it by setting my app.miniforst as requiredAdmin but I perform it with processor reference after.
now my app.miniforst file has been set with asInvoker.
By the way, could you explain how to change system time without admin permission?
And also I want to know how to prevent windows UAC dialog with admin permission.
Thank you.
 
I may not be so, it sounds as pre-Vista thinking. You can read/write HKCU and read HKLM without admin rights. Log data shouldn't be written in application folder, but in a local app data folder.
prevent windows UAC dialog with admin permission
Only way I know is using task scheduler, explained in your other thread. The task needs to approved as admin when created. The task can be configured to run on demand, including from a desktop shortcut without UAC prompt.
could you explain how to change system time without admin permission?
@Skydiver talked about that too here Question - How do I run c# application as administrator in start up
 
I may not be so, it sounds as pre-Vista thinking. You can read/write HKCU and read HKLM without admin rights. Log data shouldn't be written in application folder, but in a local app data folder.

Only way I know is using task scheduler, explained in your other thread. The task needs to approved as admin when created.

@Skydiver talked about that too here Question - How do I run c# application as administrator in start up
But I don't must do any other additional operation in windows OS out of app.
I need to solve all problems in my project programmatically.
Is it possible?
You said me that I can read/write HKCU and read HKLM without admin rights. Log data shouldn't be written in application folder, but in a local app data folder.
Can you explain in more detail?
could you explain how to change system time without admin permission?
I want to hear from you about this qustion.
 
Yes you need admin rights to change the system time. But I'm telling you that you don't need to change the system time. The system time is set by the OS by talking to NTP servers so that the machine is synchronized with highly accurate atomic clocks all over the world. All that needs to be done is to change the local time zone. You don't need admin rights to change the timezone.
 
Just adding some extra information, a possible drawback to task scheduler is if you configure to run as admin and run also when other user is logged in, if the user session itself is not admin the task will not run interactive (you can't see it and interact with it). If the user is the admin the elevated task runs without UAC prompt (and interactive).
But I don't must do any other additional operation in windows OS out of app.
UAC is what it is, there's no way around that.
Can you explain in more detail?
See the registry class for how to open a key in readonly mode. Use Environment.GetFolderPath to get the LocalApplicationData folder. The forms Application class also has a property to get it.
 
Ok. I understand in local application data folder now. thanks for your kind explanation.
But I can't understand about timezone change instead of system time. I think it is different between changing timezone and time constantly.
Could you tell me in detail again?

By the way my main goal is to prevent UAC dialog.
So is there any way to solve it programmatically in app?
I think admin permission will be mandatory in this app anyway.

my app should be installed and run in any PC. so we can't solve it with additional tools or OS setting.
Just only app must make it solve on itself programmatically.

Hope a great help.
Thank you.
 
But I can't understand about timezone change instead of system time. I think it is different between changing timezone and time constantly.
Could you tell me in detail again?
Let's back up. Why do you need to change the system time?

Possible answers are:
A) Is it to correct the time because the machine clock has lagged behind?
B) Are you changing the time because the user has travelled from one location to another?
C) Are you changing the time to work virtually to be "in synch" with other team members who live some place else?
D) Are you changing the system time because you are running a piece of software that has an expired license and so you keep resetting the time to some time back in the past to get past the license?

If your answer is A, then you don't even have to change the time. The OS knows how to fix and keep the system clock falling behind as long as it has an active Internet connection. (Actually, the OS can also fix the clock falling behind as long as you just have an active WiFi or LAN connection, but you'll need an AD server or know how to setup your own time server.) That system time internally is set to UTC, and the time displayed to the users is dependent on the timezone setting.

If your answer is B or C, then all you need to do is change the timezone for the machine. As mentioned above the OS knows how to keep the system clock up to date. All you need to do is tell the OS what timezone the user is currently in or is virtually in.

If your answer is D, I don't condone hacks to get around licenses. People should be paid fairly for their work. I won't provide any further help to help you steal someone else's work.
 
Back
Top Bottom