Sanandan

Hi all,
I have a .net CF 2.0 console app which uses Process.Start("filename","commandlinearg") function to open another .exe or .cab file. I want this to happen in .net CF 1.0 app also. But it doesn't have System.Diagnostics.Process class. Please somebody suggest me how do I do it.

Thanks and regards
Sanandan B.K.


Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Christopher Fairbairn

Hi,

You could have a look at OpenNETCF's Smart Device Framework (SDF) library, it contains a similar class in the older 1.4 version http://www.opennetcf.com/Default.aspx tabid=91.

If you don't want to use this library you could also have a look at PInvoking the CreateProcess Win32 function as documented in MSDN here http://msdn2.microsoft.com/en-us/library/ms885182.aspx, or possible ShellExecuteEx as documented here http://msdn2.microsoft.com/en-us/library/aa453684.aspx depending upon your requirements.

Hope this helps,

Christopher Fairbairn






Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Sanandan

Hi Christopher Fairbairn,

I have gone through msdn link you mentioned. It is not clear to me how I can use CreateProcess or ShellExecuteEx. My code is in C# and it is Windows Mobile 5.0 application. It would be very helpful if you can give me some more hints.

Thanks and Regards
Sanandan




Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Christopher Fairbairn

Hi,

Perhaps the easiest way then would be to use the Smart Device Framework assembly, which contains a class which looks and feels just like System.Diagnostics.Process.

Here is an example of how you may manually wrap a call to CreateProcess from within C# while targeting the Compact Framework 1.0:

Code Snippet

using System.Runtime.InteropServices;

private void button1_Click(object sender, EventArgs e)

{

StartApplication(@"\windows\clock.exe", "");

}

private void StartApplication(string executable, string arguments)

{

ProcessInfo pi = new ProcessInfo();

CreateProcess(executable, arguments, IntPtr.Zero, IntPtr.Zero,

0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pi);

CloseHandle(pi.hProcess);

}

private sealed class ProcessInfo

{

public IntPtr hProcess = IntPtr.Zero;

public IntPtr hThread = IntPtr.Zero;

public int dwProcessID = 0;

public int dwThreadID = 0;

}

[DllImport("coredll.dll", SetLastError = true)]

private static extern bool CreateProcess(string lpApplicationName,

string lpCommandLine, IntPtr lpProcessAttributes,

IntPtr lpThreadAttributes, int bInheritHandles,

int dwCreationFlags, IntPtr lpEnvironment,

IntPtr lpCurrentDirectory, IntPtr lpStartupInfo, ProcessInfo pi);

[DllImport("coredll.dll", SetLastError = true)]

private static extern int CloseHandle(IntPtr h);

Hope this helps,

Christopher Fairbairn






Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Sanandan

Hi Christopher,

I tried to run your code snippet. But it didn't work. I think problem may be with coredll.dll. I searched the whole computer but couldn't find coredll.dll. Where in the system I shall put coredll.dll Shall I have to add something to the code snippet Could you please help

Thanks and Regards
Sanandan




Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Christopher Fairbairn

Hi Sanandan,

Coredll.dll is a dll which is very central to the Windows CE operating system. It will be located within the \Windows directory on the PDA (although it is probably hidden depending upon what sort of tool you are using to view the filesystem).

Can you explain how it didn't work Did you get an exception when it ran, or did it run but simply failed to start the application It would also be helpful if you can explain what sort of device you are attempting to run this code on.

Can you put a break point in the call to the StartApplication method and step through what is happening. In particular what the value of pi.hProcess towards the end of the StartApplication method is.

Hope it helps,

Christopher Fairbairn






Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Christopher Fairbairn

Hi Sanandan,

Here's some additional articles and posts which may help you get something working, they all show code extracts which are slight variants of the same underlying process PInvoking the CreateProcess function from the OS.

Just to verify I hadn't made a typo etc during posting to the forum I copy and pasted the sample code I posted a few postings ago into a new Windows Mobile 5.0 C# winforms project, dragged a button ontop the form and hooked up the click event handler and the code seemed to still be working for me.

Hope it helps,

Christopher Fairbairn






Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Sanandan

Hi Chrisopher,
Thanks for your replies. I tried the slight variation of your code snippet (from the link you sent). It opens any exe but not cab files. I want my cab files to be opened too (i.e., installed). Please suggest something.

Thanks and regards
Sanandan




Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Christopher Fairbairn

Hi sanandan,

For that to happen automatically (when you just pass in the CAB file name) you should look PInvoking the ShellExecuteEx function as documented here http://msdn2.microsoft.com/en-us/library/aa453684.aspx. You can ask it to "open" a CAB file and it will look up the registry to file the application associated with files of this type.

Alternativly you can use the same approach you are currently using (if you don't mind hardcoding the executable name). CAB files are installed by an application called wceload.exe which can be found in the windows directory of your device (i.e. \windows\wceload.exe).

You can use the method you are currently using to launch a process to launch \windows\wceload.exe, the cab file you want installed can be passed as a command line argument. You can find more documentation on the various command line arguments wceload.exe supports (to do things like silent installs) within MSDN at http://msdn2.microsoft.com/en-us/library/ms933760.aspx

One tip when using this approach is that your cab file path should be enclosed in quote marks if the path contains any spaces.

Hope this helps,

christopher Fairbairn






Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Sanandan

Hi Christopher,
You have been so helpful. Thank you.
With wceload.exe, I can install CAB files. But I need to install more than one CAB file. For this I need to know when the installation is completed. This I have to do from the remote desktop. On remote desktop, I am using OpenNETCF.Desktop.Communication.RAPI object. I didn't find any wait method in RAPI. I am finding out completion of installation by checking whether the cab file exists or not because after installation cab file is deleted. After this I start another cab installation. But the problem is, there comes a message after the installation about successful installation on the handheld device and in case of .NET CF 2.0 installation it asks for restart. If the user clicks OK or cancel(.NET) with some delay, next installation doesn't happen. My questions are
1. Can I suppress this message so that I can do my custom installation work properly
2. If I cannot suppress the message, can I wait for the user to clik OK or cancel to start another installation

Please give me some suggestions.
Thanks and regards
Sanandan




Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Sanandan

Hi Christopher,

I got the answer. I used noui parameter in commandline for wceload. I think it will work only if we have signed cabs. Thank you so much for your help.

Thanks and regards
Sanandan




Re: .NET Compact Framework alternative for System.Diagnostics.Process in .net CF 1.0

Sanandan

Hi Christopher,
I am using noui parameter in commandline with wceload to install the cab file on the handheld device(to suppress any prompts from the system). As I understand it will work if my CAB file is signed. I know there are two kinds of signing. Normal and M2M priviledged signing. Is it enough for me to have normal certificate or shall I go for priviledged certificate for noui parameter to work
I hope you can give me some idea.

Thanks and regards
Sanandan