Link to home
Start Free TrialLog in
Avatar of JimKilby
JimKilby

asked on

Code to prevent network installation

I have built a VB5 program that I want to distribute but I do not want it to install on a network. Is there any code that can be written that checks for a network card? Or maybe multiple hard drives? Or both?

Thanks.
Jim Kilby
Avatar of web_crusher
web_crusher

of course , just what you have to do is reading the proper
section of the registry (windows registry)
its all written there - network card - hardware section

if you would like to get a code to read from the registry just
tell me about it and of course award me with your points
and excelent answer!
Avatar of JimKilby

ASKER

I am in need of the code.
I am in need of the code. To me this is a difficult question and working code is certainly worth an "A" and 200 points.
ASKER CERTIFIED SOLUTION
Avatar of shannon_cogan
shannon_cogan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
here is the code of reading a registry:
this code is reading the system information - all yo have to do is change the section to the network information - thats all - a++ grade please!!!


on a module section ' checkreg.bas
Option Explicit

' Reg Key Security Options...
Const READ_CONTROL = &H20000
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE + _
                       KEY_CREATE_SUB_KEY + KEY_ENUMERATE_SUB_KEYS + _
                       KEY_NOTIFY + KEY_CREATE_LINK + READ_CONTROL
                     
' Reg Key ROOT Types...
Const HKEY_LOCAL_MACHINE = &H80000002
Const ERROR_SUCCESS = 0
Const REG_SZ = 1                         ' Unicode nul terminated string
Const REG_DWORD = 4                      ' 32-bit number

Const gREGKEYSYSINFOLOC = "SOFTWARE\Microsoft\Windows" ' specify the reg path
Const gREGVALSYSINFOLOC = "CurrentVersion" ' section
Const gREGKEYSYSINFO = "SOFTWARE\Microsoft\Windows\CurrentVersion"

'fields to check under the current version section

Const gREGVALUSERINFO = "RegisteredOwner"
Const gREGVALSYSTEMROOTINFO = "SystemRoot"
Const gREGVALVERSIONNUMBERINFO = "VersionNumber"
Const gREGVALPRODUCTIDINFO = "ProductId"
Const gREGVALORGANIZATIONINFO = "RegisteredOrganization"


Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long

Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Global usernamenew
Global serialnumbernew
Global licencenew
Global currentcodenew
Global newcodenew
Dim St$, A%
Global Sysuser As String
Global SysRoot As String
Global SysVersion As String
Global SysProductId As String
Global SysOrganization As String


Public Function GetKeyValue(KeyRoot As Long, KeyName As String, SubKeyRef As String, ByRef KeyVal As String) As Boolean
    Dim i As Long                                           ' Loop Counter
    Dim rc As Long                                          ' Return Code
    Dim hKey As Long                                        ' Handle To An Open Registry Key
    Dim hDepth As Long                                      '
    Dim KeyValType As Long                                  ' Data Type Of A Registry Key
    Dim tmpVal As String                                    ' Tempory Storage For A Registry Key Value
    Dim KeyValSize As Long                                  ' Size Of Registry Key Variable
    '------------------------------------------------------------
    ' Open RegKey Under KeyRoot {HKEY_LOCAL_MACHINE...}
    '------------------------------------------------------------
    rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey) ' Open Registry Key
   
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError          ' Handle Error...
   
    tmpVal = String$(1024, 0)                             ' Allocate Variable Space
    KeyValSize = 1024                                       ' Mark Variable Size
   
    '------------------------------------------------------------
    ' Retrieve Registry Key Value...
    '------------------------------------------------------------
    rc = RegQueryValueEx(hKey, SubKeyRef, 0, _
                         KeyValType, tmpVal, KeyValSize)    ' Get/Create Key Value
                       
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError          ' Handle Errors
   
    If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then           ' Win95 Adds Null Terminated String...
        tmpVal = Left(tmpVal, KeyValSize - 1)               ' Null Found, Extract From String
    Else                                                    ' WinNT Does NOT Null Terminate String...
        tmpVal = Left(tmpVal, KeyValSize)                   ' Null Not Found, Extract String Only
    End If
    '------------------------------------------------------------
    ' Determine Key Value Type For Conversion...
    '------------------------------------------------------------
    Select Case KeyValType                                  ' Search Data Types...
    Case REG_SZ                                             ' String Registry Key Data Type
        KeyVal = tmpVal                                     ' Copy String Value
    Case REG_DWORD                                          ' Double Word Registry Key Data Type
        For i = Len(tmpVal) To 1 Step -1                    ' Convert Each Bit
            KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1)))   ' Build Value Char. By Char.
        Next
        KeyVal = Format$("&h" + KeyVal)                     ' Convert Double Word To String
    End Select
   
    GetKeyValue = True                                      ' Return Success
    rc = RegCloseKey(hKey)                                  ' Close Registry Key
    Exit Function                                           ' Exit
   
GetKeyError:      ' Cleanup After An Error Has Occured...
    KeyVal = ""                                             ' Set Return Val To Empty String
    GetKeyValue = False                                     ' Return Failure
    rc = RegCloseKey(hKey)                                  ' Close Registry Key
End Function

Public Sub CheckReg()


 If Not GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFO, gREGVALUSERINFO, Sysuser) Then MsgBox (Sysuser)
 If Not GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFO, gREGVALSYSTEMROOTINFO, SysRoot) Then MsgBox (SysRoot)
 If Not GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFO, gREGVALVERSIONNUMBERINFO, SysVersion) Then MsgBox (SysVersion)
 If Not GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFO, gREGVALPRODUCTIDINFO, SysProductId) Then MsgBox (SysProductId)
 If Not GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFO, gREGVALORGANIZATIONINFO, SysOrganization) Then MsgBox (SysOrganization)
 
 End Sub

I must say - i'm not usually put this much code - i want the members to be able
to think ahead without searching for the simple way - the code!!!

grade me with a++ please
Web_Crsher
i havent realised im writting a comment
please test it and reject the other stupid answers and wait for an answer from me
than jst grade me a++

Thanks
A++ thanks
hey jimkilby - you have graded shanon's answers
as a++ - what answer you've used - my'n or her's?????
I was trying to give web_crusher the a++ grade. Her's wasn't much help. Guess I need help in giving a grade. How do I change it?
please ask shanon to ask a question at the same points and on the title write it to web_cursher - and then grade me with a++
this way we all get better grades - even shanon - the a++
gives the expert more points than the ones he offered!
Shanon

Please ask a question at the 200 points and on the title write it to web_crusher then grade it with a++.

I made a mistake where I posted web_crusher's grade and am trying to correct it.