Set editor when UAC prompt - c#

I'm writing a program in C # that needs administrator rights. To do this, I added the following lines to the "app.manifest" file:
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
The request is working properly The program has administrator rights.
My problem is that on demand, the publisher is unknown and I do not know how to change it.
UAC image
I entered my name in the assembly, but it does not change anything.
Does anyone know how to change this value?

source: https://forum.powerbasic.com/forum/user-to-user-discussions/programming/59673-uac-message-publisher-unknown
In the above source a similar question is asked. The responses indicate the use of a codesigning certificate. There is also a mention to a how to in stackoverflow that explains how to create your own codesigning certificate: How do I create a self-signed certificate for code signing on Windows?

Related

EventLog WriteEntry not does not write into EventViewer in C#

I have created a C# application which creates custom log name in the event viewer, and writing entries into event viewer.
My application is working fine on Windows-7 OS machine But when i copied my binaries into another window-2012 server standard(SP1) machine its not working.
I ran my application RunAs administrator and I am seeing only custom log name but not the logging messages.
I have given full permission in the registry eventlog entry but no luck.
Could somebody suggest me how to fix the issue. Or debugging technique to fix this issue.
I have debugged the code there are no exceptions, Code is running smoothly.
my code is so simple like as below:
EventLog.CreateEventSource("MyApp", "TestingApplication")
EventLog.WriteEntry("MyApp", "Testing 123")
today i have tested with same eventsource and eventlogname, like as below
EventLog.CreateEventSource("MyApp", "MyApp")
it worked fine in window-2012 server standard(SP1), is there anything issue in Win-2012(SP1) or am I missing anything.
Even while running as an administrator, in Windows Server 2008 R2 it defaults to not having elevated privileges. You need an elevated privilege to create the source. Once the source is created, it should let you write to it.
There are a few ways to solve this, if you're building an actual application, you can modify the application manifest to require elevated privileges and admin rights:
<?xml version="1.0" encoding="utf-8" ?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator"
uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>
Or, again if you're building a normal application, you can split the code to create the event source into a separate process. Then you can check to see if the event source exists, if it does, just use it, if it does not, you can run your new process that creates the event source.
In the Process start info you'll need the 'runas' verb.
If you're running a windows service, you're a bit more restricted, as services do not have the capability of "elevating" privileges through their manifest directly as far as I'm aware.
However, your service installer can elevate just fine, and should be running under the needed admin rights, you can create your event source inside the service installer; and then just consume it within the service itself.
I solved this problem by Stop/Start Windows Event Log services. I dont know what was the problem but like Leo saied it can be a bug.
I was having exact same issue. I am using WinServer 2012r2. Log created successfully but writing events appear in the Application Log. I read a lot of MSDN and forums and done everything up to the books and still have this problem. Seems MS has a bug in latest .Net framework which causes all messages to go to the Application Log :(
Finally after I rebooted server everything was working fine. I am not sure why would I need to reboot server if testing with eventcreate command line everything was working fine.

Execute user-privileged task from elevated application

I have an applicaction which is running with administrative privileges.
Privileges are escalated automatically using application manifest.
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
From this app I have to execute some code as a user who started the app, but without elevation.
How can I achieve it?
You can use impersonation to achieve the desired results. In order to impersonate the current user without a password you need to find another process that the user has ran and get the token from that. Explorer is good for that. Here is full sample code.

Application manifest, admin rights and autostart on Windows Vista\7

So, I have an app that needs admin rights to work.
I created an app.manifest file. It works perfectly.
But now I need to set my program to autostart in Windows, and I am having trouble with this. If my program has an app.manifest file - program does not load when windows starts, but when I delete the app.manifest file - it works well.
Here is code from the app.manifest file:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="update.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
</asmv1:assembly>
Thanks for your help.
It’s not running because when you request admin access, the user needs to authorize it as admin (click the UAC Allow button), if it’s not popping up, there should be something in the icon-tray where the user can load all blocked exe's by clicking through the icon to give admin rights. when you run without the manifest, it is running only because it defaults to running under standard access (non-admin access, basic user level rights) so you're app is running but without being able to make changes to the system or file/path access items that only admin elevated apps can do. Get me?
The question is, how do you get your exe to auto start with admin privileges if it was installed and initially ran with admin elevated privileges during its installation? There seems to be a few answers to this but i am still searching for which one(s) actually work and are reliable. Basically, if it was elevated once, it should continue to be elevated (automatically, without prompting user) when it’s auto-starting (right after reboots) - but it is NOT doing that, and that's the problem. Let me know if you make progress with this.
UPDATE: 2012.11.10:
I have found a solution, using windows task scheduler to
programmatically schedule as task (that being, to run an EXE during
reboot/startup) & you have the option to run it as an elevated app,
and I think you need to be elevated to begin with in order to be able
to schedule this elevated auto run entry in the windows task
scheduler. Seems weird I know, but MS has allowed for this (and only
this) as a way to auto elevate your apps during startup, and they
haven't provided another way to do this. So, use appropriate API's to
register a Windows Task Schedule which will run your app elevated.
I'm not sure but it's probably about the authentication of startup user. if you did not already, you may check there for detailed information.

Windows Forms - C# - ask for administator privilege [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to force C# App to run as administrator on Windows 7
I am building a WinForms C# appliction, and I need it to ask for administrator privileges so I can copy and open directories in C:\.
Is this possible?
The code I am going to use (if any one needs) is this:
if (!Directory.Exists("C:\\smm"))
{
Directory.Create("gg");
}
Or something like that, but I am sure I need administrator privilege.
Anyone know how I can do this?
You need to enable ClickOnce security settings in your project, then change the application manifest to require administrator privileges. This will cause Windows to show a UAC elevation prompt when the process starts, so the user can escalate your program to admin.
To enable ClickOnce, go into your project's properties, select the Security tab on the left, then check the "Enable ClickOnce Security Settings" box. Then go into the project's "Properties" directory, and open up the app.manifest file. In that file, there's a line that sets the required privileges:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
You can make it require administrator privileges like this:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
That'll make it require admin when the process starts.

How to grant rights to HTTP namespace on installed service?

I have written a Windows Service, that opens up a WCF service on port 8003 of the local machine. Or at least, it's supposed to. The service can't start up, because of the famous exception:
System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8003/TRConfigurationService/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).
This problem is addressed here, with a very simple answer: run a command prompt in admin mode, and execute:
netsh http add urlacl url=http://+:8003/ user=DOMAIN\UserName
All very well and good, and I can do that manually on my local dev machine. But how do I do that on the client installation, without the user having to do anything other than click "Yes" (only once after/during installation) when prompted to run in Admin mode?
It sounds like you should be able to do it using WIX.
Looks like the answer is simply to make sure the service runs in admin mode, then there's no problem! For those who don't know, add an app.manifest file to the project, and set
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Categories