WPF - 附加文件夹,其中包含许多要安装在用户 C 驱动器中的 clickonce 部署的文件



我正在开发一个WPF应用程序,该应用程序具有在用户PC中运行"CMD"的功能,并导航到应用程序文件中包含的一个文件夹"平台工具"并执行命令。

string Request = " /c" + "cd../../&cd platform-tools& adb reboot ";
Process procc = new Process();
ProcessStartInfo procStartInfo2 = new ProcessStartInfo(@"cmd.exe", Request);

众所周知,当用户在他的PC中安装应用程序时,该应用程序将位于C:\Users"用户名\AppData\Local\Apps\2.0"随机名称中,例如:JBJHV6HG7HG" 因此,很难知道"平台工具"将安装在哪里。

我的问题是:有什么方法可以知道如何通过我的"请求"访问平台工具文件夹以运行 adb 命令?

有没有办法将"平台工具"安装在不同的位置,例如"用户的桌面",然后我可以更改CMD中的"CD"命令以导航到用户的桌面或C驱动器?

使用 ClickOnce,由于某些安全功能等,您将无法更改目标安装文件夹... 你可以在这里找到更多信息

您可以获取执行进程的路径,并连接文件夹名称以到达"platform-tools"文件夹:

//There's two ways to get the current file address from your application (in the end both ends in the same):
//There's two ways to get the current file address from your application (in the end both ends in the same):
//getting the filename by the process
var cc = Process.GetCurrentProcess().MainModule.FileName;
//getting the filename by the executing assembly
var dd = System.Reflection.Assembly.GetExecutingAssembly().Location;
//getting the path for that file name
string assemblyPath = Path.GetDirectoryName(cc);

var platformTools = string.Concat(assemblyPath, @"/platform-tools/someprocess.exe");
Process.Start(platformTools);

最新更新