Forum Discussion

aa1's avatar
aa1
Contributor
6 years ago

Run a bat file from network does not work

Hi,

 

I am trying to use wshshell to run a bat file from cmd but somehow I cannot get it right. All I am doing is do a cd\ on the cmd to get back to local and then browse the network path. Do I need to map it to local drive? Please help!

 

var path = "\\\abc.local\\def\\Clickonce\\AB\\stg\\xyz.temp.Desktop.application";
  var WshShell = new ActiveXObject("WScript.Shell");
  WshShell.Run("cmd /K cd\\" & "cmd /K" + path);
  Delay(10000);

The error just says: 

 

JScript runtime error.

The system cannot find the file specified
 
Thank you in advance,
aa
  • Rather than use "CD", set the CurrentDirectory property on the WshShell object.

     

    For that matter... you don't need to instantiate the shell object... TestComplete provides a wrapper.  I don't think, either, that you need to use the CMD /K anywhere in this... you just need to indicate the batch file to run... which is, I assum, the contents of the "path" variable.

     

    var path = "\\\abc.local\\def\\Clickonce\\AB\\stg\\xyz.temp.Desktop.application";
      WshShell.CurrentDirectory = "C:\\" //Or whatever you want your root to be
      WshShell.Run(path);
      Delay(10000);
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You're trying to run two commands within the same WShellRun command.  I don't think that's allowed.  Try splitting it into two different runs rather than trying to concatenate with the & symbol

    • aa1's avatar
      aa1
      Contributor

      Hi tristaanogre ,

       

      Thank you for the reply. I tried doing that but I couldnt make it to work. If I split it into two lines:

       

      1. WshShell.Run("cmd /K cd\\") ----- Opens cmd and resets the path due to cd\

      2. WshShell.Run("cmd /K" + path); -- Opens cmd and searches for the path and gives error that it cannot find the path specified. The path is not accessible from this location.

       

      I need to reach the path after doing cd\ so how do I do it in two steps?

       

      Please advise.

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Rather than use "CD", set the CurrentDirectory property on the WshShell object.

         

        For that matter... you don't need to instantiate the shell object... TestComplete provides a wrapper.  I don't think, either, that you need to use the CMD /K anywhere in this... you just need to indicate the batch file to run... which is, I assum, the contents of the "path" variable.

         

        var path = "\\\abc.local\\def\\Clickonce\\AB\\stg\\xyz.temp.Desktop.application";
          WshShell.CurrentDirectory = "C:\\" //Or whatever you want your root to be
          WshShell.Run(path);
          Delay(10000);