Einzelnen Beitrag anzeigen

punki

Registriert seit: 11. Nov 2005
5 Beiträge
 
#5

AW: Shellexeute startet Win8 app nicht

  Alt 13. Okt 2013, 19:20
Danke für die Hinweise,

ich habe inzwischen eine Lösung mit Powershell gefunden: http://poshcode.org/3740

Ich starte damit von meinem Delphi-prog die Camera-app unter Win8 mit Shellexecute.

rslt := ShellExecute_woWait ('C:\Windows\System32\WindowsPowerShell\v1.0\power shell.exe' , 'Camera.ps1', SW_SHOWMINIMIZED)

//-----------------------------------
Camera.ps1:

$code = @"
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Win8 {
public enum ActivateOptions
{
None = 0x00000000, // No flags set
DesignMode = 0x00000001, // The application is being activated for design mode, and thus will not be able to
// to create an immersive window. Window creation must be done by design tools which
// load the necessary components by communicating with a designer-specified service on
// the site chain established on the activation manager. The splash screen normally
// shown when an application is activated will also not appear. Most activations
// will not use this flag.
NoErrorUI = 0x00000002, // Do not show an error dialog if the app fails to activate.
NoSplashScreen = 0x00000004, // Do not show the splash screen when activating the app.
}

[ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
interface IApplicationActivationManager
{
// Activates the specified immersive application for the "Launch" contract, passing the provided arguments
// string into the application. Callers can obtain the process Id of the application instance fulfilling this contract.
IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
}

[ComImport, Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]//Application Activation Manager
public class ApplicationActivationManager : IApplicationActivationManager
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/]
public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
}
}
"@

add-type -TypeDefinition $code
$appman = new-object Win8.ApplicationActivationManager

function Get-MetroApp {
$entry = 'HKCU:\Software\Classes\ActivatableClasses\Package '
foreach ($appkey in (dir $entry |select -ExpandProperty pspath)) {
#$id = ((dir (join-path $appkey 'Server')) |Get-ItemProperty).appusermodelid
$id = (dir (Join-Path $appkey server) |?{$_.pspath -notmatch 'BackgroundTransferHost.1'} |Get-ItemProperty).appusermodelid
if ($id) {
$possibleclassidkeys = dir (join-path $appkey 'ActivatableClassID') |select -ExpandProperty pspath
# we look for the app key first, then app.wwa, and then any other key if neither returns an entrypoint
$key = $possibleclassidkeys |?{$_ -match 'app$'}
$entrypoint=$null
if ($key) {
if (Test-Path (join-path $key CustomAttributes)) {
$entrypoint = (Get-ItemProperty (join-path $key CustomAttributes)).('appobject.entrypoint')
}
}
if (!$entrypoint) {
$key = $possibleclassidkeys |?{$_ -match 'app.wwa$'}
if ($key) {
if (Test-Path (join-path $key CustomAttributes)) {
$entrypoint = (Get-ItemProperty (join-path $key CustomAttributes)).('appobject.entrypoint')
}
}
}
if (!$entrypoint) {
foreach ($key in $possibleclassidkeys) {
if (Test-Path (join-path $key CustomAttributes)) {
$entrypoint = (Get-ItemProperty (join-path $key CustomAttributes)).('appobject.entrypoint')
break
}
}
}
new-object psobject -Property ([ordered] @{
EntryPoint = $entrypoint
ID = $id
})
}
}
}

function Start-MetroApp {
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
[string] $ID
)
$appman.ActivateApplication($ID,$null,[Win8.ActivateOptions]::None,[ref]0)
}

Start-MetroApp Microsoft.MoCamera_cw5n1h2txyewy!Microsoft.Camera

end of Camera.ps1.
  Mit Zitat antworten Zitat