Solved

Network scanner

Posted on 2001-06-25
10
152 Views
Last Modified: 2010-05-02
Can someone point me in the right direction?  I need to develop an application that will scan our network and return all of the computers on the network.  This part I can do.  What I need help with is returning the computer name and operating system for each computer.  I also need to access the registry on each of those machines so that I can scan for the installed applications on each machine.
0
Comment
Question by:johnczimm
10 Comments
 
LVL 10

Expert Comment

by:RichardCorrie
ID: 6225586
Have you rried SMS server or (don't tell anyone I told you) BackOrifice

Richard
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6226336
Hearing...
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 6226861
http://www.mvps.org/vbnet/code/network/netserverenumver.htm

Is an excellent sample which shows how to get the computers on the network and their operating systems.

The following is an example which shows how you can access the registry on a remote server. You would use it like this:

MsgBox RemoteReg("NameOfServer","KeyPathExcluding HKLM etc", "Item Name")

This example code only looks in HKEY_LOCAL_MACHINE. You could easily modify it to be more flexible.

The following code should be placed in a module

Global Const REG_SZ As Long = 1
Global Const REG_DWORD As Long = 4

Global Const HKEY_CLASSES_ROOT = &H80000000
Global Const HKEY_CURRENT_USER = &H80000001
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const HKEY_USERS = &H80000003

Global Const ERROR_NONE = 0
Global Const ERROR_BADDB = 1
Global Const ERROR_BADKEY = 2
Global Const ERROR_CANTOPEN = 3
Global Const ERROR_CANTREAD = 4
Global Const ERROR_CANTWRITE = 5
Global Const ERROR_OUTOFMEMORY = 6
Global Const ERROR_INVALID_PARAMETER = 7
Global Const ERROR_ACCESS_DENIED = 8
Global Const ERROR_INVALID_PARAMETERS = 87
Global Const ERROR_NO_MORE_ITEMS = 259

Global Const KEY_ALL_ACCESS = &H3F

Global Const REG_OPTION_NON_VOLATILE = 0

Declare Function RegConnectRegistry Lib "advapi32.dll" Alias _
"RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, _
phkResult As Long) As Long

Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long

Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
"RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
As Long, phkResult As Long, lpdwDisposition As Long) As Long

Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
Long) As Long

Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
As String, lpcbData As Long) As Long

Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
String, ByVal lpReserved As Long, lpType As Long, lpData As _
Long, lpcbData As Long) As Long

Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
As Long, lpcbData As Long) As Long

Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
String, ByVal cbData As Long) As Long

Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
ByVal cbData As Long) As Long
 
 Public Function SetValueEx(ByVal hKey As Long, sValueName As String, _
                            lType As Long, vValue As Variant) As Long
   Dim lValue As Long
   Dim sValue As String
   Select Case lType
   
       Case REG_SZ
           sValue = vValue & Chr$(0)
           SetValueEx = RegSetValueExString(hKey, sValueName, 0&, _
                                            lType, sValue, Len(sValue))
       Case REG_DWORD
           lValue = vValue
           SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, _
                        lType, lValue, 4)
       End Select
End Function

Function QueryValueEx(ByVal lhkey As Long, ByVal szValueName As String, _
                     vValue As Variant) As Long
   Dim cch As Long
   Dim lrc As Long
   Dim lType As Long
   Dim lValue As Long
   Dim sValue As String

   On Error GoTo QueryValueExError

   ' Determine the size and type of data to be read
   lrc = RegQueryValueExNULL(lhkey, szValueName, 0&, lType, 0&, cch)
   'If lrc <> ERROR_NONE Then Error 5

   Select Case lType
       ' For strings
       Case REG_SZ:
           sValue = String(cch, 0)
           lrc = RegQueryValueExString(lhkey, szValueName, 0&, lType, sValue, cch)
           If lrc = ERROR_NONE Then
               vValue = Left$(sValue, cch)
           Else
               vValue = Empty
           End If
       ' For DWORDS
       Case REG_DWORD:
           lrc = RegQueryValueExLong(lhkey, szValueName, 0&, lType, lValue, cch)
           If lrc = ERROR_NONE Then vValue = lValue
       Case Else
           'all other data types not supported
           lrc = -1
   End Select

QueryValueExExit:
   QueryValueEx = lrc
   Exit Function
QueryValueExError:
   Resume QueryValueExExit
   
End Function

Public Sub SetKeyValue(sKeyName As String, sValueName As String, _
vValueSetting As Variant, lValueType As Long)
   Dim lRetVal As Long         'result of the SetValueEx function
   Dim hKey As Long         'handle of open key

   'open the specified key
   lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, _
                          KEY_ALL_ACCESS, hKey)
   lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
   RegCloseKey (hKey)
End Sub

Public Function RemoteReg(txtRemMachName As String, txtKeyName As String, txtKeyValue As String)
   
   Dim lRetVal As Long         'used to hold return value for all API calls
   
   Dim sRemMachName As String  'used by RegConnectRegistry
   Dim lTopLevelKey As Long    'used by RegConnectRegistry
   Dim lHKeyhandle As Long     'used by RegConnectRegistry & RegOpenKeyEx
   
   Dim sKeyName As String      'used by RegOpenKeyEx
   Dim lhkey As Long           'used by RegOpenKeyEx & RegQueryValueEx & RegCloseKey
   
   Dim sValueName As String    'used by RegQueryValueEx
   Dim vValue As String        'used by RegQueryValueEx
   
   sRemMachName = txtRemMachName         'Gets user entered name of remote machine
   'sKeyName = "Software\Microsoft\Windows NT\CurrentVersion\WinLogon" 'Gets user entered subkey name"
   'sValueName = "DefaultUserName"        'Gets user entered value name
   'sKeyName = "System\CurrentControlSet\Control" 'Gets user entered subkey name"
   'sValueName = "CurrentUser"        'Gets user entered value name
   sKeyName = txtKeyName
   sValueName = txtKeyValue
   
   lTopLevelKey = HKEY_LOCAL_MACHINE
   DoEvents
   'Get handle of a top level registry key on remote machine
   lRetVal = RegConnectRegistry(sRemMachName, lTopLevelKey, lHKeyhandle)
   
   If lRetVal = 0 Then
   
       'Get handle of the key which contains the value you need to check
       lRetVal = RegOpenKeyEx(lHKeyhandle, sKeyName, 0, KEY_ALL_ACCESS, lhkey)
       
       'Get the value
       lRetVal = QueryValueEx(lhkey, sValueName, vValue)
       
       'Always a good idea to clean up
       RegCloseKey (lhkey)
       
       If lRetVal = 0 Then    'QueryValueEx succeeded
           RemoteReg = vValue
       Else
           RemoteReg = "Unobtainable"
       End If
   Else
       RemoteReg = "Inaccessible"
   End If
End Function
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6228015
fyi,

If you want to track the progress of a question, but have no input for the issue, there is a button at the bottom of the form - 'subscribe'.

Clicking that will subscribe you to be notified of subsequent activity for that question.
0
 
LVL 1

Author Comment

by:johnczimm
ID: 6228766
Tim,
This looks good.  Now one more question.  I need to loop through the keys under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" to get the DisplayName.  Do you know how to do this?

Thanks.  
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6229092
johnczimm, please give the points to Tim and ask a new question. He did a great job, don't you think so?
0
 
LVL 1

Author Comment

by:johnczimm
ID: 6229132
I do agree.  I thought if he could answer this quick, I'd increase the points.

0
 
LVL 1

Author Comment

by:johnczimm
ID: 6229181
I do agree.  I thought if he could answer this quick, I'd increase the points.

0
 
LVL 1

Author Comment

by:johnczimm
ID: 6229271
For info on 'Retrieve all values under a Registry key' you can take a look at this:
http://www.vb2themax.com/Item.asp?PageID=CodeBank&ID=242

Thanks for the help.

JOHN
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6229405
NICE!
but let others EE make their day ;)
Cheers
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now