使用注册表启动程序,并更改当前工作目录? [英] Use registry to startup a program, and also change the current working directory?
问题描述
我正在尝试启动我在此目录中制作的程序:
I am trying to start a program I made in this directory:
C:\example\example.exe -someargument
当计算机启动时.我正在尝试使用此注册表项:
when the computer starts up. I am attempting to use this registry key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
关键是:
Name: example
Type: REG_SZ
Data: "C:\example\example.exe -someargument"
但我的程序也需要目录 C:\example 中的文件,但由于当前工作目录不同而无法找到它们.是否可以在注册表项值中执行类似操作
But my program also needs files from the directory C:\example but can't find them since the current working directory is different. Is is possible to do something like this in the registry key value
"cd C:\example\; example.exe -someargument"
所以它会改变目录?或者有更好的解决方案吗?
so that it will change the directory? Or is there a better solution?
谢谢!
推荐答案
您可以在下一个注册表项下注册您的应用程序(就像这样 Reg2Run 工具)
You can register your application under next registry key (like this does Reg2Run tool)
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\example.exe
@="c:\example\example.exe"
Path="c:\AnotherPath"
所以 System.Diagnostics.Run("example.exe");
将使用指定的工作路径启动您的应用程序.
So System.Diagnostics.Run("example.exe");
will launch your application with specified working path.
或者另一种方式:使用 C# 编写启动器.您可以使用 PowerShell cmdlet 执行相同操作.
Or another way: write a launcher using C#. You can do the same using a PowerShell cmdlet.
var info = new System.Diagnostics.ProcessStartInfo(@"c:\example\example.exe", "-someargument")
{
WorkingDirectory = @"c:\AnotherPath"
};
System.Diagnostics.Process.Start(info);
这篇关于使用注册表启动程序,并更改当前工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!