[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Network scanner

Posted on 2001-06-25
10
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

649 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