- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试从 UWP 应用启动位于 C:/Program Files (x86)/App 中的 exe。我该怎么做。
我可以使用 UWP 的 Windows 桌面扩展来启动 exe 文件,添加隐藏复制代码
<Extensions>
<desktop:Extension Category="windows.fullTrustProcess" Executable="Assets\app.exe" />
</Extensions>
到 Package.appmanifest 并调用它
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
在主类中。但是我需要将 app.exe 添加到项目的 Assets 目录
我的问题是,如果 exe 文件位于其他目录中,我如何在不准确添加 exe 文件的情况下启动它。
谢谢
最佳答案
今天我编写了一个程序来成功地从 UWP 启动任何 .exe 程序。想要分享这个过程以造福他人。这是对 stefan Wick MSFT 的回答的补充。首先需要更新 package.appmanifest。这是我在 package.appmanifest 中的内容:
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp">
<Identity
Name="217d09c4-aa67-4403-939f-518a55d46f16"
Publisher="CN=admin"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="217d09c4-aa67-4403-939f-518a55d46f16" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>App1</DisplayName>
<PublisherDisplayName>admin</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.14393.0" MaxVersionTested="10.0.16299.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="App1.App">
<uap:VisualElements
DisplayName="App1"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="App1"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<desktop:Extension Category="windows.fullTrustProcess" Executable="Assets\Launcher.exe" >
<desktop:FullTrustProcess>
<desktop:ParameterGroup GroupId="ChromeGroup" Parameters="chrome.exe"/>
<desktop:ParameterGroup GroupId="WordGroup" Parameters="WINWORD.exe"/>
</desktop:FullTrustProcess>
</desktop:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient"/>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
<Extensions>
内的代码标签是负责启动可执行文件的标签。带有<Capabilities>
的代码标签添加启动可执行文件的能力或权限。限制性能力如runFullTrust
它下面有绿色的绿线。这不是错误,程序将运行而不会出现任何错误。 Launcher.exe
上面的代码中是一个控制台应用程序。我在文本编辑器中编写代码并从中创建 Launcher.exe。 Launcher.exe 的代码是这样的:
using System;
using System.IO;
using System.Diagnostics;
using System.Reflection;
class Program
{
static void Main(string []args)
{
try
{
if(args.Length!=0)
{
string executable=args[2];
/*uncomment the below three lines if the exe file is in the Assets
folder of the project and not installed with the system*/
/*string path=Assembly.GetExecutingAssembly().CodeBase;
string directory=Path.GetDirectoryName(path);
process.Start(directory+"\\"+executable);*/
Process.Start(executable);
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
将此 Launcher.exe 控制台应用程序保存在 UWP 项目的 Assets 文件夹中。不允许 UWP 启动 .exe 应用程序。但是 UWP 应用调用此代码来启动任何 .exe 程序。 GroupId ChromeGroup 用于通过将 chrome.exe 参数传递给 Launcher.exe 来启动 chrome 浏览器。 GroupId WordGroup 用于通过将 WINWORD.exe 参数传递给 Launcher.exe 来启动 MS Word。将参数传递给 Launcher.exe 的代码是:
`private async void Button_Click(object sender, RoutedEventArgs e)
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("ChromeGroup");
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("WordGroup");
}`
点击上方的按钮 Api
将 exe 文件的名称传递给 Launcher.exe
程序。它通过接受 GroupId
来做到这一点作为参数。 Api
在 Windows.ApplicationModel
下可用命名空间。
编辑:
您要启动的可执行文件可能未安装在系统上。它可能不会与您的应用程序一起打包在 Assets 文件夹中。你可以在 Parameters
中给出可执行文件的完整路径属性。
关于c# - UWP:如何启动位于特定目录中的 exe 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49189353/
我正在为我的程序编写安装脚本,它应该在 Linux/Unix 操作系统上运行。以下文件的默认目录是什么: 可执行文件(程序)。程序应通过从命令行键入其名称来执行。 共享库。 第三方共享库(程序未开源,
我有一堆用户、组和应用程序注册,我的 MVC 应用程序使用 AAD 数据进行身份验证和授权。是否可以将 Azure Active Directory 从一个租户(目录)迁移到另一个租户(目录)?如果可
查看 cljsbuild 文档 https://github.com/emezeske/lein-cljsbuild :cljsbuild { :builds [{ ; The
忽略已经版本控制的文件 如果你不小心添加了一些应该被忽略的文件,你如何将它们从版本控制中去除而不会丢失它们?或许你有自己的IDE配置文件,不是项目的一部分,但将会花费很多时间使之按照自己的方式工作。
我想使用\tableofcontents 命令,但没有目录从新页面开始或在末尾创建新页面,并且所有内容都是单倍行距。我怎样才能做到这一点?我假设使用 tocloft,但有哪些选择? 谢谢 最佳答案 试
我有一些 javascript 菜单代码,可以在单独的目录中正常工作。但是,当我尝试从同一目录中调用相同的 .js 文件时,它不会看到这些文件。 以下内容来自另一个目录: script type="t
我有这样的路径: /my/path/to/important_folder 在同一级别上,我还有其他文件和文件夹想要在达到与 important_folder 相同的级别时列出。 我的文件夹可能更深,
1、获取文件路径实现 1.1 获取当前文件路径 ? 1
我正在使用最新版本的 NTEmacs。 我写了一个名为“.dir-locals.el”的文件,如下所示。 ((nil . ((tab-width . 8) (fill-column .
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
在我的 .vimrc 中有这些行 :set foldmethod=marker :set foldmarker=SECTION:,ENDSECTION: 用于自定义代码折叠。在我的文件中,相关语言的注
在 fish 中: for x in * echo $x end *这里包括所有目录和文件,如何只列出文件(或目录)? 最佳答案 fish 没有很多花哨的通配语法。但是,目录可以像这样迭代: f
这是我的目录结构: ├── src │ ├── helpers │ │ ├── __init__.py │ │ ├── foo.py │ │ └── bar.py │
我想递归重命名文件夹/目录名称并找到 this solution所以。但是这个命令没有效果 find . -type f -exec rename 's/old/new/' '{}' \; 这是一个正
我想在相册中创建一个文件夹,并希望将图像保存在创建的相册中。 这可能吗?有什么办法可以做到这一点吗? 我已经搜索过,大多数人都说这是不可能的。 感谢您的帮助。 最佳答案 您也许可以使用AssetsLi
如何在python中使用用户定义的名称创建临时文件/目录。我知道 tempfile .但是我看不到任何以文件名作为参数的函数。 注意:我需要这个来对包含临时文件的临时目录上的 glob(文件名模式匹配
我在项目中使用JaCoCo Gradle插件。 作为问题的一个示例,我的大部分代码都在com.me.mysoftware包下。 我正在使用代码生成器来生成build/generated/java/..
我正在尝试使用 Gradle 开始运行 jar 文件 我的任务如下所示: task startServer(type: Exec) { workingDir file("${buildDir}/a
如何在 Ant 中定义一个目录集,其中包括两个目录:项目的基目录和子目录“test”? 看起来您无法使用“/”、“.”或“”专门包含目录集的根目录。例如,这包括“./test”,但不包括“.”:
我正在使用 CTAGs 包,它使用 Sublime Text 2 生成两个文件 .tags 和 .tags_sorted_by_file。 那么当我进行项目搜索(CMD + SHIFT + F)时,如
我是一名优秀的程序员,十分优秀!