繁体   English   中英

WPF - 附加包含许多文件的文件夹,单击一次部署将安装在用户 C 驱动器中

[英]WPF - Attach Folder that has many files with clickonce deployment to be installed in user C drive

我正在开发一个 WPF 应用程序,它具有在用户 pc 中运行“CMD”并导航到应用程序文件中包含的一个文件夹“platform-tools”并执行命令的功能。

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

我们知道,当用户在他的 PC 上安装应用程序时,应用程序将位于 C:\\Users\\""UserName\\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);

正如我在评论中已经提到的,您可以在子文件夹中使用Directory.GetDirectories方法来递归搜索platform-tools目录,然后从该目录调用可执行文件,而无需运行cd命令

using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
...

//get app location
var executablePath = Assembly.GetExecutingAssembly().Location;
//find platform-tools
var dir = Directory.GetDirectories(executablePath, "platform-tools", SearchOption.AllDirectories).FirstOrDefault();
//run executable
var path = Path.Combine(dir, "adb");
var startInfo = new ProcessStartInfo("cmd.exe", $"/c \"{path}\" reboot ")
{
    UseShellExecute = false,
    CreateNoWindow = true
};
Process.Start(startInfo);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM