Connecting Tech Pros Worldwide Forums | Help | Site Map

Shell function strange behaviour

Max Vit
Guest
 
Posts: n/a
#1: Oct 2 '08
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!

Chris O'C via AccessMonster.com
Guest
 
Posts: n/a
#2: Oct 2 '08

re: Shell function strange behaviour


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:
Quote:
>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

Max Vit
Guest
 
Posts: n/a
#3: Oct 2 '08

re: Shell function strange behaviour


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.

Chris O'C via AccessMonster.com
Guest
 
Posts: n/a
#4: Oct 2 '08

re: Shell function strange behaviour


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:
Quote:
>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.
Quote:
>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

Closed Thread