According to the docs I can just use this: Windows.ApplicationModel.AppDisplayInfo.DisplayName
But I get error: An object reference is required for the non-static field, method, or property 'AppDisplayInfo.DisplayName
I can't add 'AppDiagnostics' capability or use the Package Display name which seems to be the most common solutions for this. Is the documentation wrong or am I doing something wrong?
If someone needs it for the WinUI 3
Windows.ApplicationModel.Package.Current.DisplayName
If you just want the DisplayName of your current project, you can use the following code without the need to declare the appDiagnostics capability:
string displayName = Windows.ApplicationModel.AppInfo.Current.DisplayInfo.DisplayName;
If you want the DisplayName of all running apps including UWP apps, Win32 apps, system services and so on, you need to add the appDiagnostics capability in manifest first.
Check the steps to add the appDiagnostics capability:
Add xmlns:rescap in Package and add rescap in IgnorableNamespaces. Then, add the appDiagnostics capability in Capabilities.
<Package xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
<Capabilities>
<rescap:Capability Name="appDiagnostics" />
</Capabilities>
</Package>
The appDiagnostics capability is a restricted capability, you need to get the permission from users. A user-consent prompt will be triggered at the first time calling the diagnostic APIs such as AppDiagnosticInfo.RequestInfoAsync(). Or users can open Settings panel, find the Privacy option and set the App Diagnostics.
Note that if permission is denied by users, then the APIs will only return information about the current app.
Add the following code to view the DisplayName of all running apps.
var list = await AppDiagnosticInfo.RequestInfoAsync();
foreach (var info in list)
{
string name = info.AppInfo.DisplayInfo.DisplayName;
}
Related
Basically I'd like to give users the ability to add shortcuts to other apps installed on their PC to my app so that they can launch them from within my app. I'd like for them to be able to launch Win32 apps AND UWP apps (Windows 10 Store apps). My app is not a file explorer, but users will simply have the ability to launch their favorite apps from within my app. I have my reasons for wanting this type of feature implemented. -__-
Is there a way UWP apps from within my UWP app?
UWP has provide a way to query installed UWP app for current user. you could use FindPackagesForUser to get them. And then call GetAppListEntriesAsync to get app entry for each app. If you want launch the app, just call LaunchAsync method. For more please refer the following sample code.
private async void FindBtn_Click(object sender, RoutedEventArgs e)
{
PackageManager manager = new PackageManager();
var packages = manager.FindPackagesForUser(string.Empty);
foreach (var package in packages)
{
var appEntries = await package.GetAppListEntriesAsync();
var firstApp = appEntries.FirstOrDefault();
if (firstApp != null)
{
await firstApp?.LaunchAsync();
}
}
}
Please note
``
Before call FindPackagesForUser, you need enable packageQuery capability
<Package
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap" >
......
<rescap:Capability Name="packageQuery" />
Is there a way to launch external .exe files
Currently, UWP has not provide such api to launch win32 app with path directly like classical desktop app, if you do want this feature, we suggest you make desktop extension for your UWP app, and get installed app and launch it within extension part.
Hello and thanks in advance. I'm writing this question because I've been serching the internet for weeks now and i still can't find the answer to my question. I need to include runtime permissions in my android aplication but I can't find a workig way to do this. My main problem is that I don't know where to put the requestPermissions() function.
First you need to specified the permission that your app needs in AndroidManifest.xml file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
After that you need to ensure the Xamarin.Android.Support.Compat NuGet package is included in your project because this package will backport permission specific APIs to older versions of Android.
If you are using Android 6.0 o later, you can check the permission or request in your activity using the method ContextCompat.CheckSelfPermission
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == (int)Permission.Granted)
{
// We have permission.
}
else
{
// Storage permission is not granted. If necessary display rationale & request.
}
I am trying to integrate different files and links to the Cortana voice commands using C#. Most of the applications are working fine when i copy those particular files in the Cortana voice command application folder but i am unable to launch an *.exe file (copied in the same folder). The usual error i am getting is access denied even after launching VS as admin. I am attaching the code line along with the error screenshot.
{"Abrir NAV", (Action)(async () => {
StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(#"Microsoft.Dynamics.Nav.Client.exe");
await Launcher.LaunchFileAsync(file);
})
},
Cortana Error
You could not launch executable file from your UWP app directly.
MSDN document has mentioned this point:
This API also imposes several restrictions on what types of files it can launch. Many file types that contain executable code, for example .exe, .msi, and .js files, are blocked from launching. This restriction protects users from potentially malicious files that could modify the system. From launcher documentation.
According to your description, your ".exe" file was contained in your UWP project. So, you could use the FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync() method to activate the full-trust Win32 component of an application from a Universal Windows app component in the same application package.
Please note the "full-trust" concept. You would need to declare "full-trust" for your ".exe" file in "Package.appxmanifest". For example:
<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:rescap= "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
IgnorableNamespaces="uap mp rescap desktop">
<Applications>
<Application>
...
<Extensions>
<desktop:Extension Category="windows.fullTrustProcess" Executable="MyFiles\ConsoleApp1.exe"/>
</Extensions>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust"/>
</Capabilities>
</Package>
Then, in code, you could call this method to launch that ".exe" file.
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
Is there a way to use or an alternative to InstallationManager.FindPackagesForCurrentPublisher? It looks like it is only for the phone.
I know you can launch an app by creating and then launching a URI, but I need to know if the app I want to launch is installed.
EDIT:
The app I want to launch is by the same publisher.
If we use the LaunchUriAsync(Uri) method to launch an app, system will firstly try to launch the installed app which registered this protocol, if the target app is not installed, then it will open the Store app and show the recommended apps which registered this protocol.
FindPackagesForCurrentPublisher method can only find the app packages with the same publisher ID as your app, for other app which is not with the same publisher, you will need to use FindPackages method, and this method requires ID_CAP_OEM_DEPLOYMENT. For desktop, there is no method now, you need special access to do that work, otherwise you can't break the sand box of UWP app.
But if your app won't be published into the Store, there is method which use PackageManager class to find the installed package. To use this class, you will need to add packageManagement capability into your app's manifest like this:
<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:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
...
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="packageManagement" />
</Capabilities>
</Package>
For this capability, you can refer to Special and restricted capabilities.
At last you can use this class in your app, for example list all the installed packages:
var packageManager = new PackageManager();
IEnumerable<Windows.ApplicationModel.Package> packages = (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackagesForUser("");
var list = packages.ToList();
Using the instructions from here: http://visualstudiogallery.msdn.microsoft.com/527286e4-b06a-4234-adde-d313c9c3c23e
Running Visual Studio 2013 as Admin with Update 2.
I create a C# BWRC project, TestBwrc. In Class.cs I add an int property that returns 1.
I add a new project to the solution, a C++ Brokered Windows ProxyStub called TestBwrc.Ps.
I add a reference to the TestBwrc project, and set project Linker properties to Register Output.
I then build the solution.
I add a new project to the solution, a C# blank windows store app, called TestBwrc.Client. I add a reference to the TestBwrc.Ps project.
Solution builds with no errors or warnings.
In the App.xaml.cs OnLaunched method I add TestBwrc.Class c = new TestBwrc.Class();
Visual Studio complains "Cannot resolve symbol 'Class'"
Solution builds with no errors or warnings.
Running the app throws an exception, TestBwrc.Class is not registered.
What am I missing?
Edit:
Also on TestBwrc.Client I added the Extensions tag to the app manifest with the ClassId of TestBwrc.Class and path Value of "..\Debug\TestBwrc.Ps"
The problem is the path Value of "..\Debug\TestBwrc.Ps" in the ActivateableClassAttribute as mentioned in my edit. Though %ProgramFiles% will be expanded, .. is not, nor is $(SolutionDir). So the for dev the only value that works is C:\dev\TestBwrc\Debug\TestBwrc.Ps
<Extensions>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
<Path>clrhost.dll</Path>
<ActivatableClass ActivatableClassId="TestBwrc.Class" ThreadingModel="MTA">
<ActivatableClassAttribute Name="DesktopApplicationPath" Type="string" Value="C:\dev\TestBwrc\Debug\TestBwrc.Ps" />
</ActivatableClass>
</InProcessServer>
</Extension>
</Extensions>