?
Solved

Command prompt output in Win CE

Posted on 2014-03-21
4
Medium Priority
?
563 Views
Last Modified: 2014-03-24
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()
        p.WaitForExit()

        pInfo = Nothing
        p.Dispose()

    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
0
Comment
Question by:pdi656
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:hjgode
ID: 39946987
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
0
 
LVL 1

Author Comment

by:pdi656
ID: 39950707
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.
0
 
LVL 16

Accepted Solution

by:
hjgode earned 2000 total points
ID: 39951168
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.
0
 
LVL 1

Author Closing Comment

by:pdi656
ID: 39951230
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!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question