gpt4 book ai didi

windows - 使用注册表来启动一个程序,同时改变当前的工作目录?

转载 作者:可可西里 更新时间:2023-11-01 12:42:43 25 4
gpt4 key购买 nike

我正在尝试启动我在此目录中制作的程序:

C:\example\example.exe -someargument

当计算机启动时。我正在尝试使用此注册表项:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

关键是:

Name: example
Type: REG_SZ
Data: "C:\example\example.exe -someargument"

但我的程序还需要目录 C:\example 中的文件,但由于当前工作目录不同,所以无法找到它们。是否可以在注册表项值中执行类似的操作

"cd C:\example\; example.exe -someargument"

这样它会改变目录?或者有更好的解决方案吗?

谢谢!

最佳答案

您可以在下一个注册表项下注册您的应用程序(像这样 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"); 将使用指定的工作路径启动您的应用程序。

或者另一种方式:使用 C# 编写启动器。您可以使用 PowerShell cmdlet 执行相同的操作。

var info = new System.Diagnostics.ProcessStartInfo(@"c:\example\example.exe", "-someargument")
{
WorkingDirectory = @"c:\AnotherPath"
};
System.Diagnostics.Process.Start(info);

关于windows - 使用注册表来启动一个程序,同时改变当前的工作目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2822951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com