I have written a code in C#. The code is loging into a file the following:
- CPU Usage
- RAM Usage
- Network card traffic
- Current time
I want that on system startup the code will be executed automatically. So I have written a batch file that runs the .exe file like that:
START 'C:\Debug\DiagnisticTool.exe'
while DiagnisticTool.exe is the application and it is contained in a folder named 'Debug' at C drive. The batch file is in the windows startup folder.
While I start my PC the batch file is running and than the error stated above comes up. This is how the file is been written in the script code:
using (StreamWriter outputFile = File.AppendText("PerformanceLogFile.csv"))
{
outputFile.WriteLine(something to write to file);
}
yet the error stateds that it tries to write it somewere else: 'C:\Windows\system32'.
Why is that?
When I run the program via visual studio or via the .exe application that it created it is runing OK. Plus when I run the batch file manually it works fine. The ONLY problem is that it doesn't run at startup as it should.