3

Hoping this question will get answered. Basically I am attempting to open an executable file from within an application I have created which runs on windows ce5 on a unitech barcode scanner using the .net compact framework 3.5. I have included a snippet of code where I attempt this.

Each time I debug the app via VS2008 I am getting a Win32Exception but with no further details (with or without the try catch statement). It does not tell me what the exception is nor does it provide an error code.

Here is the code I am using to try to start the process. Can you see anything wrong with it that may be causing an error? I have double and triple checked the filename and also the directory where it is stored so it is not that.

private void CustomButtonEvent(object sender, EventArgs e)
{
    string buttonName = ((Control)sender).Name;
    ProcessStartInfo processStartInfo = new ProcessStartInfo();

    buttonName = buttonName.Remove(0, 3);
    buttonName = buttonName.Replace(' ', '_');

    switch (buttonName)
    {//todo need to open the different exe's here
        case "End_Of_Line":
            {
                MessageBox.Show(@"No app behind this button yet.");
                break;
            }
        case "Asset_Tracking":
            {
                processStartInfo.FileName = "AssetTrackingScanner.exe";
                processStartInfo.WorkingDirectory = @"\Flash Storage\CompoundingManagementScannerSuite\Applications\AssetTrackingScanner\AssetTrackingScanner\bin\Debug";

                try
                {
                    Process.Start(processStartInfo);
                }
                catch (Exception f)
                {
                    MessageBox.Show(f.ToString());
                }

                break;
            }
        case "Stock Take":
            {

                MessageBox.Show(@"No app behind this button yet.");
                break;
            }
        case "Despatch":
            {
                MessageBox.Show(@"No app behind this button yet.");
                break;
            }
    }
}
VMAtm
  • 27,943
  • 17
  • 79
  • 125
CSharpened
  • 11,674
  • 14
  • 52
  • 86
  • Why don't you use the drive letter during working directory set? – VMAtm Sep 05 '11 at 12:05
  • The drive does not have a letter. All the directories have names rather than letters. Just to double check this I ran a command prompt and entered cd A: all the way up to cd P: and it never found any of the directories however if I enter cd FlashStorage it finds it no problems. – CSharpened Sep 05 '11 at 12:17
  • Is your program on the same disk with the `AssetTrackingScanner.exe`? – VMAtm Sep 05 '11 at 12:21
  • Well at the moment I am deploying the application via VS2008 and then when I click on the menu option which should run the next application I am getting the error. I will try copying the executable across to the same disk and then see if the error still occurs. I hadnt thought that it may be because I am debugging rather than running the executable directly. I will report back if this makes any difference. Thanks – CSharpened Sep 05 '11 at 12:31
  • I copied all the relevant files across to the flash storage but unfortunately the error still occurs. It is as follows: System.ComponentModel.Win32Exception:Win32Exception at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo processStartInfo) etc – CSharpened Sep 05 '11 at 13:03
  • I should add I have also tried simply loading internet explorer too and this does not work either. – CSharpened Sep 05 '11 at 13:30

1 Answers1

6

I see two problems. First, CE requires fully qualified paths, so the processStartInfo.FileName should be something like this

processStartInfo.FileName = 
@"\Flash Storage\CompoundingManagementScannerSuite\Applications\AssetTrackingScanner\AssetTrackingScanner\AssetTrackingScanner.exe"; 

Second, CE has no concept of a WorkingDirectory, so remove the call to set it.

I'm also a little concerned about the \bin\debug\ part of your path. Studio doesn't deploy to a bin\debug\ folder on the device. It build to one on the PC, but on the target device the only way it would be there is if you manually set it. This leads me to think you need to check your on-device applicatin path.

ctacke
  • 66,480
  • 18
  • 94
  • 155