c# Requested registry access is not allowed - c#

I have a problem, my application is running under admin rights (I have also manifest)
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
I'm making program to changing default icons. When I'm changing default icon for *.php file everything is ok. But if I want change default icon for *.mp3 file i get this error Requested registry access is not allowed. I dont know how can I get better privileges for working with registry. I'm using only this -> RegistryKeyPermissionCheck.ReadWriteSubTree. And this gives me error:
FileExt = FileExt.OpenSubKey("UserChoice", RegistryKeyPermissionCheck.ReadWriteSubTree);
Thanks for response!

Have u already tried to start your Assembly as an administrator? To check this quickly just start the compiled application as an administrator.
To achieve this programmatically change the user context during the execution of your code look at this MSDN article:
http://msdn.microsoft.com/en-us/library/w070t6ka.aspx

I added try catch -> try read/write catch read.

Related

WinForm DPI issue

There was this issue:
WinForm looks different than in VS designer
I thought I solved with this one:
https://stackoverflow.com/a/13228495/1806838
I used the app.manifest one.
<dpiAware>true</dpiAware>
After that all seemed to be OK. It looks perfect if I debug or if I run the application from the folder where I build it. (app\app\bin\Release\app.exe). But if I copy the executable outside that folder (for e.g. to my Desktop, and I run it then it looks like this (the right one obviously):
It's like the app.manifest is not embedded, but I checked the settings and it seems to be OK. Also, I made sure that in the app properties the correct manifest file is being selected.
Any ideas?
EDIT: So, it seems if the app.exe.manifest is in the same folder then it looks good, otherwise it's not.
EDIT2: I found that I have 2 app.mainfest files. One is app\app\app.manifest and the other one is app\app\Properties\app.manifest. So I deleted both and added a very new one having the DPI setting in it. I still have the same issue. Checked the app.manifest properties and the Build Action is set to None. Shall I change it?
EDIT3: I addedd app.manifest to the Resources and set app -> Properties -> Manifest to be Resources\app.manifest. Still the same.
So, after trying to compile the app.manifest for 3 days, I added another setting to see whether it's going to be applied. This was the run as admin:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
And when I tried to build with that I got an error message stating that it's not compatible with ClickOnce. And this was the point when I realized what a moron I am. After disabling ClickOnce via app -> Properties -> Security -> uncheck Enable ClickOnce security settings everything is just working perfectly. It seems that if it's enabled then it ignores the manifest.
I'm really sorry for the time of people tried to help wasted.

Can I set the properties of an exe file via C#?

I am using Unity to build my game. I need the application to always run as administrator.
When I build my game, I right click on the exe that is produced and set 'Run this program as an administrator' on in the Compatibility > Settings section of the exe properties.
I can write an editor script (C#) that'll execute after a build has completed. So I was wondering if I could automate this step so that I do not forget to do it every time I build?
I'm not sure if this solves your issue.
But you could add an "Application Manifest File" and configure:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
With this configuration the user gets always a UAC promt.
Do not have a ready made solution but i can give you an idea:
Have a look at this, using this way you can check if your application is running as an administrator, if no, it starts another process with administrative privilege and you can later call:
Application.Quit();
to terminate the current instance.
Other than this you must have to wrap this code under platform dependent compilation.
I know it is not a best solution, but can fix this issue.
Hope it helps!

How to run application as administrator in debug with Visual Studio?

I have a c# application where I have to have read/write access to the root of the C drive. I realize I can compile the code and run the executable as administrator and it works. But I need to debug it and I am unsure as to how one would start the app within Visual Studio.
I have tried adding:
<requestedExecutionLevel level="asInvoker" uiAccess="true" />
to my manifest but I still get access denied error.
Here is the line of code that fails:
MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(#"c:\somemapnamefile.data", System.IO.FileMode.OpenOrCreate, "somemapname", 1000);
For now I have a work around but I'd like to know for the future.
Just run visual studio itself as an administrator. Any program you debug from there will also be run as an administrator.
VS must be run with admin right. however, a more elegant way is in the requiredExecutionLevel in manifest should set to 'requireAdministrator'.
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
When you open the project and try to debug, the VS2012 will warn about the admin right and restart itself to admin right. And also the exe file will be marked as requiring admin right at the first place therefore when deploy you don't need to configure admin right requirement in file properties.
You can also set this administrator option automatically:
To answer the question in your title, you can just select Run as Administrator from the context menu when starting VS.
Now the checked answer will not working.
You should find an option for this in project properties Linker -> Manifest File -> UAC Execution Level. Set this to requireAdminstrator.
This will cause the default generated manifest to include the requestedExecutionlevel that you need, so that your users will be prompted automatically to elevate their privileges if they are not already elevated.
The "This task requires the application to have elevated permissions" error occurs because of The current user didn’t have a sufficient privilege to open Visual Studio.
As a temporary solution
You can overcome this issue by right-clicking on visual studio and select run as administrator at every time you intend to open it
As a permanent solution,
You can check the compatibility troubleshooting
Right, Click on Visual Studio > select Troubleshoot compatibility.
Select Troubleshoot Program.
Check The program requires additional permissions.
Click on Test the program.
Wait for a moment until the program launch. Click Next.
Select Yes, save these settings for this program.
For the detail steps with images, please check Visual Studio requires the application to have elevated permissions

Access to the registry key is denied (ABCPdf)

I am trying out ABCPdf 8.1 and when using the AddImageUrl(...) method I get the following error:
Access to the registry key 'HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl' is denied.
I have looked in the registry and main\featurecontrol does not exist for CURRENT_USER so I cannot change permissions on it.
Has anyone experienced this before, or know of any solutions I could try?
Thanks in advance
Who is the CURRENT_USER? Assuming it's an ASP.NET application identity, have you tried loading its user profile?
Open up IIS Manager and navigate to the application pool for your site. In the Advanced Settings dialog, set Load User Profile to True.
Perhaps it's a problem between IE9 and ABCPDF.If this error comes by using AddHtml() or AddImageHtml() , I suggest you to change the Rendering Engine from MSHtml to Gecko.
theDoc.HtmlOptions.Engine = EngineType.Gecko;
http://www.websupergoo.com/support.htm
In my case, this solution solved my error.
If you know the specific key that ABCPDF is trying to add, and you don't want to change the app pool settings, you can set the appropriate key in HKEY_LOCAL_MACHINE. We had exactly that situation and knew that ABCPDF wanted to add the FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI key. So we added the entries below to the registry. Note that the second key is specifically for 32-bit applications running on 64-bit Windows.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI]
"w3wp.exe"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI]
"w3wp.exe"=dword:00000001
I'm not sure if this is the answer but if you are trying to access this programaticaly your executable should run as administrator while accessing it. If you are in debug mode run visual studio as administrator (right click and select "Run as administrator"

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.

Categories