Re: Win32_NetworkConnection returns empty

From: Dharani Babu S (dharanibabus_at_hotmail.com.(donotspam))
Date: 10/27/04


Date: Tue, 26 Oct 2004 20:31:01 -0700

Thanks for your reply.
I am using IPEnabled property of Win32_NetworkAdapterConfiguration to find
outthe connectivity to network . Your alternatives are for 2000 , XP and
above but Win32_NetworkAdapterConfiguration.IPEnabled works fine for NT and
2000 . Is it a valid alternative ?

"Torgeir Bakken (MVP)" wrote:

> 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
>



Relevant Pages

  • Re: restrict software installation
    ... Preventing users from executing stuff on their home directory and in ... Is there some similar principle in Windows? ... emphasis on 'minimize network transfers'. ... Perhaps you can control this via some scripting stuff? ...
    (Focus-Microsoft)
  • Re: restrict software installation
    ... > Is there some similar principle in Windows? ... > emphasis on 'minimize network transfers'. ... > Perhaps you can control this via some scripting stuff? ... > just about any scripting language there is (XML objects if everything ...
    (Focus-Microsoft)
  • Re: Windows Firewall wont load
    ... I have exactly the same problem as rlittleson as in the Windows ... > newsgroup because my dialup network settings had vanished and a guy ... > Notice that the logon account is set to a NT/User account under the RPC ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Need to remove old computers
    ... I've just inherited a Windows 2K3 network and there are more ... > computers listed in Active Directory than there are computers. ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windows.server.active_directory)
  • Re: SCAN.EXE - McAfee AntiVirus Software
    ... I have two quick questions about McAfee AntiVirus's SCAN.EXE: ... small network is providing a tiny bit of resistance. ... wide variety of scripting tasks on all network ... > McAfee workstations and for McAfee Configuration Management. ...
    (microsoft.public.security.virus)