Monday, September 26, 2005

CF : Installing a cab file programmatically and quietly (no user interaction)

The trick is using wceload.exe with the /no­askdest and /noui parameters.

Again thanks to opennetcf.org.

private bool installCabFile ()
{
try
{
ProcessInfo pi = new ProcessInfo();
if (CreateProcess ("\\Windows\\wceload.exe","/no­askdest /noui " + downloadFileName, pi))
return false;
}

catch (Exception e)
{
Cursor.Current = Cursors.Default;
MessageBox.Show ("Problem installing Cab file " + e.ToString());
return true;
}

return false;
}

// CreateProcess PInvoke API
[DllImport("CoreDll.DLL", SetLastError=true)]
private extern static int CreateProcess ( String imageName, String cmdLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, Int32 boolInheritHandles, Int32 dwCreationFlags, IntPtr lpEnvironment, IntPtr lpszCurrentDir, byte [] si, ProcessInfo pi );

// GetLastError PInvoke API
[DllImport("CoreDll.dll")]
private extern static Int32
GetLastError();

public Int32 GetPInvokeError()
{
return GetLastError();
}

[DllImport("CoreDll.dll")]
private extern static Int32
WaitForSingleObject ( IntPtr Handle, Int32 Wait);

public bool CreateProcess (String ExeName, String CmdLine, ProcessInfo pi)
{
Int32 INFINITE;
unchecked {INFINITE = (int)0xFFFFFFFF;}
bool result = false;
if (pi == null) pi = new ProcessInfo ();
byte [] si = new byte [128];
result = CreateProcess (ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi) != 0;
WaitForSingleObject (pi.hProcess,INFINITE);
return result;
}

public sealed class ProcessInfo
{
public IntPtr hProcess = IntPtr.Zero;
public IntPtr hThread = IntPtr.Zero; public int dwProcessID = 0;
public int dwThreadID = 0;
}

Enjoy!

(Compact Framework)

2 comments:

alex said...

I'ts possible to install unsigned cabs in silent mode over WM5 and WM6 with the utility made by cssoft. You can download the demo version from http://cssoft.freehosting.net/website2/default.html

i'll hope it helps.

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!