Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deploying to a multi-user machine

Status
Not open for further replies.

briggsy79

Programmer
Feb 23, 2001
68
0
0
SE
Hi all.
I was wondering how i can install a program under a WinNT machine to all profiles, or more to the point to a local machine. Also how can i write to the registry not under 'HKEY current user'. Becuase at the moment I have a program that needs to be installed to every users profile on every computer, before anyone can use it.

Do I just need to be logged in as an Administrator?, or just install it to the C drive?
And once again how do i write to the registry not under 'HKEY current user'?

Thanks


-David
 
David,

Here is some code to read the registry under HKEY_LOCAL_MACHINE. I hope you find it useful.
------------------------------------
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



Public Function GetKeyValue(KeyRoot As Long, KeyName As String, SubKeyRef As String, ByRef KeyVal As String) As Boolean
On Error GoTo Error_Routine

1 Dim i As Long ' Loop Counter
2 Dim rc As Long ' Return Code
3 Dim hKey As Long ' Handle To An Open Registry Key
4 Dim hDepth As Long '
5 Dim KeyValType As Long ' Data Type Of A Registry Key
6 Dim tmpVal As String ' Tempory Storage For A Registry Key Value
7 Dim KeyValSize As Long ' Size Of Registry Key Variable
'------------------------------------------------------------
' Open RegKey Under KeyRoot {HKEY_LOCAL_MACHINE...}
'------------------------------------------------------------
8 rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey) ' Open Registry Key

9 If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError ' Handle Error...

10 tmpVal = String$(1024, 0) ' Allocate Variable Space
11 KeyValSize = 1024 ' Mark Variable Size

'------------------------------------------------------------
' Retrieve Registry Key Value...
'------------------------------------------------------------
12 rc = RegQueryValueEx(hKey, SubKeyRef, 0, _
KeyValType, tmpVal, KeyValSize) ' Get/Create Key Value

13 If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError ' Handle Errors

14 If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then ' Win95 Adds Null Terminated String...
15 tmpVal = Left(tmpVal, KeyValSize - 1) ' Null Found, Extract From String
16 Else ' WinNT Does NOT Null Terminate String...
17 tmpVal = Left(tmpVal, KeyValSize) ' Null Not Found, Extract String Only
18 End If
'------------------------------------------------------------
' Determine Key Value Type For Conversion...
'------------------------------------------------------------
19 Select Case KeyValType ' Search Data Types...
Case REG_SZ ' String Registry Key Data Type
20 KeyVal = tmpVal ' Copy String Value
21 Case REG_DWORD ' Double Word Registry Key Data Type
22 For i = Len(tmpVal) To 1 Step -1 ' Convert Each Bit
23 KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1))) ' Build Value Char. By Char.
24 Next
25 KeyVal = Format$(&quot;&h&quot; + KeyVal) ' Convert Double Word To String
26 End Select

27 GetKeyValue = True ' Return Success
28 rc = RegCloseKey(hKey) ' Close Registry Key
29 Exit Function ' Exit

30 GetKeyError: ' Cleanup After An Error Has Occured...
31 KeyVal = &quot;&quot; ' Set Return Val To Empty String
32 GetKeyValue = False ' Return Failure
33 rc = RegCloseKey(hKey) ' Close Registry Key

Exit_Routine:
Exit Function
Error_Routine:
Debug.Assert False
Err.Raise Err.Number, &quot;frmAbout.GetKeyValue(&quot; & Erl & &quot;):&quot; & Err.Source, Err.Description
End Function
----------------------------------------
Glyn.
 
Thanks
Any idea on how to adapt this to a saving of values to the registry?

Sorry im a bit slow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top