473,809 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

ipconfig /all >c:\MyAppDir\IP data.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
13 5444
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**@NorthStat e.net> wrote in message
news:9c******** *************** *********@4ax.c om...
I have a batch file named GetConf.bat.
It contains a line like this:

ipconfig /all >c:\MyAppDir\IP data.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
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("ipco nfig /all >c:\IPdata.txt" ) DID NOT WORK!!!
ShellWait ("ipconfig /all >c:\IPdata.txt" ) DID NOT WORK!!!
#AND#
Call ShellWait("c:\P rogram Files\TPSCG\Get Conf.bat") WORKED!
ShellWait ("c:\Program Files\TPSCG\Get Conf.bat") WORKED!

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

On Tue, 13 Dec 2005 10:14:19 -0500, "Douglas J. Steele"
<NOSPAM_djsteel e@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
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.fol lowhyperlink is an
alternative I use to open PDF files.

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

ipconfig /all >c:\MyAppDir\IP data.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
MLH
Good points.
Dec 13 '05 #5
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(envir on$("comspec") & " /C ipconfig /all >c:\IPdata.txt" )

--
Terry Kreft

"MLH" <CR**@NorthStat e.net> wrote in message
news:19******** *************** *********@4ax.c om...
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("ipco nfig /all >c:\IPdata.txt" ) DID NOT WORK!!!
ShellWait ("ipconfig /all >c:\IPdata.txt" ) DID NOT WORK!!!
#AND#
Call ShellWait("c:\P rogram Files\TPSCG\Get Conf.bat") WORKED!
ShellWait ("c:\Program Files\TPSCG\Get Conf.bat") WORKED!

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

On Tue, 13 Dec 2005 10:14:19 -0500, "Douglas J. Steele"
<NOSPAM_djsteel e@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
MLH
On Tue, 13 Dec 2005 16:25:18 -0000, "Terry Kreft"
<te*********@mp s.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\Syst em32\ 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(envir on$("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
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.sy s doesn't either
Nor does Start, Run c:\windows\syst em32\ipconfig /all >c:\IPdata.sy s

Now the batch file, on the other hand, seems to have no problems...
Shell("c:\Progr am Files\TPSCG\Get Conf.bat") works
Click Start, Run then c:\Program Files\TPSCG\Get Conf.bat works
And of course Call ShellWait("c:\P rogram Files\TPSCG\Get Conf.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
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$("comsp ec")

returns
C:\WINDOWS\syst em32\cmd.exe

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

Therefore on my machine
environ$("comsp ec") & " /C ipconfig /all >c:\IPdata.tx t"

translates as
C:\WINDOWS\syst em32\cmd.exe /C ipconfig /all >c:\IPdata.tx t
--
Terry Kreft

"MLH" <CR**@NorthStat e.net> wrote in message
news:hb******** *************** *********@4ax.c om...
On Tue, 13 Dec 2005 16:25:18 -0000, "Terry Kreft"
<te*********@mp s.co.uk> wrote:
Two possible reasons why
1) The environment(par ticularly 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\Syst em32\ 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(envir on$("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
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**@NorthStat e.net> wrote in message
news:19******** *************** *********@4ax.c om...
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("ipco nfig /all >c:\IPdata.txt" ) DID NOT WORK!!!
ShellWait ("ipconfig /all >c:\IPdata.txt" ) DID NOT WORK!!!
#AND#
Call ShellWait("c:\P rogram Files\TPSCG\Get Conf.bat") WORKED!
ShellWait ("c:\Program Files\TPSCG\Get Conf.bat") WORKED!

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

On Tue, 13 Dec 2005 10:14:19 -0500, "Douglas J. Steele"
<NOSPAM_djsteel e@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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1869
by: Ries Spruit | last post by:
Hiya, I have a simple program which should be executed from the commandline by various other programs. The program returns an integer as the result. What is the easiest way to pick up this returnvalue? If I use 'return -1' etc. the value is might be returned but it is not visible when executing the program directly from the commandline. Console.WriteLine would work but I am curious wether it is possible to retrieve the
14
3560
by: Mark C. | last post by:
I'm trying to call a batch file that I've built using the FileSystemObject and CreateObject("Wscript.Shell"), oShell.Run... in an asp script. Naturally, I can get the script to work from a command line but not from a browser. The page does not throw an error but the oShell.Run... portion of the script doesn't run. Any help would be appreciated. Thanks.
1
5797
by: Bucky Pollard | last post by:
I have a web service that needs to create a batch file and call it (since there are no APIs for the functionality I am looking for). I am using the Process and ProcessStartInfo objects. When I try to call the batch file, it just returns with a return code of 1. When I call cmd.exe, and pass the batch file as a parameter it hangs. After much frustration and aggrevation, I found that CMD IS in fact running, but it is running under the context...
6
11240
by: Charles Neitzel | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe...
1
3208
by: Charles | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe...
3
7623
by: JoelBrimm | last post by:
I have a batch file that executes a command line utility to do a secure file copy from our server to a 3rd party server. The batch file works fine, but when I call it from the web service the log file shows that it hangs up on the execution of the utility ( an exe ). Batch files without an exe work fine. I also tried running the exe from the web service ( rc = shell(application,hide,true) ) but it didn't work either.
6
20417
by: eric.goforth | last post by:
Hello, I have a simple batch file that I'm trying to call from a VB.NET application: @ECHO OFF IF (%1)==() GOTO END DIR %1 > MYDIR.TXT :END @ECHO ON
4
2176
by: shantanu | last post by:
Hi all i am trying to imolement a code to run a batch file. But its throwing error "No application is associated with the specified file for this operation" The code which i am implementing is private void InstallDefectService()
4
3664
ck9663
by: ck9663 | last post by:
hi guys this is a little challenging, at least for me...here goes... i have to run a DOS batch file from a server. with some parameters that i need to pass. these parameters can be found on a sql-server table. which means i need to build the string that will be used to call the batch file (set @var = 'callbatch.bat ' + @var1 + ' ' + @var2). then call the batch file using the xp_cmdshell command. each batch file runs about 4-5 hours. i don't...
0
10639
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.