locked
Trying to execute a batch file on a remote computer RRS feed

  • Question

  • I have a VB procedure that loops through many elements in an array.  This used to work fine on a XP machine, but it was just upgraded to Windows 7, and now it doesn't work.

    Shell ("psexec \\" & rCell & " C:\Windows\post-script.bat")

    rCell is a name in a name in an Excel Cell. 

    I've tried a bunch of things.  This looked promising, but didn't work.

    Set objShell = CreateObject("wscript.shell")
    objShell.Run ("runas /user:domain\administrator psexec \\" & rCell & " C:\Windows\post-script.bat"), 1, True

    Has anyone tried this and gotten it to work? If so, please do share!!


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Monday, October 6, 2014 4:30 PM

Answers

  • I finally figured it out.  This is the solution.
    http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23277839.html

    Maybe it will help someone else, who wanders over here someday.

    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


    • Edited by ryguy72 Tuesday, October 7, 2014 6:25 PM
    • Marked as answer by ryguy72 Wednesday, October 8, 2014 1:19 AM
    Tuesday, October 7, 2014 6:24 PM
  • We keep posting the obvious.  Post your issues in the PsExec forum.  Your problems are with how to use PsExec.   They have nothing to do with scripting.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Tuesday, October 7, 2014 3:04 AM
    Tuesday, October 7, 2014 1:21 AM

All replies

  • I have a VB procedure that loops through many elements in an array.  This used to work fine on a XP machine, but it was just upgraded to Windows 7, and now it doesn't work.

    Shell ("psexec \\" & rCell & " C:\Windows\post-script.bat")

    rCell is a name in a name in an Excel Cell. 

    I've tried a bunch of things.  This looked promising, but didn't work.

    Set objShell = CreateObject("wscript.shell")
    objShell.Run ("runas /user:domain\administrator psexec \\" & rCell & " C:\Windows\post-script.bat"), 1, True

    Has anyone tried this and gotten it to work? If so, please do share!!


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


    Monday, October 6, 2014 4:05 PM
  • I would recommend posting your question to The Official Scripting Guys Forum!, since this forum is primarily for Visual Basic .NET questions.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by IronRazerz Monday, October 6, 2014 6:30 PM
    Monday, October 6, 2014 4:29 PM
  • Hi,

    This isn't a support forum for the psexec utility. Try asking here:

    http://forum.sysinternals.com/pstools_forum8.html


    -- Bill Stewart [Bill_Stewart]

    Monday, October 6, 2014 5:04 PM
  • Try this first:

    Set objShell = CreateObject("wscript.shell")
    cmd = "runas /user:domain\administrator psexec \\" & rCell & " C:\Windows\post-script.bat"
    msgbox cmd
    objShell.Run cmd, 1, True

    Look closely at the command you are sending.


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 5:07 PM
  • I'm looking VERY closely.  I changed the number of parameters to 1.

    Set objShell = CreateObject("wscript.shell")
    cmd = "runas /user:domain\administrator psexec \\" & rCell & " C:\Windows\post-script.bat"
    msgbox cmd

    objShell.Exec cmd


    It still doesn't work.


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Monday, October 6, 2014 8:11 PM
  • What di you see in the message box?  Was the command correct?

    You really can't runas a psexec command on any platform unless you have cached credentials.  If you try to PsExec back to your own system on Vista or later it will not work no matter what you try to do.  That has been disabled for security reasons.

    As Bill noted you wll need to post in the sExec forum to get instructions on how to use PsExec in Vista and later.  It is not a scripting issue.

    To remote with alternate credentials you can elevate a prompt then run your script.


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 8:47 PM
  • I see everything from the line of code:

    runas /user:domain\administrator psexec  (the actual user & domain)

    machine name (which comes from rCell) & C:\Windows\post-script.bat

    It has something to do with credentials and security.  I know that much for sure!

    Thanks guys.


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Monday, October 6, 2014 10:03 PM
  • The runas command prompts for a password. (No, you can't bypass this.)

    So if you run this command using psexec, psexec is going to spawn runas.exe, and runas.exe is going to sit and wait for a password entry. There is no one there. Hence, the command will hang indefinitely. (Presumably, this is what you meant by "didn't work." When you say that something didn't work, you have to say how it didn't work.)


    -- Bill Stewart [Bill_Stewart]


    Monday, October 6, 2014 10:07 PM
  • Yes, Yes, I know.  LOL.  I used to work with people who said it all the time...'it doesn't work.'  My first and only response was, 'what doesn't work?'

    Sorry.  Actually, there is no error or anything.  It just does nothing at all.  So, obviously I'm not an expert with these remote machines.  

    I never used a password and I was never prompted for a password.  

    Would it looks something like this?
    psexec \\workstation64 -c test.exe -u UserName -p Pa55w0rd

    Would it be something like this?
    psexec -user UserName -p Pa55w0rd "C:\Windows\post-script.bat"

    Maybe I need to try using PowerShell.  I've never worked with it; maybe it's time to learn a new skill.  At this point, I'm trying to get this working probably as quickly as possible.  Deadlines loom.

    Finally, this may be a dumb question, but is the UserName & Pa55w0rd that of the machine that I'm running this code from, or that of the machine that I'm running the batch file on?  I think it's the one where I'm running the batch file, right.

    I'd really appreciate any insight with this!!


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


    • Edited by ryguy72 Tuesday, October 7, 2014 1:27 AM
    Tuesday, October 7, 2014 1:18 AM
  • We keep posting the obvious.  Post your issues in the PsExec forum.  Your problems are with how to use PsExec.   They have nothing to do with scripting.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Tuesday, October 7, 2014 3:04 AM
    Tuesday, October 7, 2014 1:21 AM
  • Right; as noted, you really have a psexec question, not a scripting question.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, October 7, 2014 3:04 AM
  • I finally figured it out.  This is the solution.
    http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23277839.html

    Maybe it will help someone else, who wanders over here someday.

    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


    • Edited by ryguy72 Tuesday, October 7, 2014 6:25 PM
    • Marked as answer by ryguy72 Wednesday, October 8, 2014 1:19 AM
    Tuesday, October 7, 2014 6:24 PM
  • Good day ryguy72

    You have unclose threads please check this and close the thread if the issue is closed, or inform us if you need any more help

    Thanks!

    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/77fc0a4f-fb12-4699-9a98-f3e94a626785/how-to-recursively-sum-a-sum?forum=transactsql


    [Personal Site]  [Blog]  [Facebook]
    signature

    Tuesday, October 7, 2014 10:37 PM