473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Shell function strange behaviour

I have come across a strange issue whilst trying to use a shell
command call from Access and have spent some time trying to figure
this out but can't find the cause as yet.

The issue is: I need to execute a command call from within Access to
execute a batch file (sample.bat). To do this, we use the Shell
function, something like:

Shell "cmd /c sample.bat"

sample.bat is located in C:\WINDOWS\system32 and this directory is set
in the PATH variable.

The issue is that when I attempt to execute the Shell call, I get the
following message:
'sample.bat' is not recognized as an internal or external command,
operable program or batch file.

My environment is Windows XP SP2 and Access 2003.

So I jump to my Start Run cmd to invoke command line, then execute
sample.bat and it works!

To further debug this issue, this is what I've done and found so far:
a) On Access, perform a Shell call that looks like: Shell "cmd /k".
This opens up a Command window.
b) I also open a Command window by going to Start Run cmd.

PATH
* On both (a) and (b) I verify that 'C:\WINDOWS\system32' is
definitely in the PATH, so sample.bat can be executed without
prefixing its location (yes, I anyways tried to prefix the location
but didn't help)
DIR
* On (b), I go to the directory C:\WINDOWS\system32 and then execute a
'dir sample.bat' and find the file
* On (a), I go to the directory C:\WINDOWS\system32 and then execute a
'dir sample.bat' and can't find the file!!!
CHANGE THE LOCATION OF sample.bat to C:\
* On (b), I set the PATH to C:\ and execute sample.bat and it works
* On (a), I set the PATH to C:\ and execute sample.bat and it
works!!!! Of course, I can now do a DIR and find the file

Even though I found a workaround to my issue, I am baffled as to why
the Command interpreter behaves differently when called from within
Access compared to when it's called from the Start Run option.

The workaround is less attractive if, for example, you need to run
some other commands (like CSVDE) that should actually be in the
directory C:\WINDOWS\system32 and it doesn't work (which is also
happening to me).

I log on as a local admin, I even opened up the permissions on the
root C:\WINDOWS to Everyone and have it propagated to all the
subfolders but I still get that on (a); I can't see sample.bat or
CSVDE.exe and, therefore, I can't execute the file.

Any clues would be highly appreciated!
Oct 2 '08 #1
3 6706
The dos shell and Start Run cmd use the path environment variable if the
executable's path isn't given. VBA's Shell function uses the current
directory if the executable's path isn't given. Sample.bat isn't in the
current directory. Type the full path to sample.bat to solve the problem.

Chris
Microsoft MVP
Max Vit wrote:
>I have come across a strange issue whilst trying to use a shell
command call from Access and have spent some time trying to figure
this out but can't find the cause as yet.

The issue is: I need to execute a command call from within Access to
execute a batch file (sample.bat). To do this, we use the Shell
function, something like:

Shell "cmd /c sample.bat"

sample.bat is located in C:\WINDOWS\system32 and this directory is set
in the PATH variable.

The issue is that when I attempt to execute the Shell call, I get the
following message:
'sample.bat' is not recognized as an internal or external command,
operable program or batch file.

My environment is Windows XP SP2 and Access 2003.

So I jump to my Start Run cmd to invoke command line, then execute
sample.bat and it works!

To further debug this issue, this is what I've done and found so far:
a) On Access, perform a Shell call that looks like: Shell "cmd /k".
This opens up a Command window.
b) I also open a Command window by going to Start Run cmd.

PATH
* On both (a) and (b) I verify that 'C:\WINDOWS\system32' is
definitely in the PATH, so sample.bat can be executed without
prefixing its location (yes, I anyways tried to prefix the location
but didn't help)
DIR
* On (b), I go to the directory C:\WINDOWS\system32 and then execute a
'dir sample.bat' and find the file
* On (a), I go to the directory C:\WINDOWS\system32 and then execute a
'dir sample.bat' and can't find the file!!!
CHANGE THE LOCATION OF sample.bat to C:\
* On (b), I set the PATH to C:\ and execute sample.bat and it works
* On (a), I set the PATH to C:\ and execute sample.bat and it
works!!!! Of course, I can now do a DIR and find the file

Even though I found a workaround to my issue, I am baffled as to why
the Command interpreter behaves differently when called from within
Access compared to when it's called from the Start Run option.

The workaround is less attractive if, for example, you need to run
some other commands (like CSVDE) that should actually be in the
directory C:\WINDOWS\system32 and it doesn't work (which is also
happening to me).

