问题
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