Re: Batch file and MFC
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 13 Jan 2007 22:16:44 -0500
Since batch files don't do graphics, I agree with Scot. Why bother?
ShellExecute will look up the .bat file name and launch a process that will execute the
script. Overall, I find the batch file approach to be rather primitive, a real throwback
to unix programming (which was pretty much stuck in the Dark Ages), but sometimes you need
to allow the end user to modify the commands, and then it is almost reasonable.
Good software engineering says that you don't use .bat files to do things that don't need
to be changed post-deployment and for which there are already good APIs. The reason is
that you never get sufficient information back from a batch file if there is a failure,
whereas if you are writing code you have complete control, including abilities to write
smart recovery code, ask the user to make a decision, inform the user of the ACTUAL,
PRECISE cause of the error, etc. Again, if you have to allow the end user to modify the
script, then the deferred binding of a batch file is actually useful, but I find that too
many ex-unix programmers think of batch jobs as substitutes for writing good code in the
first place (it doesn't help that Unix has one of the worst sets of primitive APIs in the
known universe for doing anything worthwhile--I know, I worked in in for 15 years, and
despised it for all of that time. Trivial things like programmed wildcard expansion were
nightmares. Copying a group of files and subdirectories was ghastly. Actually, anything
seriously related to doing interesting system programming largely did not exist, and the
substitute was "write a batch job, capture the output, and use that". It sucked).
Unless you are running with admin privileges, it is safe to assume that you will not be
able to cause a restart of the system. Also, it is seriously questionable why you
*should* initiate a restart. There are very few valid reasons to restart a computer these
days. With some of the modern capabilities such as side-by-side installation
configurations, nearly all the historical reasons for requiring a restart have gone away.
So one of the important questions to ask is "is this really necessary". Requiring
restarts is now considered poor programming practice, something to be avoided unless
absollutely positively utterly unavoidable, and part of your job is to make sure a restart
is avoidable.
Microsoft is tightening up the ability to cause restarts because various malware can use
this for denial-of-service attacks, so it is actually getting harder and harder to cause a
restart, while at the same time the capabilities they are providing programmers make it
less and less necessary to do so for traditional reasons.
Sometimes it is nice to see output as if you had a console window; I've found a listbox to
be a Really Great Tool for this. See my "Logging ListBox Control" essay on my MVP Tips
site. Feel free to download and adapt.
Also, you may want to read other essays on my site, especially the "dialog box" series.
joe
On Sat, 13 Jan 2007 20:16:03 -0600, "Scot T Brennecke" <ScotB@xxxxxxxxxxxxxxxxxx> wrote:
I don't see any problem with making a GUI equivalent of a batch file. If it works reliably, then IJoseph M. Newcomer [MVP]
wouldn't advise you against doing it. However, if there's no user interface, I don't quite
understand your motivation for doing this.
To deal with the shutdown, look at using one of the following API functions: ExitWindowsEx,
InitiateSystemShutdown, or InitiateSystemShutdownEx.
"one-trick-pony" <worldofpain.aamir@xxxxxxxxx> wrote in message
news:1168525322.175177.162900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Greetings,
I am a new programmer of MS VC++. I would like to convert a batch file
into an MFC dialog based Visual C++ executable program which will
execute in Windows. My first question is, is this a valid approach? If
so, what is best approach in setting up this program that will
automatically execute large number of commands (because thats what
really batch files is, executing commands in succession)? Currently,
the set up I have is upon executing OnInitDlg function(which is
executed automatically upon application execution), I call up another
function to continue to execute commands in succession. There is no
user intervention or input involved for this particular batch file. If
there is an error, either batch file stops executing and/or jumps to
another instruction. Is this a valid approach or good software
engineering practice to have MFC based application mimic a batch file?
I have coded part of it, compiled and executed and it runs faster and
with wonderful GUI instead of console window.
Also, at the end, the batch file restarts computer. I would like to
exit my MFC program before that step and let the computer continue to
shut down. I am not familiar with how to set that up. I am looking for
comments/suggestions/guidance that would help me improve my program and
help me become a better programmer. I am open to any software
engineering ideas. Thanks for your help.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Batch file and MFC
- From: one-trick-pony
- Re: Batch file and MFC
- From: Scot T Brennecke
- Batch file and MFC
- Prev by Date: Re: GetGlyphOutline API
- Next by Date: Re: calling constructor from CString
- Previous by thread: Re: Batch file and MFC
- Next by thread: Re: Batch file and MFC
- Index(es):
Relevant Pages
|