Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
3.00/5 (1 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 :)
i.e.
form1 contains:
text box for user input, which is folder location (\\server\share\or\path)
user types \\127.0.0.1\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
GazMan
Posted
Comments
Sergey Alexandrovich Kryukov 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++.
--SA

1 solution

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:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^],
http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx[^].

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:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[^].

—SA
 
Share this answer
 
Comments
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 (\\127.0.0.1\c$\temp) stored in the %source% variable and on button click net use X: \\127.0.0.1\c$\temp ... thanks again hope i can figure it out from here :)
Sergey Alexandrovich Kryukov 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.
--SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900