Execution Question

Posted on 2004-10-27
Last Modified: 2010-04-17

I have this line in my code:

objShell.Run("psexec \\ -s -u hostx -p hostxpass diruse /s /m /* " & "d:\root\" & " > " & "d:\root\will\test.txt")
If I echo the command out, and just copy and paste it into a command prompt, the script executes as expected.

However, if I run it using the above code, the command executes fine BUT it does not pipe it out into a file.  To double check, I made sure the program ran a longtime, and in the title bar it said \\ -s -u hostx -p hostxpass diruse /s /m /* d:\root\ > d:\root\will\test.txt

Does anybody have any idea why the pipe out is working if I execute it from the command prompt, but not from the Run method?
Question by:gexen
    LVL 5

    Expert Comment

    i think u'll have to escape the \

    ie. write \\ instead of \ in the whole string
    LVL 1

    Author Comment

    I don't believe that is the case in VBScript, as \ is not an escape operator as far as I know..

    Also, the script executes correctly, the pipe doesn't work.  If it were an escape issue with the \'s, it wouldn't  have run correctly because it needs the full path "d:\root\" to execute.
    LVL 23

    Accepted Solution

    When you run the cxommand that way, there's no command shell to see the redirect.  Instead, explicitly run the command shell with "cmd /c prog.exe args >filename"
    LVL 23

    Expert Comment

    To wit:

    objShell.Run("cmd /c psexec \\ -s -u hostx -p hostxpass diruse /s /m /* " & "d:\root\" & " > " & "d:\root\will\test.txt")

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    countEvens challenge 2 36
    bigDiff challenge 17 45
    VBA color chart bars 12 38
    find a node in VST 2 24
    This is an explanation of a simple data model to help parse a JSON feed
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now