Forum Discussion

Radar's avatar
Radar
Occasional Contributor
13 years ago

Query Schedule Task On Remote Virtual Machine

We have a testing environment which comprises a number of VM's that represent our production system.

TestComplete resides on its own XP VM in this environment, however is part of a Workgroup and is not on the Domain with the VM's that make up the system.



What I am trying to do is check if a Schedule Task exists on one of the remote VM's in the environment.  I am trying to achieve this by doing the following:



[JScript]


    var remoteServer = "\\\\AMIPSP01"

    var userName = "user";

    var passWord = "password";

    var computerName = aqEnvironment.GetEnvironmentVariable("COMPUTERNAME");

    var tempPath = aqEnvironment.GetEnvironmentVariable("TEMP");

    var fullTempPath = LongPathName(tempPath); //function to convert the short path name to a long path name

    var tempDir = aqString.Replace(fullTempPath, ":","$"); 

    var fileName =  "\\\\"+computerName+"\\"+tempDir+"\\SchduleTaskList.csv";





    var cmdString = "SCHTASKS /Query /S "+remoteServer+" /U "+userName+" /P "+passWord+" /FO CSV >> "+fileName;



    var processID = WMI.CreateProcess(cmdString);



I ave tried this script an a number of variations, however have not been able to generate a file listing the scheduled tasks.



Your help will be appreciated.



Regards

Mark

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I just responded to another of your posts with a suggestion to use the WScript.Shell object to execute the command line.



    Take a look at what I did there and see if that object works for this situation as well.
  • Radar's avatar
    Radar
    Occasional Contributor
    Hello Robert,



    I tried using the same method as suggested for my earlier post, however it was not successful.



    cmdString =  "SCHTASKS /Query /S "+remoteServer+" /U "+userName+" /P "+passWord+" /FO CSV >> "+fileName;


            shellObject = Sys.OleObject("WScript.Shell")

            execOut = shellObject.Exec(cmdString)


    I can use the very same string on a command line and that works, however via TC script I am not having any luck.



    Regards

    Mark
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    What part of it is not working?  When the script runs, you should see a CMD prompt display showing the command line being executed.  Is it that the command line does not execute?  Or are you expecting some sort of value to come back on the Exec?  Exec, as far as I know, does not return any values.  Please give some more details as to what is happening, what errors you're seeing, etc.
  • Radar's avatar
    Radar
    Occasional Contributor
    Hello Martin



    When I say it is not working, I mean the expected csv file is not generated.

    The command is executing, as I can see the command window open and close, however the CSV file containing the information is not created.

    If I copy the string directly into a command window it does work.

    I get the string by copying it from the Debug/Evaluate dialog.



    Regards

    Mark
  • Radar's avatar
    Radar
    Occasional Contributor
    Hello Martin



    Have you been able to give this query any further thought?



    Regards

    Mark
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    WScript.Shell has a working directory property.  I wonder if it's possible that must be set in order to actually see the CSV file get created.  That's something to investigate at least.