Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


franner

WPI - ConnectedToInternet() question

Recommended Posts

I have been trying to use ConnectedToInternet() and the suggestions in this thread:

But it doesn't work.

I have tried using both

ConnectedToInternet() and !ConnectedToInternet()

ConnectedToInternet()="true", ConnectedToInternet(true) and ConnectedToInternet("true

")

do I need to enable something in WPI to get it to work? In wpi > settings > general > allow check for internet connection is checked.

When I use !ConnectedToInternet() in exclude the item becomes gray with internet access and without internet access. It is as if wpi don't see my internet as it doesn't make any difference. Hope you can help me out solving this issue.

Btw. great work with WPI its really an awesome work.

Share this post


Link to post
Share on other sites

First, open WPI, hit Alt+G, My Computer tab, Internet Connection. What's it say?

Second, if is false, go into WPIScripts/api.js, near the top, uncomment the 2 internet check lines. Try again. I was having issues with it a while back.

Share this post


Link to post
Share on other sites

First, open WPI, hit Alt+G, My Computer tab, Internet Connection. What's it say?

it say's false

Second, if is false, go into WPIScripts/api.js, near the top, uncomment the 2 internet check lines. Try again. I was having issues with it a while back.

after uncommenting

//	if (AllowCheckForInternet)
// CheckForInternet();

I get:

Internet Connection - true

But if I unplug my ethernet cable and start wpi again it still say's Internet Connection - true.

if it does make any difference, i'm running windows 7 x64.

Edited by franner

Share this post


Link to post
Share on other sites

It's not a continuous check. It only does it at startup. And if doing a fresh install and your NIC driver is not installed before WPI starts, then, no internet.

Plug in cable, start WPI, check in Alt+G, unplug cable, hit F5, check again.

Share this post


Link to post
Share on other sites

I got it figured out after a few tries.

Thanks for your help.

Unfortunately it didn't solve the issue. Not when moving the folder or try again elsewhere on the PC.

Edited by franner

Share this post


Link to post
Share on other sites

It still doesn't work in virtual machine or in different folders.

Then I tried disable internet - disable LAN, unplug cable so no connection on main pc and in my virtual machine all connection is disconnected.

I started all over. Downloaded fresh, and nothing have been changed by me.

Copy it to my virtual machine.

Then I start wpi - internet connection - true

go to options - features - "allow check for internet connection" - alt+G - internet - false. But now when I close wpi and start it again and alt+G - internet connection - true. Here it should have said false instead.

Then I try edit api.js as u mentioned.

where I replace


// if (AllowCheckForInternet)
// CheckForInternet();

with this:


if (AllowCheckForInternet)
CheckForInternet();

start WPI - internet connection - true

I don't see why it don't work on my main or in virtual machine. I have now tried different combinations but none seems to work everytime.

If it works internet connection should say false and not true.

I have tried in windows xp and windows 7. I have restarted my PC and virtual machine and that doesn't help either. Its strange that it doesn't work the way it should :(

Edited by franner

Share this post


Link to post
Share on other sites

So WPI is kinda bugged ATM when checking connection to the internet?

I have tried on fresh install serial times now, with windows xp, windows 7 x32 and windows 7 x64. All have samme issue as mentioned above, maybe you can look into it or know a solution (I have tried what you said but it does not solve the issue unfortunately).

Share this post


Link to post
Share on other sites

Let's make sure we are both reading this the same: In Alt+G if Internet Connection is true, you are online; if false you are not. It does not mean "Allow for check for internet" is enabled/disabled. The Allow checkbox has to be checked for WPI to do an online check.

ConnectedToInternet() and !ConnectedToInternet() are what you want to use.

Share this post


Link to post
Share on other sites

Let's make sure we are both reading this the same: In Alt+G if Internet Connection is true, you are online; if false you are not. It does not mean "Allow for check for internet" is enabled/disabled. The Allow checkbox has to be checked for WPI to do an online check.

ConnectedToInternet() and !ConnectedToInternet() are what you want to use.

That is correct, that is the way I understand it too.

in alt+G if true = online

in alt+G if false = offline

The Allow checkbox has to be checked for WPI to do an online check.

WPI > options > features > "Allow check for Internet Connection".

This one needs to be checked right?

ConnectedToInternet() and !ConnectedToInternet() are what you want to use.

correct

Share this post


Link to post
Share on other sites

It's the javascript function that's broken (yes, I downloaded WPI out of curiosity, just to check that):


function CheckForInternet()
{
position="network.js";
whatfunc="CheckForInternet()";

var oExec = WshShell.Exec('ping -n 1 74.25.155.99');

while (oExec.Status == 0)
Pause(0,100);
var Output = oExec.StdOut.ReadAll() + oExec.StdErr.ReadAll();
// if (Output.search("Reply from") > -1) // Not always in English???
if (Output.search("74.25.155.99:") > -1)
ConnToNet=true;
else
ConnToNet=false;
}

Parsing text is always error prone, especially when running on OS with different locales (languages & formats), and that the utils can sometimes yield unexpected error messages. But here it just blindly pings 74.25.155.99 (an arris status page that isn't guaranteed to always be up or anything), and checks ping's output for that same text ("74.25.155.99"), which will pretty much always be present on the very first line it outputs, regardless of the connection state, so it'll always return true.

Unless you absolutely must be compatible with the ancient Win2k and earlier, the Win32_PingStatus WMI class is a far better/more robust approach, i.e. something like this:


var seriesOfTubes = false;
var wmiSvc = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var pingRes = wmiSvc.ExecQuery("Select * from Win32_PingStatus Where Address = 'google.com'");
var e = new Enumerator(pingRes);
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
if (p.StatusCode == 0)
seriesOfTubes = true;
}
WScript.Echo ((seriesoftubes) ? "We Has The Internets!" : "");

This just works, regardless of language/locale, and no unforeseen error messages will cause problems... so long as Google still exists.

Share this post


Link to post
Share on other sites

I'm not so used to javascript (I can read it and do some editing) but have no idea if I should code it up myself.

Could you explain which lines should be replaced in which files for this to work?

Thanks alot for your kindness to help and figuring this out. I am really greatful for both your help.

Edited by franner

Share this post


Link to post
Share on other sites

@CoffeeFiend: I had just updated the code code to something much simpler, getting rid of the text search. I never did like that, mainly because of different locales. I will be switching over to your method, though. Thanks for the code snippet.

@Franner: I sent you a beta copy of v8.2.0. Let me know the results.

Share this post


Link to post
Share on other sites

Could you explain which lines should be replaced in which files for this to work?

Well, if you want a drop-in replacement, you could replace this tidbit from network.js


function CheckForInternet()
{
position="network.js";
whatfunc="CheckForInternet()";

var oExec = WshShell.Exec('ping -n 1 74.25.155.99');

while (oExec.Status == 0)
Pause(0,100);
var Output = oExec.StdOut.ReadAll() + oExec.StdErr.ReadAll();
// if (Output.search("Reply from") > -1) // Not always in English???
if (Output.search("74.25.155.99:") > -1)
ConnToNet=true;
else
ConnToNet=false;
}

by:


function CheckForInternet()
{
position="network.js";
whatfunc="CheckForInternet()";

ConnToNet=false;
var wmiSvc = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var pingRes = wmiSvc.ExecQuery("Select * from Win32_PingStatus Where Address = 'google.com'");
var e = new Enumerator(pingRes);
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
if (p.StatusCode == 0)
ConnToNet=true;
}
}

Note: I have not tested this at all, so I would backup network.js first.

@CoffeeFiend: [snip] I will be switching over to your method, though. Thanks for the code snippet.

You're welcome. Hopefully the bits above will work as-is. Either ways, I was wondering why you guys haven't setup a public repository for WPI (not sure if you're using a revision control at all). CodePlex has free Mercurial hosting (otherwise I believe sourceforge and google code also do). It's free, it works great, it's super fast, and it's easy to use (using TortoiseHG and VisualHG). One could've forked WPI (not in the traditional "forking" sense), cloned it locally, made their changes, committed their work and pushed to it, then sent you a pull request to let you know that this available (then you can opt to merge the changes with your version). In a few simple clicks you could have had these changes integrated in your latest development version (without giving a 3rd party write access to your repository). It would allow people to contribute fairly easily (I'm not saying there would necessarily be a lot of contributors though), easily get any version of any file, see what's changed, etc.

Share this post


Link to post
Share on other sites

Thanks both of you CoffeeFiend and mritter you are great.

In the end what solve the issue for me was the one provided by CoffeeFiend. It works and does the jobs thanks for pointing it out.

Unfortunately the method by mritter worked great on windows xp, vista and windows 7 x86. But on my windows 7 x64 it didn't work for me (but on mritter's windows 7 x64 it worked). I don't know why, but this method by CoffeeFiend worked on all editions I tried (windows 7 x86, x64, windowws xp and vista when I tested it). Thank you both nontheless for solving this issue you are great!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...