By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,130 Members | 2,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,130 IT Pros & Developers. It's quick & easy.

Any reason to favor calling a batch file VS running a CMD directly in A97 VBA?

P: n/a
MLH
I have a batch file named GetConf.bat.
It contains a line like this:

ipconfig /all >c:\MyAppDir\IPdata.txt

I believe I could run the line with something
like ShellWait by Terry Kreft. Any reason I
should run the procedure via a batch file
call as opposed to launching the command
string directly?
Dec 13 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
No reason that I can think of.

What are you trying to accomplish, by the way? It may be that you can
retrieve whatever you want without having to resort to those contortions.
Take a look at what Randy Birch has at
http://vbnet.mvps.org/code/network/index.html

(ObWarning: Randy's site is aimed at VB programmers, not Access programmers.
There are significant differences between the controls available on forms in
VB vs. those available on forms in Access. Consequently, not all of the
GUI-related code on Randy's site will port into Access)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"MLH" <CR**@NorthState.net> wrote in message
news:9c********************************@4ax.com...
I have a batch file named GetConf.bat.
It contains a line like this:

ipconfig /all >c:\MyAppDir\IPdata.txt

I believe I could run the line with something
like ShellWait by Terry Kreft. Any reason I
should run the procedure via a batch file
call as opposed to launching the command
string directly?

Dec 13 '05 #2

P: n/a
MLH
Thanks, Doug. Regarding the Randy Birch site, I thought you might
have been referring to the section on using INI files??? I found
nothing there though. Which part exactly were you talking about?

BTW, I seem to have run into a snag with ShellWait...
Call ShellWait("ipconfig /all >c:\IPdata.txt") DID NOT WORK!!!
ShellWait ("ipconfig /all >c:\IPdata.txt") DID NOT WORK!!!
#AND#
Call ShellWait("c:\Program Files\TPSCG\GetConf.bat") WORKED!
ShellWait ("c:\Program Files\TPSCG\GetConf.bat") WORKED!

I don't understand. The batch file GetConf.bat contains the same CMD
string ipconfig /all >c:\IPdata.txt but I've tested and the
file "IPdata.txt" is not being created using the syntax in the first
two cases.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

On Tue, 13 Dec 2005 10:14:19 -0500, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
No reason that I can think of.

What are you trying to accomplish, by the way? It may be that you can
retrieve whatever you want without having to resort to those contortions.
Take a look at what Randy Birch has at
http://vbnet.mvps.org/code/network/index.html

(ObWarning: Randy's site is aimed at VB programmers, not Access programmers.
There are significant differences between the controls available on forms in
VB vs. those available on forms in Access. Consequently, not all of the
GUI-related code on Randy's site will port into Access)


Dec 13 '05 #3

P: n/a
In some conditions, I prefer to use a batch file.

Like starting a database with a workgroup and switches using the "start"
command. Benefit? You don't need to know the full path of msaccess.exe on
each workstation on a network. application.followhyperlink is an
alternative I use to open PDF files.

"MLH" <CR**@NorthState.net> wrote in message
news:9c********************************@4ax.com...
I have a batch file named GetConf.bat.
It contains a line like this:

ipconfig /all >c:\MyAppDir\IPdata.txt

I believe I could run the line with something
like ShellWait by Terry Kreft. Any reason I
should run the procedure via a batch file
call as opposed to launching the command
string directly?

Dec 13 '05 #4

P: n/a
MLH
Good points.
Dec 13 '05 #5

P: n/a
Two possible reasons why
1) The environment (particularly the PATH) may be different in the cmd
shell as opposed to the windows shell
2) As ipconfig is a dos program it may just not like being run in this
way.

You could have tried
Call ShellWait(environ$("comspec") & " /C ipconfig /all >c:\IPdata.txt")

--
Terry Kreft

"MLH" <CR**@NorthState.net> wrote in message
news:19********************************@4ax.com...
Thanks, Doug. Regarding the Randy Birch site, I thought you might
have been referring to the section on using INI files??? I found
nothing there though. Which part exactly were you talking about?

