Results 1 to 14 of 14
  1. #1
    pgaccess is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    6

    Problem with Shell from Access

    Hello Guys,


    I'm a new entry in that forum and I haven't so much experience, so I meet a problem with Shell function.
    I'll try to explane the situation, I need to execute a dos command from Access 2007, so I wrote as below :

    shell ("wmic csproduct get name,vendor > LogFile.log")

    when that row is executes the Prompt window flashing for one second and no error for that command but the LogFile.log is missing, if I try to execute the command from Prompt of Dos it works perfectly. Why ?

    The work directory is c:\users\pippo\

    Please let me know something, thanks in advance.

    PG

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    put the command into a .BAT file , then shell the bat.

    call shell ("c:\runthis.bat")

    runthis.bat file:
    wmic csproduct get name,vendor > LogFile.log

  3. #3
    pgaccess is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    6
    Thank you,
    perhaps I have not said everything, I've done as you told me, but my intention is to eliminate every .bat file in order to execute the command when the user runs my access application.
    I would like to get the information I need without the user knows and reads this process in the working directory, this should be a gosth process. I hope I have explained my intention possibly without written .bat files in the directory but run Shell commands directly from Access, is it technically possible?

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What about this: Shell "cmd.exe /c <yourcommand>"

  5. #5
    pgaccess is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    6
    As you told me I tried to execute this but it doesn't work:

    Shell "cmd.exe /c wmic csproduct get name,vendor > Path & LogFile.log"

    Path is variable where I put the work directory ...

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    1 - does the cmd work in DOS exactly as you typed it above?
    2 - does the Shell work without using a variable path?

  7. #7
    pgaccess is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    6
    1. No, but when I write the command from access it needs to knows the path because without doesn't work
    2. Yes, from prompt of Dos it works if I typed manually the path : cmd.exe /c wmic csproduct get name,vendor > c:\users\pippo\LogFile.log

    However I need to execute the command from Access !!! That's the real problem !!!
    Please, you Try to write the command into a bat file and run it from Access and let me know your test ...

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    1 - No? first get the cmd working in DOS prior to trying to make it work in Access
    2 - if it is the path that is causing the problem then find the path in Access prior to running the Shell

  9. #9
    pgaccess is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    6
    Perhaps I have explained not so good, forget the path for the moment ...

    1. I told you that in DOS this command works :
    cmd.exe /c wmic csproduct get name,vendor > c:\users\pippo\LogFile.log
    2. If I put the following command in ACCESS doesn't works : Shell "
    cmd.exe /c wmic csproduct get name,vendor > c:\users\pippo\LogFile.log"

    Why ? Could you try in your PC ?

  10. #10
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Here's another one that evidently works: Shell "cmd /c echo go>C:textfile.txt"

    Sorry, I am unable to try it on my pc.

    Another option is to create a temp bat file just before the Shell command, maybe in temp folder, with the command you want, then Shell it, then delete it.

  11. #11
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Hmm... Executing your Shell command in the VB Immediate Window, changing c:\users\pippo to c:\users\jwhite (for my PC), it worked fine. Could it be something like an application permission issue? Is c:\users\pippo set as a Trusted Location in Ac2007? If you changed it to write to c:\temp and created the folder beforehand, does that work?

  12. #12
    pgaccess is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    6
    Thanks at all,

    I solved as below :

    Shell "cmd.exe /c wmic csproduct get name,vendor >" & Path & "LogFile.log"

    Now I can execute the shell from Access defining the path as I want, reading the LogFile.log e after erase the
    LogFile.log without that user see that process and the .log file ....

    Wow !!! Thanks again !!!

  13. #13
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Well done! (Not sure how much help we were!)

  14. #14
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    We both overlooked sample string in post #5 - the variable is within the quoted string to execute.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How can I import ColumnHistory into a new Access shell?
    By tgall in forum Import/Export Data
    Replies: 6
    Last Post: 01-25-2019, 07:36 AM
  2. Calling Microsoft Power Shell from within Access
    By crowegreg in forum Programming
    Replies: 1
    Last Post: 11-18-2014, 02:59 PM
  3. Run Database while hiding Access Shell
    By Sarah88 in forum Programming
    Replies: 1
    Last Post: 08-19-2014, 10:11 AM
  4. Weird problem with Call Shell
    By oatsybob in forum Programming
    Replies: 8
    Last Post: 07-04-2013, 12:02 AM
  5. Replies: 8
    Last Post: 02-05-2013, 02:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums