Starting application on start-up, using the wrong path to load

后端 未结 2 1008
旧巷少年郎
旧巷少年郎 2021-01-06 02:42

I am using registry key to set my application to load on Windows Startup(after a user login). My Code:

RegistryKey RegKey = Registry.LocalMachine;
RegKey = R         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 03:44

    Directory.SetCurrentDirectory() can be used to set your working directory when the app starts. EXE path can be retrieved using Application.ExecutablePath.

    Put them together:

    var fi = new FileInfo(Application.ExecutablePath);
    Directory.SetCurrentDirectory(fi.DirectoryName);
    

提交回复
热议问题