• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

Command prompt output in Win CE

I'm working on a VB.NET program for a Windows CE device. In part of the program I want to open a console program, pass it an argument and read the output. The below code works perfectly in a standard Windows Form program, but will not work in the Windows CE environment.

    Public Function GET_PW_CS(ByVal stIN As String) As String

        'INPUTS: stIN = the argument (passkey) for the  string desired
        'OUTPUTS: The string from the console program

        'Set up the Process
        Dim pInfo As New ProcessStartInfo()
        pInfo.FileName = "C:\MyConsoleProgram.exe"
        pInfo.Arguments = stIN
        pInfo.RedirectStandardOutput = True
        pInfo.UseShellExecute = False
        pInfo.CreateNoWindow = True

        'Calls the program and gets the output
        Dim p As Process = Process.Start(pInfo)
        GET_PW_CS = p.StandardOutput.ReadLine()

        pInfo = Nothing

    End Function

Open in new window

These lines aren't recognized as being valid in CE:

pInfo.RedirectStandardOutput = True
pInfo.CreateNoWindow = True
 GET_PW_CS = p.StandardOutput.ReadLine()

Any suggestions? Perhaps there is a completely different way to accomplish this?

Thanks in advance
  • 2
  • 2
1 Solution
As Windows CE has only very limitted resources the tools, runtimes and applications have been stripped down. So Compact Framework only and native C API supports only a subset of what is available in full framework and desktop windows.

Although Windows CE offers a command prompt, there is no API to redirect stdin, stderror and stdout back to compact framework.

You need to workaround this if you need to cpature the output of an console app. >ou can redirect output to a file and then in your code wait until the console process has terminated and then read the file.

See also: http://msdn.microsoft.com/en-us/library/aa453925.aspx
pdi656Author Commented:
I set up my console app to write the output to a file. I then tried calling the console app from my program, but it errors out when trying to run the console app. The console app is on our internal network, as is the text file. For some reason it doesn't like executing my command prompt from the network. When I copy the command prompt to the mobile device itself and call it from there I get a MissingMethodException error.

All I'm trying to accomplish is that I'm trying to dynamically get a database connection string for the software on the mobile device to use. We will be moving several database servers over the next few months. Because the connection strings are coded into the software, the only way for the devices to work properly is if I re-install the software on each device on the day of the server switch. My thinking is that if the program dynamically looks up the connection when the software starts, the servers can be moved anytime and all I have to do is change the connection string in one spot (the console program).

If there is another way to accomplish this, I'm open for it.
There are varous ways to 'update' software on Windows CE devices, but all of them require coding.

Idea 1) You have your connection string extern to the main app. For example in a file or in registry. Then have either an update application or update code in mail app that reads the setting from a server and updates the registry/the file.

Idea 2) Your main app implements a server (ie http or simple socket) that can be reached from outside the device. Then have a desktop app that accesses the server and changes setting.

Idea 3) you implement a separate server and make changes from desktop PC custom app. For example see my extended webserver at http://www.hjgode.de/wp/2012/10/19/windows-mobile-a-simple-web-server-with-extended-features/

Idea 4) Possibly your device already supports any config tool. For example config by barcodes or files sent to specific locations or has a ready to use ftp server.

Idea 5) You have many devices and already thought about remote management of these. Take a look at SOTI MobilControl or Wavelink.

Idea 6) You get every device at your hands and dock it to your PC. Then create automated task that updates every device via ActiveSync/WMDC. ActiveSync automation example at http://www.hjgode.de/wp/2010/02/26/pc-activesync-can-be-used-to-automate-tasks-on-device-connection/

Idea 7) Create a process that watches a dir and then takes config files like WAP provisioning ones and use DMProcessConfig to change device settings/registry.  Needs your app uses an external storage for custom connection string etc.


Can you tell which devices you are talking about? Some manufacturers provide free management tools.
pdi656Author Commented:
Great suggestions. Sounds like I should have hired you to set all of this up in the first place! I thought about storing it in the registry, but I wasn't sure how I'd be able to change it remotely. I didn't want it in a file as I was worried that someone would see it. Not that they couldn't get into the registry, but they are less likely to there.

These devices have barcode readers on them. I may simply send the updated data in the form of a barcode and have the user scan it into a utility in my program that will update the connection string in the registry - a combination of two of your suggestions. I'm still going to explore some of your other suggestions too. Thanks for the ideas!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now