0

I am making a monitoring application that runs with Windows (Reg key added to HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run to make my app run on Windows Start).

Here's the behavior of my application :
- It logs some informations
- It takes a screenshot
- Upload everything to mysql
- Wait 10 seconds
- Does everything again

When I compile my application in VisualStudio2015, everything works fine.

When I decide to add the autorstart key in HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run, on Windows start, the application "seems" to freeze just before "Upload everything to mysql", here's the code just before "Upload everything to mysql" :

if (File.Exists(Directory.GetCurrentDirectory() + @"\screenshots\ScreenCapture.jpeg")) {

Is there anything denying my application from using "File.Exists" if the application is started by the registry (Windows) ?
Does my application has the same permissions ?

I have been struggling for 2 days on it and I would really appreciate some help.
Thanks.

Andrea
  • 3,370
  • 1
  • 17
  • 25
  • 2
    GetCurrentDirectory probably returns system directory. Have a look at [this answer](http://stackoverflow.com/a/15653938/754438) to get the idea. P.s. for path creation i suggest to use something like that: `Path.Combine(currentDir, "screenshots", "ScreenCapture.jpeg")` – Renatas M. Feb 02 '17 at 08:35
  • At windows start not everything necessarily has started, you may want to make it a scheduled task that runs on user login, not when windows starts up – BugFinder Feb 02 '17 at 08:47
  • @BugFinder I tried to start a bat (waiting 20 seconds) instead of starting the .exe directly on Windows start and the problem persists. – Sakarias Longhorn Feb 02 '17 at 08:53
  • 1
    Don't use `Directory.GetCurrentDirectory()`. If the file should be in the same folder as your executable, use `Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)` to get the directory name. – Matthew Watson Feb 02 '17 at 08:57
  • **Path.GetDirectoryName(Application.ExecutablePath);** worked ! You guys are my heroes. Thanks a lot! – Sakarias Longhorn Feb 02 '17 at 09:00

0 Answers0