Francisco H Tapia
my.lists at verizon.net
Tue Sep 16 15:35:06 CDT 2003
Watch for the line wrap... note finding the network has not worked on a 9x machine. Option Explicit '-------------------------------------------------------------------- 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam at allapi.net Const RPC_S_OK = &H0 Const RPC_S_UUID_LOCAL_ONLY = &H720 Const RPC_S_UUID_NO_ADDRESS = &H6CB Private Type UUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type Private Declare Function UuidCreate Lib "rpcrt4" (lpUUID As UUID) As Long Private Declare Function UuidToString Lib "rpcrt4" Alias "UuidToStringA" (lpUUID As UUID, lpUUIDString As Long) As Long Private Declare Function RpcStringFree Lib "rpcrt4" Alias "RpcStringFreeA" (lpUUIDString As Long) As Long Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cBytes As Long) '-------------------------------------------------------------------- 'Use the following to get UserName Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 'Use the following to get PC Name Private Const MAX_COMPUTERNAME_LENGTH As Long = 31 Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long 'Thanks to: Http://www.allapi.net 'To run this program, you must set the startup object to 'Sub Main' 'You can do this by going to Project->Project Properties->Startup Object 'In a module Private Const PLATFORM_ID_DOS = 300 Private Const PLATFORM_ID_OS2 = 400 Private Const PLATFORM_ID_NT = 500 Private Const PLATFORM_ID_OSF = 600 Private Const PLATFORM_ID_VMS = 700 Private Type WKSTA_INFO_102 wki100_platform_id As Long pwki100_computername As Long pwki100_langroup As Long wki100_ver_major As Long wki100_ver_minor As Long pwki102_lanroot As Long wki102_logged_on_users As Long End Type Declare Function NetWkstaGetInfo Lib "netapi32" (ByVal servername As String, ByVal level As Long, lpBuf As Any) As Long Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam at allapi.net Function fOSPCName() As String Dim dwLen As Long Dim strString As String 'Create a buffer dwLen = MAX_COMPUTERNAME_LENGTH + 1 strString = String(dwLen, "X") 'Get the computer name GetComputerName strString, dwLen 'get only the actual data strString = Left(strString, dwLen) 'Show the computer name fOSPCName = strString End Function Function fOSDomainName() As String 'code submitted by Andreas Linnemann (ALinnemann at gmx.de) Dim pWrkInfo As Long, WrkInfo(0) As WKSTA_INFO_102, lResult As Long, strComputername As String 'make sure you replace the value of the following constant 'with a valid computer name from your LAN strComputername = fOSPCName() If CheckOS4NT = True Then lResult = NetWkstaGetInfo(StrConv("\\" & strComputername, vbUnicode), 102, pWrkInfo) If lResult = 0 Then Dim cname As String cname = String$(255, 0) CopyMemory WrkInfo(0), ByVal pWrkInfo, ByVal Len(WrkInfo(0)) CopyMemory ByVal cname, ByVal WrkInfo(0).pwki100_langroup, ByVal 255 fOSDomainName = StripTerminator(StrConv(cname, vbFromUnicode)) NetApiBufferFree ByVal pWrkInfo End If Else 'Couldn't determine Domain on 9x fOSDomainName = fOSPCName() End If End Function MartyConnelly wrote: > WMI API should have it. Installed on WinXP and Win2000, have to install > from MS for Win9x > Windows Management Instrumentation, You could hunt around here for > sample code. > > http://www.activxperts.com/activmonitor/windowsmanagement/wmisamples/ > > > example > The Win32_NetworkClient WMI class represents a network client on a > Windows system. Any computer system on the network with a client > relationship to the system is a descendent (or member) of this class > (for example, a computer running Windows 2000 Workstation or Windows 98 > that is part of a Windows 2000 domain). > > On Error Resume Next > strComputer = "." > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") > Set colItems = objWMIService.ExecQuery("Select * from > Win32_NetworkClient",,48) > For Each objItem in colItems > Wscript.Echo "Caption: " & objItem.Caption > Wscript.Echo "Description: " & objItem.Description > Wscript.Echo "InstallDate: " & objItem.InstallDate > Wscript.Echo "Manufacturer: " & objItem.Manufacturer > Wscript.Echo "Name: " & objItem.Name > Wscript.Echo "Status: " & objItem.Status > Next > > John Skolits wrote: > >> I need to be able to detect the name of what local network I am on. >> >> Anyone have an API call for this? >> >> John Skolits -- -Francisco