Run an application

  • Thread starter Thread starter Simone D'Onofrio
  • Start date Start date
S

Simone D'Onofrio

Hi, in framework I use the sub Shell to run an external program but in
compact framework i can't find it.

Any suggest?

Simone D'Onofrio
 
Simone,

use the opennetcf library then it's as simple as ...

OpenNETCF.Diagnostics.Process.Start("\myapp.exe", "")

Cheers,
Jo.
 
And in V1.1 (coming soon) we'll have Shell() too for VB.NET developers!

Peter
 
I have used PInvoke to call CreateProcess. Most of the parameters are
required to be null in CE, so it's pretty easy. Here's a C# example.

public struct PROCESS_INFORMATION
{
public UInt32 hProcess;
public UInt32 hThread;
public UInt32 dwProcessId;
public UInt32 dwThreadId;
}

[DllImport("coredll.dll", EntryPoint="CreateProcess", SetLastError=true)]
private static extern int CreateProcess(
string lpszImageName,
string lpszCmdLine,
IntPtr lpsaProcess, // null
IntPtr lpsaThread, // null
int fInheritHandles, //false
uint fdwCreate, // I don't use this parameter. It could be made available
as a bitwise enum ...
IntPtr lpvEnvironment, // null
IntPtr lpszCurDir, // null
IntPtr lpsiStartInfo, // null
ref PROCESS_INFORMATION lppiProcInfo
);

// public wrapper doesn't expose the mandatory parameters
public static int CreateProcess(
string lpszImageName,
string lpszCmdLine
ref PROCESS_INFORMATION lppiProcInfo;
)
{
if(lpszImageName != null)
{
if(!lpszImageName.EndsWith("\0"))
{
lpszImageName += "\0";
}
}
if(lpszCmdLine != null)
{
if(!lpszCmdLine.EndsWith("\0"))
{
lpszCmdLine += "\0";
}
}
return CreateProcess(
lpszImageName,
lpszCmdLine,
IntPtr.Zero, // null
IntPtr.Zero, // null
0, //false
0, // I don't use this parameter ...
IntPtr.Zero, // null
IntPtr.Zero, // null
IntPtr.Zero, // null
ref lppiProcInfo
);
}
}
 
Back
Top