Solved

Security info in Win Registry

Posted on 2003-11-26
2
373 Views
Last Modified: 2010-04-17
I have to design an application that retrieves security-related information from the Windows Registry. I was wondering what is the best language to use, I am most competent in VB 6 but would welcome your suggestions. Some possible benefits and disadvantages of languages would also prove to be useful.

Thanks
0
Comment
Question by:kingbailey2000
2 Comments
 
LVL 10

Accepted Solution

by:
ADSaunders earned 50 total points
ID: 9824577
Hi kingbailey2000,
Doesn't really matter which language you use, as you'll need to program for the advapi32. This api contains calls for registry access.
The following is a module that I use for registry access in VB6 just cut & paste into something like ModRegistry.bas file, then add it to your project.

I'm not claiming that this is all my work, probably some is (if not most) but like a lot of my code, it's garnered from all corners of the Internet. Many thenks to all who contributed, knowingly or unknowingly.
--------------- cut ---------------------------
Public 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
Public Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" _
                       (ByVal hKey As Long) As Long
Public Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" _
                       (ByVal hKey As Long, _
                        ByVal dwIndex As Long, _
                        ByVal lpValueName As String, _
                        lpcbValueName As Long, _
                        ByVal lpReserved As Long, _
                        lpType As Long, _
                        lpData As Byte, _
                        lpcbData As Long) As Long
Public Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
                       (ByVal hKey As Long, _
                        ByVal lpValueName As String, _
                        ByVal lpReserved As Long, _
                        lpType As Long, _
                        lpData As Any, _
                        lpcbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public 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
Public 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
Public 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 Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" ( _
     ByVal hKey As Long, _
     ByVal lpSubKey As String) As Long
Public Declare Function GetLastError Lib "kernel32" () As Long

Public Enum ROOT_KEYS
     HKEY_ALL = &H0&
     HKEY_CLASSES_ROOT = &H80000000
     HKEY_CURRENT_USER = &H80000001
     HKEY_LOCAL_MACHINE = &H80000002
     HKEY_USERS = &H80000003
     HKEY_PERFORMANCE_DATA = &H80000004
     HKEY_CURRENT_CONFIG = &H80000005
     HKEY_DYN_DATA = &H80000006
End Enum

Public Enum SEARCH_FLAGS
     KEY_NAME = 0
     VALUE_NAME = 1
     VALUE_VALUE = 2
     WHOLE_STRING = 4
End Enum

Public Enum FOUND_WHERE
     FOUND_IN_KEY_NAME
     FOUND_IN_VALUE_NAME
     FOUND_IN_VALUE_VALUE
End Enum

Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const SYNCHRONIZE = &H100000
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Public Const KEY_READ = &H20019  ' ((READ_CONTROL Or KEY_QUERY_VALUE Or
                          ' KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not
                          ' SYNCHRONIZE))

Public Const REG_OPTION_NON_VOLATILE = 0
Public Const ERROR_SUCCESS = 0&
Public Const ERROR_INVALID_HANDLR = 6&
Public Const ERROR_ACCESS_DENIED = 5&
Public Const ERROR_MORE_DATA = 234&
Public Const ERROR_NO_MORE_ITEMS = 259&

Public Const REG_NONE = 0
Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const REG_DWORD_LITTLE_ENDIAN = 4
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_LINK = 6
Public Const REG_MULTI_SZ = 7
Public Const REG_RESOURCE_LIST = 8
Public Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Public Const REG_RESOURCE_REQUIREMENTS_LIST = 10

Public Const MAX_KEY_SIZE = 256
Public Const MAX_VALUE_SIZE = 4096

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

Public Function TrimNull(startstr As String) As String
   Dim pos As Integer
   pos = InStr(startstr, Chr$(0))
   If pos Then
      TrimNull = Left$(startstr, pos - 1)
      Exit Function
   End If
   TrimNull = startstr
End Function

----------- end cut -----------------

Regards .. Alan
0
 

Expert Comment

by:amitm
ID: 9856491
As ADSaunders pointed, language is not a bar. But you must have database for the same which stores information {key, parameter, value} pairs to check whether machine is vulnerable or not.  
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Filename to be appended with DateTimeof Download 3 68
Query Syntax 17 50
Run AutoHotkey script directly from Notepad++ 5 129
print bytes of an integer 6 21
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

685 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