Script to check internet conectivity

I am admin user and the WshShell.Exec works…

Reading ping responce shouldnt from text shouldnt be to bad so long as can trim lines, if not so long as response times stay between 10-99ms the layout should be similar up to % loss (0-100)

I seem to remember that @emre gave us the ability to read return values of program execution. I need to find that post.

Also, recent enhancements to file.X() helper in latest .57 refresh added an execute function…

file.For('c:\\folder\\test.txt').Starter().Execute();

The new ones were for folder creation I think…

file.ReadFromFile()

But if we could read directly from cmd exe that would be sweeeeet.

function test(){
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("cmd /c ping 8.8.8.8 > C:\\Pinglog.txt");
var listFile = file.ReadFromFile("C:\\Pinglog.txt");
var listLine	= listFile.split('\n')
return listLine[7];
}

kinda works but need to delay the read file as ping obviously takes time…

Google responses all relate to delaying whole function.

I guess this isn’t new at all - it was added in .52 …

file.Starter(<filePath>).Execute();
file.Starter(<filePath>).Hidden.Execute();
file.Starter(<filePath>).With(<arguments>).Execute();
file.Starter(<filePath>).WorkOn(<workingDir>).Execute();
var returnVal = file.Starter(<filePath>).With(<arguments>).WorkOn(<workingDir>).Hidden.ShellExecute();
1 Like

Hmm, am struggling to use;
var returnVal = file.Starter(<filePath>).With(<arguments>).WorkOn(<workingDir>).Hidden.ShellExecute();

Not sure on the definitions of the parameters;

function test(){
var response = file.Starter("C:\\Pinglog.txt").With("cmd /c ping 8.8.8.8 > C:\\Pinglog.txt").WorkOn("C:\\").Hidden.ShellExecute();
return response
}

If giving a samba complete freeze

FilePath is the path/file to the executable. Using ShellExecute() you should even be able to set the file to .htm to launch Browser, .txt to launch Notepad, etc…

1 Like
function test(){
var response = file.Starter("C:\\Windows\\System32\\cmd.exe").With("ping 8.8.8.8").Hidden.ShellExecute();
return response
}

Thanks, makes seance, am still struggling though, above still gives faital samba freeze.

Take out Hidden.

SambaPOS is waiting for the command window to be closed to return a value. Once you close the window, the return is generated.

Once you get it working properly and the window can close on its own, you should be able to put Hidden back in.

1 Like

Ok thanks, great.

With("ping 8.8.8.8")
obviously isnt the what cmd to run.

where does the pin command go?

Not sure. Have not been able to get ping to work yet.

function exec() {
  var p = 'C:\\Windows\\System32\\';
  var f = 'cmd.exe';
  var args = '/c ping 8.8.8.8 > C:\\Pinglog.txt';
  var wdir = 'C:\\';
  var returnVal = file.Starter(p+f).With(args).WorkOn(wdir).ShellExecute();
  return 'rv:'+returnVal;
}

I expected that to work, but it does not. And theoretically, we should be able able to call ping directly, without cmd.exe. Though I suppose we need CMD functionality to redirect ping output to file.

1 Like

Your script gives me the ping file in c: and return value of rv:-1073741510

Would settle for reading from text file if can not have the cmd window open every time run…

function exec() {
  var p = 'C:\\Windows\\System32\\';
  var f = 'cmd.exe';
  var args = 'ping 8.8.8.8';
  var wdir = 'C:\\';
  var returnVal = file.Starter(p+f).With(args).WorkOn(wdir).ShellExecute();
  return 'rv:'+returnVal;
}

without the write to file the same response is returned… not sure where -1073741510 comes from though…

I am not getting the Pinglog.txt file created anywhere, and it executes and closes so fast, I cannot see what is going on. My return is 1.

If I don’t use /C ping, just a cmd window opens, no ping happens, and return is -1073741510.

hmmmm, I now get;

blank cmd window for couple of secs then closes
then get response 0
test file;

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=31ms TTL=50
Reply from 8.8.8.8: bytes=32 time=30ms TTL=50
Reply from 8.8.8.8: bytes=32 time=30ms TTL=50
Reply from 8.8.8.8: bytes=32 time=31ms TTL=50

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 30ms, Maximum = 31ms, Average = 30ms

Delete the text file. See if it really gets created. It could be from previous testing.

I am not getting anything other than quick flash of cmd window. Might be permissions, though I am Admin. Maybe Win 10 has to do with it?

Yep, same again.

Deleted txt and empties recycle bin.

function exec2() {
  var p = 'C:\\Windows\\System32\\';
  var f = 'cmd.exe';
  var args = '/c ping 8.8.8.8 > C:\\Pinglog.txt';
  var wdir = 'C:\\';
  var returnVal = file.Starter(p+f).With(args).WorkOn(wdir).ShellExecute();
  return 'rv:'+returnVal;
}

Gives the same;

function exec() {
  var p = 'C:\\Windows\\System32\\';
  var f = 'cmd.exe';
  var args = 'ping 8.8.8.8';
  var wdir = 'C:\\';
  var returnVal = file.Starter(p+f).With(args).WorkOn(wdir).ShellExecute();
  return 'rv:'+returnVal;
}

Gives me cmd window with C:> normal enty when opening whihc doesnt close and then when closing get the -1073741510 response value

In theory your;

function exec2() {
  var p = 'C:\\Windows\\System32\\';
  var f = 'cmd.exe';
  var args = '/c ping 8.8.8.8 > C:\\Pinglog.txt';
  var wdir = 'C:\\';
  var returnVal = file.Starter(p+f).With(args).WorkOn(wdir).ShellExecute();
  return 'rv:'+returnVal;
}

Would work if I pull from the test file… although would need to delay the reading for ping to execute…