Forum Discussion

Ryan_Moran's avatar
Ryan_Moran
Valued Contributor
11 years ago

JScript Built in method to run shell commands

Looking for a built in method to run shell commands.



Currently using:



wshell = new ActiveXObject('WScript.Shell');




function run(p){


 wshell.run(p);


}



Thanks.
  • Hi Ryan, the CLR Bridge allows for the usage of managed assemblies created using the .Net framework, see the documentation here




    For example, the following code shows how to create a GUID using System.Guid in the .Net Framework


     


    function createGuid() {


      var guid = dotNET.System.Guid.NewGuid();


      Log.Message( guid.ToString() );


    }


     


    Be aware, though, the CLR Bridge is not able to expose all .Net Classes as you would expect in Visual Studio, therefore I have created a number of .Net helper assemblies that I use to wrap up any .Net functionality I want to utilise.


     


    User32.dll is not available to CLR Bridge as it is not a managed assembly, however, the documentation here describes now you can access User32.dll




    Phil

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Ryan, the CLR Bridge allows for the usage of managed assemblies created using the .Net framework, see the documentation here




    For example, the following code shows how to create a GUID using System.Guid in the .Net Framework


     


    function createGuid() {


      var guid = dotNET.System.Guid.NewGuid();


      Log.Message( guid.ToString() );


    }


     


    Be aware, though, the CLR Bridge is not able to expose all .Net Classes as you would expect in Visual Studio, therefore I have created a number of .Net helper assemblies that I use to wrap up any .Net functionality I want to utilise.


     


    User32.dll is not available to CLR Bridge as it is not a managed assembly, however, the documentation here describes now you can access User32.dll




    Phil

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Ryan, I am not aware of a nice way to do this in Test Complete.


     


    However, I also wasn't happy with the prescribed approach so I wrote a .Net library that effectively wraps System.Diagnostics.Process which enables me to execute commands silently and, IMHO, more cleanly, which I access via the CLR Bridge.


     


    Regards,


    Phil Baird

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Not familiar with this CLR Bridge....could I use this to access the user32.dll possibly?
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Ryan,


     


    I've recently posted the script of how to execute the Xcopy command in TestComplete. Here it is. You can use a similar approach. 


     

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Tanya,

    I appreciate the response but I fail to see how that is different from the original code I posted. Can you explain further to help me understand?
  • jorgesimoes1983's avatar
    jorgesimoes1983
    Regular Contributor
    I use similar code, and the run a bat file with commands, for instance:



    function kill_internet_explorer()

    {

      // gets the path to the current project

      var Path;

      var ficheiro = "kill_internet_explorer.bat";  

      Path = Project.Path;  

      Path += ficheiro;

     

      // allows path with spaces

      var objShell = new ActiveXObject("shell.application");        

      objShell.ShellExecute(ficheiro, "", "Path", "open", 1);

     



      //Log.Message(Path);



      //obj.Run(Path);

     

      Delay(2000);

    }



    then...



    .bat file content as such:



    taskkill /f /im "iexplore.exe"

    start /MAX iexplore.exe