I log on as a local admin, I even opened up the permissions on the
root C:\WINDOWS to Everyone and have it propagated to all the
subfolders but I still get that on (a); I can't see sample.bat or
CSVDE.exe and, therefore, I can't execute the file.

Any clues would be highly appreciated!
--
Message posted via http://www.accessmonster.com

Oct 2 '08 #2
Hi Chris - This is what i have tried:

Shell "cmd /k c:\WINDOWS\System32\sample.bat"
-AND-
Shell "c:\WINDOWS\System32\cmd /k sample.bat"
-AND-
Shell "c:\WINDOWS\System32\cmd /k c:\WINDOWS\System32\sample.bat"

The result is still the same :-(

'c:\WINDOWS\System32\sample.bat' is not recognized as an internal or
external command, operable program or batch file.

I use the '/k' so the command windows is kept open; and on every
instance, doing a DIR on C:\WINDOWS\System32 for sample.bat brings no
results even though the file is there.
BTW, 'cmd.exe' it's on the same folder so I am really struggling to
understand what's going on.

Furthermore, the Start Run cmd will show this PATH:
PATH=C:\Program Files (x86)\PC Connectivity Solution\;C:\WINDOWS
\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\P rogram Files
(x86)\ATI Technologies\ATI.ACE\Core-Static;C:\WINDOWS\sysWOW64

And the Shell "cmd /k" will show a different PATH (as you correctly
suggested) but that still contains C:\WINDOWS\System32:
PATH=C:\Program Files (x86)\Microsoft Office\OFFICE11\;C:\Program
Files (x86)\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C:
\WINDOWS\System32\Wbem;C:\Program Files (x86)\ATI Technologies\ATI.ACE
\Core-Static;C:\WINDOWS\sysWOW64

I have even set the PATH temporarily to only look at C:\WINDOWS
\System32 but the result is the same.

It looks that there must be some permission issue for sample.bat when
it is placed on the System32 folder; so when Shell "cmd /k" is
executed somehow it is not authorised to 'see' that sample.bat is in
System32.

However, if I place sample.bat on i.e. C:\ then the problem is gone.

Oct 2 '08 #3
That looks like a permissions problem to me too. But you found a folder you
can put it in so you have a solution. I'd suggest making a new folder on c:\
to put and execute your batch file so the root doesn't get cluttered.

Chris
Microsoft MVP
Max Vit wrote:
>Hi Chris - This is what i have tried:

Shell "cmd /k c:\WINDOWS\System32\sample.bat"
-AND-
Shell "c:\WINDOWS\System32\cmd /k sample.bat"
-AND-
Shell "c:\WINDOWS\System32\cmd /k c:\WINDOWS\System32\sample.bat"

The result is still the same :-(

'c:\WINDOWS\System32\sample.bat' is not recognized as an internal or
external command, operable program or batch file.

I use the '/k' so the command windows is kept open; and on every
instance, doing a DIR on C:\WINDOWS\System32 for sample.bat brings no
results even though the file is there.
>It looks that there must be some permission issue for sample.bat when
it is placed on the System32 folder; so when Shell "cmd /k" is
executed somehow it is not authorised to 'see' that sample.bat is in
System32.

However, if I place sample.bat on i.e. C:\ then the problem is gone.
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200810/1

Oct 2 '08 #4

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

Similar topics

1
by: Joe Blo | last post by:
I have this line in my code that spits out (run time error 53, file not found). Running this program (project.exe) works fine if I do it through the command prompt or Run dialogue box on the...
10
by: Nick Craig-Wood | last post by:
I'm trying to avoid using shell metacharacters in os.popen in a portable fashion. os.popen() only seems to take a string as the command which would need tricky quoting. os.popen2() can take a...
5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
5
by: L337Hax0r | last post by:
for my operating systems design class i am supposed to write a shell in c. i have no idea where to start and our teacher hasn't given us much info. anyone know of any good tutorials?
8
by: zhiwei wang | last post by:
I remember that there is a function that could invoke shell command such as "rm" "cp", directly in .c file. But I could not recall its name, and I googled with nothing meaningful. I vaguely...
12
by: manochavishal | last post by:
Hi, I am having strange problem in my Program. I cannot paste the whole program as it is huge so just pasting the lines i think are necessary. I am passing a integer array pointer to a...
47
by: pkirk25 | last post by:
I've made a small program to demonstrate one problem I'm having fixing strings in C. I need to be able to remove HTML mark-ups from text lines. I create my variable, pass it to my function,...
23
by: g.ankush1 | last post by:
#include <stdio.h> /* 1st example int a() { return 1; }
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.