Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Shellexeute startet Win8 app nicht (https://www.delphipraxis.net/177025-shellexeute-startet-win8-app-nicht.html)

punki 10. Okt 2013 18:20

Shellexeute startet Win8 app nicht
 
Hallo,

ich betreibe eine Win32-Anwendung (Delphi XE2) auf einem Tablet-PC mit Windows 8 Pro.
Aus der Delphi-Anwendung möchte ich einige Win8-apps starten (z.B. Kamera = C:\Windows\Camera\Camera.exe).

Leider funktioniert der Winapi-Aufruf "Shellexecute" nicht. Die Kamera-App (camera.exe) kann auch nicht per Doppelklick aus dem Windows Explorer gestartet werden, sondern nur aus der Metro-Oberfläche klappt das.

Der Delphi Programmcode:

// sollte die Kamera-App unter Win8 starten
procedure TForm1.bt_KameraClick(Sender: TObject);
var rslt : integer;
begin
rslt := ShellExecute_woWait ('C:\Windows\Camera\Camera.exe','');
end;

// Winapi-Aufruf:
function ShellExecute_woWait(FileName: string; Params: string):integer;
var exepath:string;

begin
Result := 0;
if (not FileExists(FileName)) then begin
Result := ERROR_FILE_NOT_FOUND;
exit;
end;

exepath := extractFilepath(FileName);
Result := ShellExecute(0, // handle to parent window
nil, // pointer to string that specifies operation to perform (--> klappt auch nicht mit 'open')
PChar(FileName), // pointer to filename string
PChar(Params), // pointer to string that specifies executable-file parameters
PChar(exepath), // pointer to string that specifies default directory (--> klappt auch nicht mit nil)
SW_SHOWNORMAL // whether file is shown when opened
);
// >32: erfolgreich
if Result>32 then
Result := 0;
end;


Wie kann ich aus einer Win32-Anwendung eine Win8 app starten?

Danke.

Punki:)

ringli 10. Okt 2013 20:34

AW: Shellexeute startet Win8 app nicht
 
Welchen Fehler gibt ShellExecute denn zurück bzw. was sagt GetLastError?

jaenicke 10. Okt 2013 20:58

AW: Shellexeute startet Win8 app nicht
 
Zitat:

Zitat von ringli (Beitrag 1231684)
Welchen Fehler gibt ShellExecute denn zurück bzw. was sagt GetLastError?

Was bringt das in dem Fall? Der Start ist nun einmal so nicht möglich.

Das Problem ist, dass eine App nur mit einer entsprechenden Umgebung (in einem App-Container) gestartet werden kann. Wie man das aus einer Desktop-Anwendung heraus machen kann, weiß ich aber auch nicht.

jfheins 10. Okt 2013 22:42

AW: Shellexeute startet Win8 app nicht
 
Ich habe da mal einen Artikel aufgetrieben: http://blogs.msdn.com/b/windowsappde...ws-8-apps.aspx
Dort wird automatisches Testen beschrieben. Ein Teil davon ist es, die Win8 App aufzurufen.
Im wesentlichen muss man wohl das Interface "IApplicationActivationManager" verwenden.

C# Code gibt es wohl hier: http://stackoverflow.com/questions/1...plication-in-c

punki 13. Okt 2013 19:20

AW: Shellexeute startet Win8 app nicht
 
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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:07 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz