Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,164 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,898 people online right now. Registration is fast and FREE... Join Now!




processstartinfo arguments

 
Reply to this topicStart new topic

processstartinfo arguments

corliss
9 Dec, 2007 - 09:51 AM
Post #1

D.I.C Head
Group Icon

Joined: 25 Oct, 2006
Posts: 119



Thanked: 1 times
Dream Kudos: 50
My Contributions
Hey all,
I made a c# application that starts an another applction using the processstartinfo.
Everything seemed to be 5/5 until I started using arguments.
CODE

//How to Wait for a Shelled Process to Finish
            //Get the path to the system folder.
            string sysFolder =
            Environment.GetFolderPath(Environment.SpecialFolder.System);
            //Create a new process info structure.
            ProcessStartInfo pInfo = new ProcessStartInfo();
            //Set the file name member of the process info structure.
            pInfo.FileName = "msaccess";
            pInfo.Arguments = @"C:\Wolf Lair\WorkDeskTemp\"+username+@"\WolfDeskApp2k3.mdb"+runtime+macros;
            //Start the process.
            Process p = Process.Start(pInfo);
            //Wait for the window to finish loading.
            p.WaitForInputIdle();
            //Wait for the process to end.
            p.WaitForExit();


The problem is that when I use the pInfo.Arguments it provides the arguments in a strange string.
The argument works when I type it into a cmd prompt.
The argument is:
"c:\Wolf Lair\WorkDeskTemp\Corliss\WolfDeskApp2k3.mdb" /runtime /X _AutoExec
This argument assumes that the users name is corliss....which is used just for examples purpose.

In C# the argument is passed as invalid when I run it. I think it is because it is passed with quotes around the whole argument.
Any help is greatly needed.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Processstartinfo Arguments
9 Dec, 2007 - 05:47 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,199



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
It is the fact that you have a space in the file path. Use double quotes inside the quotes to force it to be evaluated...

Example

CODE

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "msaccess";
// Notice the doubling of double quotes inside the quotes (leading to three sets of double quotes)
startInfo.Arguments = @"""C:\Documents and Settings\db1.mdb""";

Process.Start(startInfo);


This should help clear up your situation. Make sure you are evaluating to a legit path as well.

Enjoy!

"At DIC we be process starting space encountering code ninjas!" decap.gif
User is online!Profile CardPM
+Quote Post

corliss
RE: Processstartinfo Arguments
9 Dec, 2007 - 06:50 PM
Post #3

D.I.C Head
Group Icon

Joined: 25 Oct, 2006
Posts: 119



Thanked: 1 times
Dream Kudos: 50
My Contributions
QUOTE

"At DIC we be process starting space encountering code ninjas!" decap.gif

NOYCE!!!!!!!!!!!!
Thanks Martyr Always a help......p.s. I guess I sould try it first
User is offlineProfile CardPM
+Quote Post

corliss
RE: Processstartinfo Arguments
28 Dec, 2007 - 10:05 AM
Post #4

D.I.C Head
Group Icon

Joined: 25 Oct, 2006
Posts: 119



Thanked: 1 times
Dream Kudos: 50
My Contributions
Here is the finished app.
CODE

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Text;
/*Created By: Shawn Corliss
* On: Dec 4, 2007
* For: Clinicvault.Inc
* This application will gather variables for the purpose of
* launching the Wolfdesk.exe with commang args.
* This application will then remain open until the Wolfdesk
* closes.
* Clinicvault needs to do this because we need to restrict the number
* of instances of Wolfdesk that a single user can open at one time.
*/

namespace wolf
{
    class collect
    {
        static void Main(string[] args)
        {
            /*variable declerations*/
            String username,workingfolder = "";
            string sourcepath = "C:\\wolf Lair\\Programs\\";
            string[] files = new string[]             {"WolfDeskApp2k3.mdb", "wolfHelpFile.hlp",
                "System.mdw"};

            
            
            /*find the current username*/
            username = Environment.UserName.ToString();

            /*find the needed directory*/
            workingfolder = "C:\\Wolf Lair\\WorkDeskTemp\\" + username+"\\";
            DirectoryInfo personalpath = new DirectoryInfo(workingfolder);

            /*verification that the file is found*/
            if (!personalpath.Exists)
                personalpath.Create();

            /*Control loop to check to see if the files are in the working folder*/
            /*the files can also be overwirtten if there is an error*/
            for (int i = 0; i < 3; i++)
            {
                //if (!File.Exists(workingfolder + files[i]))
                //{

                    File.Copy(sourcepath + files[i],workingfolder+files[i], true);
               // }
            }
            //How to Wait for a Shelled Process to Finish
            //Get the path to the system folder.
            string sysFolder =
            Environment.GetFolderPath(Environment.SpecialFolder.System);
            //Create a new process info structure.
            ProcessStartInfo pInfo = new ProcessStartInfo();
            //Set the file name member of the process info structure.
            pInfo.FileName = "msaccess";
            pInfo.Arguments = @"""C:\Wolf Lair\WorkDeskTemp\" + username + @"\WolfDeskApp2k3.mdb"" /runtime /x _AutoExec";
            //Start the process.
            Process p = Process.Start(pInfo);
            //Wait for the window to finish loading.
            p.WaitForInputIdle();
            //Wait for the process to end.
            p.WaitForExit();

        }
      
    }
    
}


The problem is that I need the console window to close. I tryed pinfo.createnowindow to false and it dosnt show the results of the command...like opening the app that I want to open with the command. I also attempted useshellexecute to false and that did not acheive the results that I want.
Realistically I would like to know how to make the parent invisable while have the child useable when the parent and child are completly differnt like say an actual app and a command line.

This post has been edited by corliss: 28 Dec, 2007 - 12:24 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:01AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month