Programmaufruf mit Compact Framework auf WindowsXP

Hallo,
ich habe folgendes Problem:

Ich möchte ein Programm aus C# heraus starten. Das hört sich noch ziemlich simple an,
ABER
ich will das Compact Framework nutzen, damit meine Applikation sowohl auf XP als auch auf CE läuft. Somit gibt es kein System.Diagnostic.Process sondern nur CreateProcess mit DLL-Import … ok, habe ich für Windows CE auch hinbekommen
ABER
Der Aufruf funktioniert leider nicht auf Windows XP. Vielleicht müssen die Parameter anders gesetzt werden, oder vielleicht gibt es eine ganz andere Lösung, keine Ahnung.

Soweit die Schilderung des Problems. Alles zusammen nochmal in EINER Frage formuliert:

Wie starte ich aus C# (.NET Compact Version) ein externes Programm unter Windows XP ???

Danke im voraus!
Beanpole

Auch hallo.

Also ich benutze SharpDevelop unter W2k3 und von daher interessiert mich ein solches Problem verständlicherweise (nicht…).
Aber probier’s mal hier: http://www.entwickler-forum.de/[email protected]
(Wie eine .exe starten und 2 Beiträge gleich auf der ersten Seite)
Stammt übrigens aus dem .NET Framework Forum von www.derentwickler.de

HTH Java 4ever !!!
mfg M.L.

Auch hallo.

Die genannten Foren habe ich schon durchsucht … ohne brauchbare Ergebisse!

auf dem Pocket PC finktioniert die Sache mit:

CreateProcess(„iexplore.exe“, webaddress, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, new Byte[128], pi);

Vielleicht weiß ja jemand, wie man mit CreateProcess auf NICHT-WindowsCE weiterkommt!?

Gruß,
Beanpole

Hi!
Wie hast Du denn das CreateProcess deklariert? Fast alle merkwürdingen Probleme mit .NET hatte ich durch fehlerhafte Interop-Deklarationen.
Insbesondere würde ich mir die letzten beiden Parameter anschauen. Vielleicht liegt es an so trivialen Punkten wie der nicht belegten Strukturgröße cb der STARTUPINFO?

Gruß,
Martin

[Bei dieser Antwort wurde das Vollzitat nachträglich automatisiert entfernt]

Hallo,

die Deklaration:
>----
[DllImport(„coredll.Dll“)]
private static extern int CreateProcess(string strImageName, string strCmdLine, IntPtr pProcessAttributes, IntPtr pThreadAttributes , int bInheritsHandle, int dwCreationFlags, IntPtr pEnvironment, IntPtr pCurrentDir, Byte[] bArray, ProcessInfo oProc);

ProcessInfo pi = new ProcessInfo();

public class ProcessInfo
{
public int Process;
public int Thread;
public int ProcessID;
public int ThreadID;
}

System.Runtime.InteropService.MarshallDirectiveException: parameter #10 kann nicht gemarshallt werden: Die Typendefinition für diesen Typ enthält keine Layoutinformationen.

Für solche Fragen schaust Du vielleicht am besten hier: http://pinvoke.net/
Da findet man für praktisch alles und jedes die (meist) korrekten Deklarationen. Und wenn man irgendwo einen Fehler findet, dann kann man ihn auch gleich für den Rest der Welt korrigieren :smile:

Für WinXP findet sich CreateProcess übrigens nicht in coredll.dll, sondern in kernel32.dll. Wenn Du deshalb aber ohnehin unterscheiden musst, welche Version es gerade ist kannst Du m.M. nach im nicht-CE-Fall auch die normalen Process-Klassen verwenden, oder?

Martin

[Bei dieser Antwort wurde das Vollzitat nachträglich automatisiert entfernt]

Hallo und Vielen Dank,

ich habe gefunden was ich brauchte! :smile:

Hier die Beispiellösung, falls z.B. „C://Programme/Textpad/Textpad.exe“ gestartet werden soll!

>----
public class Extern_pc
{
public Extern_pc()
{
}

[DllImport(„kernel32.dll“)]
static extern bool CreateProcess(string lpApplicationName,string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles,uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,[In] ref STARTUPINFO lpStartupInfo,out PROCESS_INFORMATION lpProcessInformation);

public void StartupTextpad()
{
const uint NORMAL_PRIORITY_CLASS = 0x0020;
bool retValue;
string Application = „C://Programme/Textpad/Textpad.exe“;
string CommandLine = @" c:\boot.ini";
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
STARTUPINFO sInfo = new STARTUPINFO();
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
pSec.nLength = Marshal.SizeOf(pSec);
tSec.nLength = Marshal.SizeOf(tSec);

retValue = CreateProcess(Application,CommandLine, ref pSec,ref tSec,false,NORMAL_PRIORITY_CLASS,
IntPtr.Zero,null,ref sInfo,out pInfo);
}

public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public bool bInheritHandle;
}

public struct STARTUPINFO
{
public uint cb;
public IntPtr lpReserved;
public IntPtr lpDesktop;
public IntPtr lpTitle;
public uint dwX;
public uint dwY;
public uint dwXSize;
public uint dwYSize;
public uint dwXCountChars;
public uint dwYCountChars;
public uint dwFillAttribute;
public uint dwFlags;
public ushort wShowWindow;
public ushort cbReserved2;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdError;
}

public struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public uint dwProcessId;
public uint dwThreadId;
}

}//end_class_Extern_pc