BTW, I seem to have run into a snag with ShellWait...
Call ShellWait("ipconfig /all >c:\IPdata.txt") DID NOT WORK!!!
ShellWait ("ipconfig /all >c:\IPdata.txt") DID NOT WORK!!!
#AND#
Call ShellWait("c:\Program Files\TPSCG\GetConf.bat") WORKED!
ShellWait ("c:\Program Files\TPSCG\GetConf.bat") WORKED!

I don't understand. The batch file GetConf.bat contains the same CMD
string ipconfig /all >c:\IPdata.txt but I've tested and the
file "IPdata.txt" is not being created using the syntax in the first
two cases.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

On Tue, 13 Dec 2005 10:14:19 -0500, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
No reason that I can think of.

What are you trying to accomplish, by the way? It may be that you can
retrieve whatever you want without having to resort to those contortions.
Take a look at what Randy Birch has at
http://vbnet.mvps.org/code/network/index.html

(ObWarning: Randy's site is aimed at VB programmers, not Access
programmers.
There are significant differences between the controls available on forms
in
VB vs. those available on forms in Access. Consequently, not all of the
GUI-related code on Randy's site will port into Access)

Dec 13 '05 #6

P: n/a
MLH
On Tue, 13 Dec 2005 16:25:18 -0000, "Terry Kreft"
<te*********@mps.co.uk> wrote:
Two possible reasons why
1) The environment (particularly the PATH) may be different in the cmd
shell as opposed to the windows shell Thx Terry. I checked the path this way: Click Start, Run, "CMD" and
typed Path. C:\WINDOWS\System32\ was in the path and IPconfig.exe
is there.
2) As ipconfig is a dos program it may just not like being run in this
way. You're probably right with this one.

You could have tried
Call ShellWait(environ$("comspec") & " /C ipconfig /all >c:\IPdata.txt")

I would like to explore this, but am unsure what's meant by environ$
and comspec.

Dec 13 '05 #7

P: n/a
MLH
Its also worth mentioning the following...

Shell("ipconfig /all >c:\IPdata.sys") does not work from VBA
Click Start, Run then ipconfig /all >c:\IPdata.sys doesn't either
Nor does Start, Run c:\windows\system32\ipconfig /all >c:\IPdata.sys

Now the batch file, on the other hand, seems to have no problems...
Shell("c:\Program Files\TPSCG\GetConf.bat") works
Click Start, Run then c:\Program Files\TPSCG\GetConf.bat works
And of course Call ShellWait("c:\Program Files\TPSCG\GetConf.bat")
works too (obviously)

All produce the desired file...

Directory of C:\
12/13/2005 11:52 AM 877 IPdata.sys
1 File(s) 877 bytes
0 Dir(s) 9,338,142,720 bytes free
Dec 13 '05 #8

P: n/a
Environ$ is a VBA function which returns the values of environment strings.

So
Environ$("Path")

returns the Path environment string

Comspec is the environment string which holds the path to your command line
interpreter, so on my current machine
Environ$("comspec")

returns
C:\WINDOWS\system32\cmd.exe

The /C is a switch to cmd.exe to say run the command and then close.

Therefore on my machine
environ$("comspec") & " /C ipconfig /all >c:\IPdata.txt"

translates as
C:\WINDOWS\system32\cmd.exe /C ipconfig /all >c:\IPdata.txt
--
Terry Kreft

"MLH" <CR**@NorthState.net> wrote in message
news:hb********************************@4ax.com...
On Tue, 13 Dec 2005 16:25:18 -0000, "Terry Kreft"
<te*********@mps.co.uk> wrote:
Two possible reasons why
1) The environment(particularly the PATH) may be different in the cmd
shell as opposed to the windows shell

Thx Terry. I checked the path this way: Click Start, Run, "CMD" and
typed Path. C:\WINDOWS\System32\ was in the path and IPconfig.exe
is there.
2) As ipconfig is a dos program it may just not like being run in this
way.

