Unauthorized Access Exception writing file from .exe
I think that it is a problem with permissions to the folder.
Probably Visual Studio runs your application as an administrator and the .EXE file is executed as a normal user.
why to I get this error: System.UnauthorizedAccessException: 'C:\Windows\system32\CSV_file'
This happens because when your program is called by the batch the current folder is not the one you have your executable and windows doesn't care to change the current directory to your folder. The only thing that matters is the availability of your program and this is granted because you give the full path to the START command.
You can fix your problem changing the START command and specifying the folder where your program should be run
START /D C:\Debug C:\Debug\DiagnisticTool.exe
or adding a CD command just before running the file
CD C:\DEBUG
START C:\DEBUG\DiagnosticTool.exe
or changing the path passed to StreamWriter
using (StreamWriter outputFile = File.AppendText(@"C:\debug\PerformanceLogFile.csv"))
this last option, while allowing to leave your batch as is, could be a problem if you want to customize the output folder. For example if you are not allowed to create a C:\DEBUG folder on the target machine or for some other reason.
Access to path denied while reading a dll from Program Files which is actually got from a nuget package
For this application, even for reading the DLLs from the Program Files folder I needed Admin rights so I forced the application to have such rights for execution.
The below line for the newly created application manifest file is changed and that solved the issue.
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
The fix is explained well in How do I force my .NET application to run as administrator?
The reasons are stated well in https://stackoverflow.com/a/50588465/129130
System.UnauthorizedAccessException (A first chance exception)
You need to run your app as admin.
Here's he right way to do it:
http://blogs.msdn.com/b/nikhiln/archive/2007/04/19/embed-a-manifest-to-make-an-application-elevate-in-vista.aspx
Related Topics
Sqlcommand Parameters Add VS. Addwithvalue
ASP.NET MVC $.Post Call Returning String...Need Help with Format for Jqgrid
Authenticate and Request a User's Timeline with Twitter API 1.1 Oauth
Getting the Size of a Field in Bytes with C#
How to Send Sms Through C# Code Using System.Io.Ports Using Gsm Modem
Associating Enums with Strings in C#
Get Name of Property as a String
Differencebetween Debug and Release in Visual Studio
The Name 'Controlname' Does Not Exist in the Current Context
Parallel.Foreach and Async-Await
Vb.Net Equivalent for C# 'Dynamic' with Option Strict On
How to Check the .Net Framework Version
Fire and Forget Async Method in ASP.NET MVC
Most Common C# Bitwise Operations on Enums
Interop Type Cannot Be Embedded
.Net Core MAChine Key Alternative for Webfarm