Click here to Skip to main content
13,052,956 members (62,152 online)
Rate this:
Please Sign up or sign in to vote.
Hi All,

desperately need help here...
I have a batch file that calls vbs boxes for user input (or response, yes no mainly) the user input goes to text file that is read into the bat variable used to execute in the opperation (command variables)
so i thought... get visual c++ 2k10 express and make a form with all the fields for usre input to create all the variables in one go and a couple of radio butttons to choose which batch file to run the variables in and job done right.. :) but no, now i have a pretty form with all the bits that save the user input to my private int variables but then discovered express doesn't seem to support running them in a command... ok, visual studio 2k10 ultimate trial (got 30 days to sort this out lol) so no prob i'll google running a command with variables from a form using user input and copy paste the code right??? errrrm is this such a difficult question? seems straight forward to me, but search as I may... no simple example or easy to follow course/video anywher to be found... oh-crap... yep I'm a network administrator not a programmer, the odd script or bat no prob but with all the will in the world (and a 30 day trial) i don't think i can get what I'm lookin' for... so any help greatly appreciated here :)
form1 contains:
text box for user input, which is folder location (\\server\share\or\path)
user types \\\c%\temp
which goes to my defined variable (int) %source%

button::do it now

easy, now run:
net use z: %source%

just a simple example of this would help me greatly :)

obviously the batch contains more than this (and works fine)... but messy with 4 vbs scrips and a batch file to hold it all together with some input needed back at the command prompt couse i don't even know how to get that into a message box lol so jumping to a single forms solution may be one small step for you guys but one giant leap for me.... :)

please please pretty please anyone think they can guide the blind then I'm your man :D

thanks in advance (hopefully)

cheers and TakeItEasy
Posted 17-Apr-12 18:10pm
SAKryukov 18-Apr-12 0:39am
What do you mean "Forms" in C++? The tag "Forms" is reserved for .NET UI based on System.Windows.Forms. If this is the case, this must be C++/CLI, not C++.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Unfortunately, this question is hard to understand. So, sorry if I'm answering a wrong question; please don't blame me too much for that.

It seems to me that your problem is running a child process from your application, such as you would do by the command line like net use z: %source%, where %source% is some parameter. I also think that you are talking about .NET application — please see my comment to the question.

If this is the problem, the solution is this: you need to use the class System.Diagnostics::Process::Start, please see:[^],[^].

If you have a batch file with a parameter (should be represented as %1 in the code of a batch file), the first parameter of Process::Start should be a name of the batch file, and second parameter — the parameter(s) of the batch file.

Also, you may need to redirect the output of the child process to a stream to use the output in your host program. For this purpose, you need to use the properties StandardOutput and StandardError (just in case there are errors :-)). You can find a code sample for redirection here:[^].

GazManian65 20-Apr-12 18:34pm
Thanks SAKryukov,
you understood fine, System.Diagnostics::Process::Start was indeed what I was looking for and smaples on how to use it, the links you provided should point me in the right direction :) %source% is a variable taken from user input by the way.. in its simplest form one text box for user input for location of source data (\\\c$\temp) stored in the %source% variable and on button click net use X: \\\c$\temp ... thanks again hope i can figure it out from here :)
SAKryukov 20-Apr-12 19:14pm
OK, good. This approach will do the trick. What is important, you are going to run some legitimate console-oriented application or a batch and can redirect the output and parse the output text if you need it (not those crazy doing-who-knows-what UI application which people often ask about). I also hope the application is based on command line, not interactive. Even if it was interactive, you would need to re-direct the input, which is also possible, just a bit more complex. So, it all should work for you.

You are welcome.
Good luck, call again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 18 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100