You're probably right with this one.

You could have tried
Call ShellWait(environ$("comspec") & " /C ipconfig /all
>c:\IPdata.txt")

I would like to explore this, but am unsure what's meant by environ$
and comspec.

Dec 13 '05 #9

P: n/a
The page I sent you to doesn't have anything about INI files.

It has a number of different code snippets to get you information about IP
addresses, MAC addresses, DNS and DHCP servers and the like. Since that's
typically the type of information I'm looking for when I run ipconfig /all,
I thought you might be able to get the information you were looking for
directly.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"MLH" <CR**@NorthState.net> wrote in message
news:19********************************@4ax.com...
Thanks, Doug. Regarding the Randy Birch site, I thought you might
have been referring to the section on using INI files??? I found
nothing there though. Which part exactly were you talking about?

BTW, I seem to have run into a snag with ShellWait...
Call ShellWait("ipconfig /all >c:\IPdata.txt") DID NOT WORK!!!
ShellWait ("ipconfig /all >c:\IPdata.txt") DID NOT WORK!!!
#AND#
Call ShellWait("c:\Program Files\TPSCG\GetConf.bat") WORKED!
ShellWait ("c:\Program Files\TPSCG\GetConf.bat") WORKED!

I don't understand. The batch file GetConf.bat contains the same CMD
string ipconfig /all >c:\IPdata.txt but I've tested and the
file "IPdata.txt" is not being created using the syntax in the first
two cases.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

On Tue, 13 Dec 2005 10:14:19 -0500, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
No reason that I can think of.

What are you trying to accomplish, by the way? It may be that you can
retrieve whatever you want without having to resort to those contortions.
Take a look at what Randy Birch has at
http://vbnet.mvps.org/code/network/index.html

(ObWarning: Randy's site is aimed at VB programmers, not Access
programmers.
There are significant differences between the controls available on forms
in
VB vs. those available on forms in Access. Consequently, not all of the
GUI-related code on Randy's site will port into Access)

Dec 13 '05 #10

P: n/a
MLH <CR**@NorthState.net> wrote in
news:9c********************************@4ax.com:
I have a batch file named GetConf.bat.
It contains a line like this:

ipconfig /all >c:\MyAppDir\IPdata.txt

I believe I could run the line with something
like ShellWait by Terry Kreft. Any reason I
should run the procedure via a batch file
call as opposed to launching the command
string directly?


I only write a batch file for this kind of thing when the SHELL
commands need to be executed in order. An example of this was where
I was concatenating two files with COPY and then renaming them. I
found it easier to do it all in DOS with a single batch file than to
do multiple SHELLANDWAIT statements in VBA.

I also sometimes write the batch file in code and then call it in
cases where it gets too complicated to pass arguments to the batch
file.

Basically, I think it's better to minimize the number of your SHELL
commands, but that's really only a personal preference. Using even 1
exposes you to the possibility of failure of outside processes, so
there's no difference in kind, just a difference in quantity.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 13 '05 #11

P: n/a
"Saintor" <sa******@REMOVETHIShotmail.com> wrote in
news:2f********************@weber.videotron.net:
Like starting a database with a workgroup and switches using the
"start" command. Benefit? You don't need to know the full path
of msaccess.exe on each workstation on a network.
application.followhyperlink is an alternative I use to open PDF
files.


The START command doesn't always work on all machines. I have never
been able tofigure out why, though. The Access Web has ShellExecute
API code that would be equivalent and could be run from Access.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 13 '05 #12

P: n/a
MLH
YES!
It worked like a charm. Many, many thx.
Dec 14 '05 #13

P: n/a
MLH
You're absolutely right. When I first hit the page,
I clicked some of the links at the top, rather than
scrolling downward. Thank-you. The information
on that page is quite helpful. I even found some
VB code for sync'ing with time servers I found
interesting.
Dec 14 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.