none
Please help: WMI: running batch script on remote machine using VBscript

    Question

  • I am trying to run batch script test1.bat on remote computer.

    I am not seeing error with below script and i don't know who to troubleshoot this . Please help. 

    test1.bat has vbscript and it it runs QTP script.

    Dim sServer 

    sServer = "<RemoreServerName>"    


    Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

    Set objSWbemServices = objSWbemLocator.ConnectServer(sServer, "root\cimv2", "<UserName>", "<Password>")

    Set objProcess = objSWbemServices.Get("Win32_Process")

    errReturn = objProcess.Create("C:\Scripts\test1.bat", Null, Null, intProcessID) 

    If errReturn <> 0 Then
      msgbox "It could not be started due to error: " & errReturn
    End If  


    Thursday, February 07, 2013 9:31 PM

Answers

  • Hey JRV, 

    It works when I logged in the the second machine and it runs the script. 


    That is what I keep posting.  It will only work if you are logged into the remote machine interactively.  You cannot use a remote background session.  What you are trying to do cannot be done.

    ¯\_(ツ)_/¯

    Monday, February 18, 2013 11:19 PM

All replies

  • YOu cannot run vbscript commands in a batch file.  The extension must be VBS.


    ¯\_(ツ)_/¯

    Thursday, February 07, 2013 9:51 PM
  • I mean this is VBS file on one machine and I am trying to run C:\Scripts\test1.bat file on remote machine.

    Thursday, February 07, 2013 9:53 PM
  • test1.bat has vbscript and it it runs QTP script. -- clarify: test1.bat calls a vbscript and inside that vbscript there is code to call Quality Center to run tests (QTP).

    When I go to remote computer and run the test1.bat manually and it works.

    When I use above VBscript code from another machine and nothing happens.

    I need help figuring out the above code is correct or not and troubleshooting help.

    Thursday, February 07, 2013 9:56 PM
  • c:\test1.bat has to be stored on remote machine and not locally.

    Not all comamnds can be run remotely so it would also depend on what is in the bat file.


    ¯\_(ツ)_/¯

    Thursday, February 07, 2013 10:14 PM
  • test1.bat is on the remote computer and I RDP to the remote computer and executed test1.bat on remote computer manually and everything works fine.

    Thursday, February 07, 2013 10:18 PM
  • contents of scripts folder

    test1.bat: test1.vbs

    test1.vbs: connecting to Quality center and run QTP scripts

    These works properly if I am in remote computer.

    Thursday, February 07, 2013 10:21 PM
  • That does not tell me what is in the test1.bat file.


    ¯\_(ツ)_/¯

    Thursday, February 07, 2013 10:47 PM
  • Here you go:

    test1.bat:

    ----------

    cd C:\Scripts

    test1.vbs


    Thursday, February 07, 2013 10:56 PM
  • Can't be done.  It requires advanced delegation and Windows does not have that capability under normal circumstances.

    test1.bat calls test1.vbs which calls a remote copy of the same.  - Not allowed.


    ¯\_(ツ)_/¯

    Thursday, February 07, 2013 11:02 PM
  • Have you tried using psexec.exe from the pstools suite? It may be another way to appraoch your problem.

    http://download.sysinternals.com/files/PSTools.zip

    Cheers

    Friday, February 08, 2013 12:23 AM
  • Have you tried using psexec.exe from the pstools suite? It may be another way to appraoch your problem.

    http://download.sysinternals.com/files/PSTools.zip

    Cheers

    It does not matter whether it is WMI or PsExec.  Windows is designed to not allow this to work without changing the security on the systems.

    Look up WMI delegation or second hop.


    ¯\_(ツ)_/¯

    Friday, February 08, 2013 12:26 AM
  • Thanks jrv and other people:

    Looks like JRV is confused how i am doing, below is the complete picture:

    ------------------------------------------------------------------------------

    Machine 1:

    testa.bat: it has below VBS

    testb.vbs:

    Dim sServer 

    sServer = "<RemoreServerName>"    


    Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

    Set objSWbemServices = objSWbemLocator.ConnectServer(sServer, "root\cimv2", "<UserName>", "<Password>")

    Set objProcess = objSWbemServices.Get("Win32_Process")

    errReturn = objProcess.Create("C:\Scripts\test1.bat", Null, Null, intProcessID) 

    If errReturn <> 0 Then
      msgbox "It could not be started due to error: " & errReturn
    End If  

    --------------------------------------------------------------------------------------

    Machine2:


    test1.bat:

    ----------

    cd C:\Scripts

    test1.vbs

    Friday, February 08, 2013 3:59 PM
  • Please suggest now. I will look into the link you sent
    Friday, February 08, 2013 4:00 PM
  • Thanks jrv and other people:

    Looks like JRV is confused how i am doing, below is the complete picture:

    ------------------------------------------------------------------------------

    Machine 1:

    testa.bat: it has below VBS

    testb.vbs:

    Dim sServer 

    sServer = "<RemoreServerName>"    


    Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

    Set objSWbemServices = objSWbemLocator.ConnectServer(sServer, "root\cimv2", "<UserName>", "<Password>")

    Set objProcess = objSWbemServices.Get("Win32_Process")

    errReturn = objProcess.Create("C:\Scripts\test1.bat", Null, Null, intProcessID) 

    If errReturn <> 0 Then
      msgbox "It could not be started due to error: " & errReturn
    End If  

    --------------------------------------------------------------------------------------

    Machine2:


    test1.bat:

    ----------

    cd C:\Scripts

    test1.vbs

    What is in test1.vbs on machine2?


    ¯\_(ツ)_/¯

    Friday, February 08, 2013 6:48 PM
  • Please suggest now. I will look into the link you sent

    what link are you talking about?

    Links are accessed by just clicking.


    ¯\_(ツ)_/¯

    Friday, February 08, 2013 6:48 PM
  • test1.vbs in machine 2 is the code to connecting HP Quality Center tool and Run QTP Script.
    Friday, February 08, 2013 7:21 PM
  • test1.vbs in machine 2 is the code to connecting HP Quality Center tool and Run QTP Script.

    That does not tell me what is in the file only what you think it is supposed to do.

    ¯\_(ツ)_/¯

    Friday, February 08, 2013 8:27 PM
  • This script is working properly when I go the remote machine (machine 2) and tested it out and looks perfect. It connects to Quality Center, go to specific test set in test lab, run the test set, sends email based on result of the test. 

    It is not working when invoking from machine 1.

    Let me know if you need other details.

    Friday, February 08, 2013 8:36 PM
  • This script is working properly when I go the remote machine (machine 2) and tested it out and looks perfect. It connects to Quality Center, go to specific test set in test lab, run the test set, sends email based on result of the test. 

    It is not working when invoking from machine 1.

    Let me know if you need other details.


    We cannot help you if you cannot post the script you are talking about.  You cannot remotely execute a process that authenticates to a third machine.  Many processes will only work in a full interactive session. WMI is not a full session.  Only seeing what you are doing in your script will resolve this.

    ¯\_(ツ)_/¯

    Friday, February 08, 2013 9:14 PM
  • It's possible there may be security software on your remote machine which is stopping remote execution?

    Inspired by Carlsberg.

    Friday, February 08, 2013 9:35 PM
  • Here you :

    test1.vbs:

    Call RunTestSet("<Test Name>", "<Test Set Name>", "<ServerName>", "RUN_REMOTE")


    Public Sub RunTestSet(tsFolderName, tSetName, HostName, runWhere)


    ' Get the test set tree manager from the test set factory.
        'tdc is the global TDConnection object.
        Set tdc = CreateObject("TDApiOle80.TDConnection.1")
        tdc.InitConnectionEx "<QCURL>"
        tdc.ConnectProjectEx "DEFAULT", "<ProjectName>", "<UserName>", "<Password>"
        Set tsTreeMgr = tdc.TestSetTreeManager

    ' Get the test set folder passed as an argument to the example code.
        nPath = "<FolderPath>" & Trim(tsFolderName)
        Set tsFolder = tsTreeMgr.NodeByPath(nPath)

    ' Search for the test set passed as an argument to the example code.
        Set tsList = tsFolder.FindTestSets(tSetName)
        Set theTestSet = tsList.Item(1)

    ' Start the scheduler on the local machine.
        Set Scheduler = theTestSet.StartExecution("")
        Scheduler.TdHostName = HostName

    ' Run the tests.
        Scheduler.Run
      
        Set execStatus = Scheduler.ExecutionStatus
            
        While RunFinished = False
        execStatus.RefreshExecStatusInfo "all", True
            RunFinished = execStatus.Finished
        Wend
        
    'Send Notification Email
        Set tsTestFactObj= theTestSet.TSTestFactory
        set TestSetTestsList = tsTestFactObj.NewList("")
     
        for each y in TestSetTestsList
    tsId = y.id
        next

        Set tsTestObj = tsTestFactObj.Item(tsId)

        If tsTestObj.status = "Failed" Then
    Set tsRunObj = tsTestObj.LastRun
    Set tsStepFactObj = tsRunObj.StepFactory

    Set tsStepList = tsStepFactObj.newList("")
    for each y in tsStepList
    if y.status = "Failed" Then
    message = message & "Status: " & y.status & "<br/>" &_
     "Step Name: " & y.name & "<br/>" &_
     "Actual Results: " & y.field("ST_DESCRIPTION") & "<br/>" & "<br/>"
    End If
    next

        tdc.Sendmail "<UserName>",,"Test Results for " & tsTestObj.name & ": FAILED", message
        Else If tsTestObj.status = "Passed" Then
    tdc.Sendmail "<UserName>", "Test Results for " & tsTestObj.name & ": PASSED", "The Test Passed"
        Else
    tdc.Sendmail "<UserName>", "Test Results for " & tsTestObj.name & ": INCOMPLETE", "The Test Did Not Complete"
        End If
        End If


    End Sub
     

    Friday, February 08, 2013 11:17 PM
  • What results are you getting? Is an email sent? Which one?

    The next step would be to put add some logging, and output the logging messages to a file:

    a) to determine if the vbs script actually runs

    b) to determine at what point the script is failing.

    c) to capture any error messages that may be generated.

    After each commented block in the code you posted, I would write a checkpoint message to a logfile... "Completed test set tree manager"


    Inspired by Carlsberg.

    Friday, February 08, 2013 11:33 PM
  • I replied on another thread: http://social.technet.microsoft.com/Forums/lt/ITCG/thread/a5e9c4e5-e21a-4f71-befd-c38db0e182ab



    Hey Raffy,
    Below is my observation:

    1)
    If test1.bat has only below : works and I see Hellow world on test file
    echo "Hello World" > c:\temp\test.txt

    2) If test1.bat has only below: Does see anything  and no file created with Hello world
    cd C:\Scripts
    test1.vbs
    echo "Hello World" > c:\temp\test.txt

    Let me do some troubleshooting.

    Friday, February 08, 2013 11:54 PM
  • I'm guessing if you rearrange the order:

    cd C:\Scripts
    echo "Hello World" > c:\temp\Step1.txt

    test1.vbs

    echo "Hello World" > c:\temp\Step2.txt

    the c:\temp\Step1.txt appears, but not c:\temp\Step1.txt? (it would help to delete the files after each test)

    You need to put some logging in the vbscript to test if it even starts.


    Inspired by Carlsberg.

    Saturday, February 09, 2013 12:37 AM
  • Last time I am going to post this.  You cannot remotely run a script that tries to touch a third machine.  This requires delegation and so your script will not work when run remotely.

    Sorry - but what you are trying to do cannot be made to work except when you are directly logged into the remote machine.

    Look again at this link as it explains in detail why this cannot work.

    See: http://technet.microsoft.com/en-us/library/ee692772.aspx#EDAA


    ¯\_(ツ)_/¯

    Saturday, February 09, 2013 1:00 AM
  • I replied on another thread: http://social.technet.microsoft.com/Forums/lt/ITCG/thread/a5e9c4e5-e21a-4f71-befd-c38db0e182ab



    Hey Raffy,
    Below is my observation:

    1)
    If test1.bat has only below : works and I see Hellow world on test file
    echo "Hello World" > c:\temp\test.txt

    2) If test1.bat has only below: Does see anything  and no file created with Hello world
    cd C:\Scripts
    test1.vbs
    echo "Hello World" > c:\temp\test.txt

    Let me do some troubleshooting.

    Here is another issue that you are not factoring in.  YOU have NO error management. You will never see if there are any errors.  Implement error handling to a file and you will likely see the error that is being thrown.


    ¯\_(ツ)_/¯

    Saturday, February 09, 2013 1:09 AM
  • I think jrv might be right. It depends on how the second machine authenticates to the machine hosting HP Quality Center.

    In my environment, I have no trouble creating a pssession on remote machines and executing a vbscript within that session which connects to a third machine running SQL server. That's because the connection method to the SQL server supplies it's own credentials (SQL creds, not Windows Domain creds).

    It depends on how the connection to HP Quality Center supplies credentials.

    If it relies on the credentials of the user running the script, it's going to fail, because of the double hop issue jrv mentioned earlier.

    If there's an alternative way, maybe specifying the credentials, you may be able to get it to work.


    Inspired by Carlsberg.

    Saturday, February 09, 2013 1:17 AM
  • I think jrv might be right. It depends on how the second machine authenticates to the machine hosting HP Quality Center.

    In my environment, I have no trouble creating a pssession on remote machines and executing a vbscript within that session which connects to a third machine running SQL server. That's because the connection method to the SQL server supplies it's own credentials (SQL creds, not Windows Domain creds).

    It depends on how the connection to HP Quality Center supplies credentials.

    If it relies on the credentials of the user running the script, it's going to fail, because of the double hop issue jrv mentioned earlier.

    If there's an alternative way, maybe specifying the credentials, you may be able to get it to work.


    Inspired by Carlsberg.

    This is not really the explanation.  Only with WinRM can you supply explicit credentials and only using CredSSP and HTTP protocol.  In a domain you must use Kerberos to authenticate.  Kerberos credentials cannot be passed explicitly.  With WMI there is no way to do this.  If he HP test server or any part of its target are on a third server this cannot be made to work without altering the security of the domain.

    ¯\_(ツ)_/¯

    Saturday, February 09, 2013 1:39 AM
  • Thanks everyone.

    I got admin access now.

    It is working if I stay logged in the the server computer using windows RDP manually. It does not work if I logged off the machine and run it.

    Any suggestion?

    Thursday, February 14, 2013 4:40 PM
  • Thanks everyone.

    I got admin access now.

    It is working if I stay logged in the the server computer using windows RDP manually. It does not work if I logged off the machine and run it.

    Any suggestion?

    As noted before. YOu cannot do what you are trying to do due to security restrictions on delegation.

    Sorry.


    ¯\_(ツ)_/¯

    Thursday, February 14, 2013 4:51 PM
  • Any other ways I can achieve this.
    Thursday, February 14, 2013 5:06 PM
  • Any other ways I can achieve this.

    Yes - Use PowerSHell with remoting and CredSSP.  Other than that you will have to explain what the intended outcome is.  Most likely a completelty different qappraoch can get you where you need to be.


    ¯\_(ツ)_/¯

    Thursday, February 14, 2013 9:31 PM
  • Some details about what I am trying to do:

    Machine1: Windows Build server. Once build is completed. It will trigger automated QTP tests from HP Quality Center. For this purpose, we need machine2.

    Machine2: VB script codes connect to Quality Center Client and find the test and opens QTP tool and runs the test.

    Monday, February 18, 2013 10:16 PM
  • You cannot run a script that connects to a remote machine and then connect to a third machine.  This is not allowed in Windows.  No matter how many times you ask this question the answer will always be that you cannot do this.  It is a fundamental limitation of Windows with some very limited exceptions.

    Sorry


    ¯\_(ツ)_/¯

    Monday, February 18, 2013 10:25 PM
  • Hey JRV, 

    It works when I logged in the the second machine and it runs the script. 

    Monday, February 18, 2013 11:12 PM
  • Hey JRV, 

    It works when I logged in the the second machine and it runs the script. 


    That is what I keep posting.  It will only work if you are logged into the remote machine interactively.  You cannot use a remote background session.  What you are trying to do cannot be done.

    ¯\_(ツ)_/¯

    Monday, February 18, 2013 11:19 PM
  • Hi psnovice,

    It sounds more like you need help configuring a solution for a specific product or set of products that you are using. This is not the correct forum for this discussion.

    Bill

    Monday, February 18, 2013 11:57 PM
    Moderator