Starting a process with Windows start-up (can not find supporing files)

会有一股神秘感。 提交于 2021-02-05 12:20:50

问题


I programmed (C# .Net 3.5) a process to start when windows (XP) starts. This process uses other files in the same folder as itself. Moreover, it starts another process, again located in the same folder.

However, it seems like the process cannot find the files in the same folder (they are there). Instead, it looks in "C:\Documents and Setting\User" folder. Whenever, all the files are in this folder it starts properly but NOT when they are in a different folder.

The process is made to start with Windows start-up by registering it in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run


回答1:


You may try setting the working directory when you start your process:

Directory.SetCurrentDirectory(
    Path.GetDirectoryName(
        Assembly.GetExecutingAssembly().Location
    )
);

If you later try accessing a file in the same directory as the process executable by specifying a relative path it should be able to find it.



来源:https://stackoverflow.com/questions/1585127/starting-a-process-with-windows-start-up-can-not-find-supporing-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!