version of exe on device

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I find out the version of an executable on the device,
from the desktop?

I have tried using the OpenNETcf.Reflection assembly, but I don't know
how to target a particular exe (path).

Any ideas would be helpful.

Thank you.
 
I did something similar before. The solution i came up with was to
read the device's registry for the InstallDir of my application, then
I copied the assembly on the device to the desktop then checked for
the Version of the assembly.

You can use the remote api (RAPI) for reading the devices registry and
manipulating files on the device.

I can post some sample code if you wish.

Regards,
Christian Resma Helle
http://christian-helle.blogspot.com
 
Here's sample of how to copy an assembly from the device to the
desktop and get its version.


[C# CODE]

[DllImport("rapi.dll")]
static extern int CeRapiInit();

[DllImport("rapi.dll")]
static extern int CeRapiUninit();

[DllImport("rapi.dll")]
static extern int CeCloseHandle(IntPtr hObject);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
static extern IntPtr CeCreateFile(
string lpFileName,
uint dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
static extern int CeReadFile(
IntPtr hFile,
byte[] lpBuffer,
int nNumberOfbytesToRead,
ref int lpNumberOfbytesRead,
int lpOverlapped);

const int ERROR_SUCCESS = 0;
const uint GENERIC_READ = 0x80000000;
const short OPEN_EXISTING = 3;
const short INVALID_HANDLE_VALUE = -1;
const short FILE_ATTRIBUTE_NORMAL = 0x80;

public static Version GetAssemblyVersionFromDevice(string
remote_file, string local_file)
{
bool rapi = CeRapiInit() == ERROR_SUCCESS;
if (!rapi) {
return null;
}

IntPtr remote_file_ptr = CeCreateFile(
remote_file,
GENERIC_READ,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);

if (remote_file_ptr.ToInt32() == INVALID_HANDLE_VALUE) {
return null;
}

FileStream local_file_stream = new FileStream(
local_file,
FileMode.Create,
FileAccess.Write);

int read = 0;
int size = 1024 * 4;
byte[] data = new byte[size];

CeReadFile(remote_file_ptr, data, size, ref read, 0);

while (read > 0) {
local_file_stream.Write(data, 0, read);
if (CeReadFile(remote_file_ptr, data, size, ref read, 0) == 0)
{
CeCloseHandle(remote_file_ptr);
local_file_stream.Close();
return null;
}
}

CeCloseHandle(remote_file_ptr);
local_file_stream.Flush();
local_file_stream.Close();

if (!File.Exists(local_file)) {
return null;
}

if (rapi) {
CeRapiUninit();
}

Version version =
Assembly.LoadFrom(local_file).GetName().Version;

return version;
}


Regards,
Christian Resma Helle
http://christian-helle.blogspot.com
 
Christian,

Thanks for your response. That's a great idea. I would love to see your
sample code on this.

Truly
 
This is an example how to use the code I posted previously:

Version ver = CeFile.CopyFromDevice(
"\\Program Files\\MyApp\\MyApp.exe",
string.Format("{0}\\MyApp.exe", Environment.CurrentDirectory));

MessageBox.Show(ver.ToString());

Regards,
Christian Resma Helle
http://christian-helle.blogspot.com
 
Back
Top