Re: Win32_NetworkConnection returns empty
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 10/26/04
- Next message: SumYungGuy: "GetSecurityDescriptor and Access Denied"
- Previous message: Dharani Babu S: "Win32_NetworkConnection returns empty"
- In reply to: Dharani Babu S: "Win32_NetworkConnection returns empty"
- Next in thread: Dharani Babu S: "Re: Win32_NetworkConnection returns empty"
- Reply: Dharani Babu S: "Re: Win32_NetworkConnection returns empty"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 26 Oct 2004 17:04:23 +0200
Dharani Babu S wrote:
> Hi all
> I am trying to find out whether a system is connected to network or not . So
> I thought ConnectionState property of Win32_NetworkConnection will give me
> the status of the system . But when I executed the ExecQuery( "select * from
> Win32_NetworkConnection " or "select ConnectionState from
> Win32_NetworkConnection ") it returns with no values . It does not return
> NULL also . Could anyone point tome the problem ? and is
> Win32_NetworkConnection the right class to find out the presence of a system
> in a network ?
Hi
Note that Win32_NetworkConnection only represents mapped drives, and
not if your system is connected to a network or not.
Some alternatives maybe:
Windows XP and beyond:
'--------------------8<----------------------
sComputerName = "." ' Use "." for local computer
Set oWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
For Each oAdapter In oWMIService.InstancesOf("Win32_NetworkAdapter")
If oAdapter.NetConnectionStatus = 2 Then
WScript.Echo "Network connection """ & oAdapter.NetConnectionID _
& """ is connected"
End If
Next
'--------------------8<----------------------
Windows 2000 and beyond:
'--------------------8<----------------------
sComputerName = "." ' Use "." for local computer
Set oWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\wmi")
Set oNicCollection = oWMIService.InstancesOf("MSNdis_MediaConnectStatus")
For Each oNic In oNicCollection
If oNic.NdisMediaConnectStatus = 0 Then
sNicStatus = "connected"
Elseif oNic.NdisMediaConnectStatus = 1 Then
sNicStatus = "disconnected"
Else
sNicStatus = "unknown"
End If
WScript.Echo "Status of " & oNic.InstanceName & ": " & sNicStatus
Next
'--------------------8<----------------------
-- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx
- Next message: SumYungGuy: "GetSecurityDescriptor and Access Denied"
- Previous message: Dharani Babu S: "Win32_NetworkConnection returns empty"
- In reply to: Dharani Babu S: "Win32_NetworkConnection returns empty"
- Next in thread: Dharani Babu S: "Re: Win32_NetworkConnection returns empty"
- Reply: Dharani Babu S: "Re: Win32_NetworkConnection returns empty"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|