×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to know the user have an online internet ?
2

How to know the user have an online internet ?

How to know the user have an online internet ?

(OP)
Hi every body.
I want to know the user that use my application ,have a online Internet ? Is there any function in vfp for this porpose ?
if NO , can I check it in someway , this is necessary for me , Do you have any IDEA ?
i am very pleased for hear some help
thank you

RE: How to know the user have an online internet ?

Declare SHORT InternetGetConnectedState In wininet.Dll;
	INTEGER @lpdwFlags, Integer dwReserved
?displayState()
Procedure  displayState
Local lConnected
lConnected = .F.
lpdwFlags = 0
If InternetGetConnectedState (@lpdwFlags, 0) = 1
	lConnected = .T.
Endif
Return lConnected
Endproc
 



If you want to get the best response to a question, please check out FAQ184-2483: How to get the best response from the forum first.

RE: How to know the user have an online internet ?

I don't like to open up a can of worms, but I'll do. With a benefit of enabling to know a lot more than just the Internet connection state and with an outlook to be able to enhance VFPs CreateObject capabilities.

First of all, why? I faintly remembered InternetGetConnectedState had to do with the dial-up sate of a computer, and since we're away from that and in the era of mostly permanent DSL Modem or other internet connections, I thought I look up if there's a catch to using InternetGetConnectedState.

InternetGetConnectedState documentation says: Note Using this API is not recommended, use the INetworkListManager::GetConnectivity method instead.

So I began digging. To cut to the chase, here's how you can follow that recommendation and make use of the NetworkListManager in VFP:

CODE

Clear 
? ComputerIsConnectedToInternet()

Function ComputerIsConnectedToInternet()
   #Define CLSID_NetworkListManager "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"
   #Define IID_INetworkListManager  "{DCB00000-570F-4A9B-8D69-199FDBA5723B}"

   Local lcIsConnectedToInternet, loNetworkListManager

   Try 
      loNetworkListManager = CreateObjectEx(CLSID_NetworkListManager,'',IID_INetworkListManager)
      lcIsConnectedToInternet = Iif(loNetworkListManager.IsConnectedToInternet,"Yes","No")
   Catch
      lcIsConnectedToInternet = "Unknown"
   EndTry       
   
   Return lcIsConnectedToInternet
EndFunc 

I put the CreateObjectEx in a Try..Catch block, as it's an interface needing Vista or later Windows, so when it doesn't work the status is unknown. You could change it to using the logical values .T., .F. and .NULL. instead. And, of course, the catch block could revert back to using InternetGetConnectedState, it should only be necessary on XP and that's a dying species. I know POS systems still make use of it.

You can get more info. Just a short outlook, what else the NetworkListManager can show you:

CODE

=ListNetworks()

Procedure ListNetworks()
   #Define CLSID_NetworkListManager "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"
   #Define IID_INetworkListManager  "{DCB00000-570F-4A9B-8D69-199FDBA5723B}"

   Local lcIsConnectedToInternet, loNetworkListManager

   loNetworkListManager = CreateObjectEx(CLSID_NetworkListManager,'',IID_INetworkListManager)
   
   For Each loNetwork in loNetworkListManager.GetNetworks(3)
       ? "Network:", loNetWork.GetName(), Iif(loNetWork.IsConnected,"Connected","Not Connected"), Iif(loNetWork.IsConnectedToInternet,"(Internet)","")
   EndFor 
EndProc 

There's more to it, not only regarding NetworkListManager. Before using CreateObjectEx with the CLSID and IIDs I came across a lot of things I'll just list here:
Creating the NetworkListManager in In C++: https://msdn.microsoft.com/de-de/windows/desktop/a...
Creating the NetworkListManager in Alaska xbase++: http://news.alaska-software.com/readmessage?id=%3C14696f1f$2f06d883$e308a@news.alaska-software.com%3E&group=public.xbase%2B%2B.activex
Using CoCreateInstance in VFP: https://blogs.msdn.microsoft.com/calvin_hsia/2005/...

And then I remembered CreateObjectEx also has the CLSID (Class ID) and IID (Interface ID) parameters you need to get at such classes. But Calvin Hsia's article is useful nevertheless, it teaches a bit about COM usage better than VFPs simpler CreateObject() can do. At the time he wrote that VFP7 was extended in DECLARE providing a type "OBJECT", that enables getting an object from such a DECLARE DLL parameter being an address of an object. And VFP7 also didn't have CreateObjectEx(). Nevertheless, CoCreateInstance has some more parameters CreateObjectEx() lacks and so in other cases, you might gain something from that.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: How to know the user have an online internet ?

Olaf
I have tested what I posted before posting it, and if my WI-FI is on I get .T., if I turn it off I get a .F..



If you want to get the best response to a question, please check out FAQ184-2483: How to get the best response from the forum first.

RE: How to know the user have an online internet ?

I don't doubt that, Mike.

There's still that recommendation from Microsoft.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close