The easy way to do this is to retrieve the local IP address. If it's in your range you know the computer is online. Most methods to get the local IP only give you the first one registered. This means if someone is connecting over a VPN the IP address you get won't tell you anything about access to the corporate network. You need to enumerate all the IP interfaces that are connected and figure out if one is connected to the LAN.
Now, how do you go about this? Well, you could go the low tech route and Shell("ipconfig /all > ip.txt") and then parse it. That's certainly doable, but then you have to make sure the user can write to the folder where you put the file, and be sure you clean it up. It gets messy. You could use Windows API calls, such as GetAdaptersInfo, but that doesn't tell you if the connection is actually active, just that an IP address is assigned (think disabled NIC's with static IP's), so then you need to add on a couple more API calls to verify whether each interface is enabled. Bleh.
Enter WMI. Microsoft started shipping Windows Management Instrumentation (WMI) with Windows 2000, and it's also in Windows XP. Alongside WMI is Windows Scripting Host (WSH), which is an object wrapper around a lot of really cool functionality that you had to delve into obscure API calls to get previously. Using WMI and WSH you can easily get all the adapters in a computer, determine if they are active, and know with certainty what the user is connected to.
provided by Julian Robichaux at nsftools.com.