Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

Passing in Command Line Arguments to C# .NET app Without Using Manifest File Inside a UWP App

I have a UWP app that I am developing that launches another application, which in turn launches a bat file, which does certain tasks, in order to not block the UI thread, while having enough permissions to do the tasks. The EXE I'm trying to launch is a separate .NET framework app that is in the same SLN, but a different project, in an app package project. However, the second C# app that the UWP app is launching requires command line arguments that may as often as the user of the app decides, so they can't be hard-coded into the manifest file, and using the following command:

await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("ArgumentGroupName");

Is there an alternative to the above command that allows for parameters to be passed in, while changing the parameter value is available at every launch? I've googled for days without finding any topic on this apart from one comment on an SO post that I can't find that says that it can be done without using the app's manifest file. I am using the latest version of Visual Studio 2019 with the latest .NET Framework (4.8) and Windows SDK (Windows 2004-compatible). The second C# app runs using the .NET Framework and the main UWP app uses the Windows SDK.

question from:https://stackoverflow.com/questions/65903808/passing-in-command-line-arguments-to-c-sharp-net-app-without-using-manifest-fil

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Passing in Command Line Arguments to C# .NET app Without Using Manifest File Inside a UWP App

For your requirement, you could pass the launcher parameter with LocalSettings. Store the parameter in the UWP client and retrieve value from launcher, then call process start with retrieved paramete.

For example

UWP Client

private async void btnClick_Parameters(object sender, RoutedEventArgs e)
{
    if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
    {
        // store command line parameters in local settings
        // so the Lancher can retrieve them and pass them on
        ApplicationData.Current.LocalSettings.Values["parameters"] = "command parameter";

        await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("Parameters");
    }
}

Launcher

string parameters = ApplicationData.Current.LocalSettings.Values["parameters"] as string;
Process newProcess = Process.Start(rootPath + @"WPFWPF.exe", parameters);

For more detail please refer stanfen's blog UWP with Desktop Extension – Part 2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...