-5

Hello guys I created program which starts on startup but it gets error that says :

Could not find file 'C:\Windows\system32\Uribaani-Realm-Computer.ico'.

This file is installed in application folder. When I start program mannualy everything works fine.

Code where program shows error on mindump debugger.

NotifyIcon icon = new NotifyIcon();
icon.Icon = new Icon("Uribaani-Realm-Computer.ico");
icon.Visible = true;

I add autostart program from question answered below :

How to make an exe start at the Windows Startup

Community
  • 1
  • 1
Ben sin aspa
  • 100
  • 11

1 Answers1

2

The current folder is "C:\Windows\system32" when it's run automatically, so that's where it's looking for the ico file. You will need to provide the full path to the ico in your code.

If the file is in the same folder as the exe, you can use AppDomain.CurrentDomain.BaseDirectory. For example:

icon.Icon = new Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uribaani-Realm-Computer.ico"));
Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84