Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




How To Take Registry Backup Using VB Code


Hi all,

Can any body help me how to take registry backup using VB code?
Because I want to make a program which will automatically take the registry backup.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Registry Backup
Does anyone know how to backup a registry key with VB and WSH? I basically want to do the registry export and save a key to a .reg file without any GUI interaction (ie: batch script).

I am able to use the WshShell.RegRead method to read default values, but I need the key and all its sub-keys and values. Any ideas?

thanks,
Kevin

Backup The Registry
Hello,

I would like to know if there is a way to wipe clean the system drive (C), reinstall windows, and copy in the old registry, so that the guids & other systems ids point to the installed apps on the other drives (which weren't erased)?

I haven't heard of any options besides ghosting, so any feedback is appreciated.

Cheers,

E

Registry Backup-Restore
Does anyone know, how to make a registry backup-restore program in visual basic?

Backup Registry Keys For App
I know how to backup a registry key from within regedit.exe but would like to know how I can go about creating a text file with the registry keys for my app and then saving that as backup.reg. (getting those keys from the registry)

Please advise if this can be done and if so, how would I go about doing this? Have searched VBF and found nothing that answers this question. Thanks in advance for any suggestions.

Creating A Registry Backup Under XP
I'm looking for code regarding how to backup the registry through VB under Windows XP.

Have searched high and low and came up with nothing... can anyone point me in the right direction?

Thanks,
- Cam

Can I Backup DB From VB Code?
Greetings!!!!

Can anyone pse assist me, I want to backup / restore my access db from vb

Can it be done?

They say.."I'm an embaresment to Nature"

My Code Backup To CD-R
Backing up my code/programs to CD-R stores them as "R" read only property files.
When I need them and re-install them back to my hard drive I have to manually change each and every one of them from "R" to "A" (Archive).
Any way around this I am using Easy CD creator and see no option to select to correct this.
What a pain!

Thanks Russ Dodge

Backup SQL Data Using VB Code.
Hi there,
I want to use VB code to make a backup file/restore, export/import data from SQL server Database. Can I do it, please give me an example, because I am developing an application and include backup function in it but I don't know how to do.
Thanks a lot for all your helps.

How To Backup Files Using VB6 Code
Hi all,

I'd like to run the following partial code by you to verify if the coding is correct. To give you some background information: this code should backup 4 files; connect to a cash register to copy the backup file to, if the first cash register (rg001) is not available then it should try to connect to the second cash register (rg002) and if that cash register is also not available then it should connect to cash register 3 (rg003). If none of the cash registers are available it should connect to a network drive and copy the backup file to the specified location on the network drive. I have created the following partial code to achieve this goal:


VB Code:
'zip the following files: database backup, PLUFILE and PRICENSTLogMessage "TRACE", "Starting zip of backup"Zipfiles "d:mssqlackupGTINRecovery.zip", sBackupfile & _         " c:
sb estdbasePLUFILE.idx" & _         " c:
sb estdbasePLUFILE.dat" & _         " c:
sb estdbasePRICEHST.idx" & _         " c:
sb estdbasePRICEHST.dat", 30, "", False, "d: emp"LogMessage "TRACE", "copying zip to register" 'get credentials to access rg001GetCredentialsFromXML "SDwjke&**jkFhjdhfg2g", "sHJHcvbb388h^2##@!@",APP_INI_FILE, "ClientConfig", _      "User", "Pwd", gsUser, gsPwdDim bMapWorked As BooleanDim sRegister As String sRegister = Left(sServer, 5) & "rg001"bMapWorked = modUtility.MapDrive("\" & sRegister & "c$", "", sRegister &"" & gsUser, gsPwd, False)If not bMapWorked Then 'get credentials to access rg002GetCredentialsFromXML "SDwjke&**jkFhjdhfg2g", "sHJHcvbb388h^2##@!@",APP_INI_FILE, "ClientConfig", _      "User", "Pwd", gsUser, gsPwdDim bMapWorked As BooleanDim sRegister As String sRegister = Left(sServer, 5) & "rg002"bMapWorked = modUtility.MapDrive("\" & sRegister & "c$", "", sRegister &"" & gsUser, gsPwd, False)   ElseIf not bMapWorked Then 'get credentials to access rg003GetCredentialsFromXML "SDwjke&**jkFhjdhfg2g", "sHJHcvbb388h^2##@!@",APP_INI_FILE, "ClientConfig", _      "User", "Pwd", gsUser, gsPwdDim bMapWorked As BooleanDim sRegister As String sRegister = Left(sServer, 5) & "rg003"bMapWorked = modUtility.MapDrive("\" & sRegister & "c$", "", sRegister &"" & gsUser, gsPwd, False)ElseIf not bMapWorked Then      Err.Raise 1, , "Cannot map drive to register for copy of DB backup"End If 'copy the zip file to register 1      objFSO.CopyFile "d:mssqlackupGTINRecovery.zip", "\" & Left(sServer, 5) &"rg001" & "c$
ecoveryGTINRecovery.zip", TrueIf not objFSO.CopyFile Then'copy the zip file to register 2      objFSO.CopyFile "d:mssqlackupGTINRecovery.zip", "\" & Left(sServer, 5) &"rg002" & "c$
ecoveryGTINRecovery.zip", TrueElseIf not objFSO.CopyFile Then  'copy the zip file to register 3      objFSO.CopyFile "d:mssqlackupGTINRecovery.zip", "\" & Left(sServer, 5) &"rg003" & "c$
ecoveryGTINRecovery.zip", True ElseIf not objFSO.CopyFile Then'copy the zip file to a mapped network drive      objFSO.CopyFile "d:mssqlackupGTINRecovery.zip", "\test-server-01Recovery"ElseIf not objFSO.CopyFile Then      Err.Raise 1, , "Unable to copy db backup to register or network drive"End If


If you have any ideas on whether this will work or whether this code can be improved please let me know.

Thanks very much in advance,

Richard

Code For Winzip Backup
<html><div style='background-color:'><P>Can anyone of you please the code for the below problem.</P>
<P>I needs to take backup of many Cobol, Sculptor(Both are Dos based) and VB files daily.</P>
<P>If I give a file name,  Program should create a Zip file which has all the selected files, Folder and Sub folders which I selelcted.</P>
<P>Regards</P>
<P>Thomas Mathew</P>
<P> </P></div><br clear=all><hr>Post Classifieds on MSN classifieds. <a href="http://g.msn.com/8HMAENIN/2734??PS=">Buy and Sell on MSN Classifieds.</a> </html>

Getting A Value For My Code From The Registry (Win32 Registry APIs)
There is a variable (SQL Connection String) in my code that I do not want hard-coded.
So I must find a way to be able to store that value in the Registry, and thus I need to import the Win32 Registry APIs (not sure what this implies) into my VB project and work from there.

Anyone able to give me some pointers or point me in the right direction? I do not have much experience with Win32 and APIs but I was told this is an easy task.

SQL Server Database Backup Code
I am developing a client-server vb6 application with SQL Server 2000 as the database. I want to have a backup/restore functionality in vb6 using SQL- DMO where i am backing up the database to a file on the server rather than a device.

However, what i need was to allow users to select the folder where he wish to place his file. I can use Common Dialog control, but the problem is the common dialog control shows the local file system, whereas i want to show the users the file structure of the machine where SQL Server is installed. I have no idea on how to go about it.

MSSQL: How To Catch Backup Progress In VB Code Using ADO
hi everybody,

any idea how to catch the progress in Backup of MSSQL DB so I can use a progress bar to simulate it

I use the following code:

Connection.Execute "Backup Database Z to disk=c: empzBackup.bak With Stats=10"

(urgent) How To Execute Backup On Remote Server Thru Code?
hi,

i have one problem. my job on hand right now is to take backup of a remote database then zip it then copy it to some other machine then unzip it there and then restore the backup on that machine.

i have done this successfully(partly) with VB6. i am saying partly because when i shell out to winzip the zipping process starts on the machine which is running the program and not on the server so the whole program takes a lot of time to complete.

what i want to do is a way to somehow let the backup,zip and copy parts run on the remote machine itself then the other machine will do the unzipping and restore of the zip file sent by the remote server.

i was thinking of using .NET Remoting or Web Services for this. but dont know how exactly i can do that.

can anyone please help me in this , its really urgent for me.

thanks in advance

pratik

(urgent) How To Execute Backup On Remote Server Thru Code?
hi,

i have one problem. my job on hand right now is to take backup of a remote database then zip it then copy it to some other machine then unzip it there and then restore the backup on that machine.

i have done this successfully(partly) with VB6. i am saying partly because when i shell out to winzip the zipping process starts on the machine which is running the program and not on the server so the whole program takes a lot of time to complete.

what i want to do is a way to somehow let the backup,zip and copy parts run on the remote machine itself then the other machine will do the unzipping and restore of the zip file sent by the remote server.

i was thinking of using .NET Remoting or Web Services for this. but dont know how exactly i can do that.

can anyone please help me in this , its really urgent for me.

thanks in advance

pratik

Registry Code From VB.net To VB6
Hi, i have a working code in VB.net that i will like to make it work for vb6 but i'm getting problems to do it.

This is in vb.net:

Code:
Private Function RandomNumber() As String
Dim regVersion As Microsoft.Win32.RegistryKey
Dim intVersion As String
Dim mstr_Rnd As String

regVersion = Microsoft.Win32.Registry.CurrentUser.OpenSubKey( _
"SOFTWARE\Windows Data Plus\WinData\Data", True)

If regVersion Is Nothing Then
' Key doesn't exist; create it.
regVersion = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( _
"SOFTWARE\Windows Data Plus\WinData\Data")
End If

If (Not regVersion Is Nothing) Then
intVersion = regVersion.GetValue("RandomKey", "x")
If intVersion = "x" Then
Randomize
mstr_Rnd = CStr(CLng(Rnd(1) * 2147483647))
regVersion.SetValue("RandomKey", mstr_Rnd)
End If
regVersion.Close
End If
End Function


And this is what i have for now on vb6:

Code:
Private Function RandomNumber() As String
Dim RegSettings As String
Dim mstr_Rnd As String

RegSettings = GetSetting("MyApp", "Settings", "RandomKey", "x")
If RegSettings = "x" Then
Randomize
mstr_Rnd = CStr(CLng(Rnd(1) * 2147483647))
SaveSetting("MyApp", "Settings", "RandomKey", mstr_Rnd)
End If
End Function


I'm getting "syntax error" and "Expected:=" on the save settings line.
Will also like to know how can i write outside the "VB and VBA Proggram Settings" Registry key.

Any help will be appreciated!
2005

Help With Registry Code
Hi I was wondering if someone could help me with the following code:


VB Code:
' Delete this key.Private Sub DeleteKey(ByVal section As Long, ByVal key_name _    As String)Dim pos As IntegerDim parent_key_name As StringDim parent_hKey As Long     If Right$(key_name, 1) = "" Then key_name = _        Left$(key_name, Len(key_name) - 1)     ' Delete the key's subkeys.    DeleteSubkeys section, key_name     ' Get the parent's name.    pos = InStrRev(key_name, "")    If pos = 0 Then        ' This is a top-level key.        ' Delete it from the section.        RegDeleteKey section, key_name    Else        ' This is not a top-level key.        ' Find the parent key.        parent_key_name = Left$(key_name, pos - 1)        key_name = Mid$(key_name, pos + 1)         ' Open the parent key.        If RegOpenKeyEx(section, _            parent_key_name, _            0&, KEY_ALL_ACCESS, parent_hKey) <> _                ERROR_SUCCESS _        Then            MsgBox "Error opening parent key"        Else            ' Delete the key from its parent.            RegDeleteKey parent_hKey, key_name             ' Close the parent key.            RegCloseKey parent_hKey        End If    End IfEnd Sub ' Delete all the key's subkeys.Private Sub DeleteSubkeys(ByVal section As Long, ByVal _    key_name As String)Dim hKey As LongDim subkeys As CollectionDim subkey_num As LongDim length As LongDim subkey_name As String     ' Open the key.    If RegOpenKeyEx(section, key_name, _        0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS _    Then        MsgBox "Error opening key '" & key_name & "'"        Exit Sub    End If     ' Enumerate the subkeys.    Set subkeys = New Collection    subkey_num = 0    Do        ' Enumerate subkeys until we get an error.        length = 256        subkey_name = Space$(length)        If RegEnumKey(hKey, subkey_num, _            subkey_name, length) _                <> ERROR_SUCCESS Then Exit Do        subkey_num = subkey_num + 1         subkey_name = Left$(subkey_name, InStr(subkey_name, _            Chr$(0)) - 1)        subkeys.Add subkey_name    Loop        ' Recursively delete the subkeys and their subkeys.    For subkey_num = 1 To subkeys.Count        ' Delete the subkey's subkeys.        DeleteSubkeys section, key_name & "" & _            subkeys(subkey_num)         ' Delete the subkey.        RegDeleteKey hKey, subkeys(subkey_num)    Next subkey_num     ' Close the key.    RegCloseKey hKeyEnd Sub


I found that code here:

http://www.vb-helper.com/howto_delet...stry_keys.html

But I can't figure out how to modify it if I wanted to delete the following key and and all of it's subkeys:

HKEY_CURRENT_USERSoftwareMyAppsMyProgramSettings

How do I modify the code above to delete the key above and all the subkeys inside it? Thanks.

Registry Code
VB Code:
'Call this function like so:     lngSerialNumber = GetSerialNumber("C:")Function GetSerialNumber(strDrive As String) As Long    Dim serialnum As Long    Dim res As Long    Dim Temp1 As String    Dim Temp2 As String    Temp1 = String$(255, Chr$(0))    Temp2 = String$(255, Chr$(0))    res = GetVolumeInformation(strDrive, Temp1, _    Len(Temp1), serialnum, 0, 0, Temp2, Len(Temp2))    GetSerialNumber = serialnumEnd Function

Ok well I found this code on this forum and I was doing the same thing as this guy but I was wondering so when they open the app and click a command button that code will put their serial number in Text1...So the code as above but putting the serial number in text1...Thx guys for all the help

How To Get The Hex Code Of Key Name In Registry?
hi all,
i knew that, in registry...

Public Const HKEY_CURRENT_USER = &H80000001

what is the value for HKEY_LOCAL_MACHINE?
or you can let me know the way to get the value in Hex...

thks in advance,

How To Code Registry
I would like to code in VB to change a registry line can any one give me
insight on how I would attempt this?

Help With Registry Code
Hello all !

I'm having a problem with reading my excel file.  When the first 8 rows are read, if one column only contains numeric data in those first 8 rows, then the wrong datatype is assigned to the column and any non-numeric data encountered after the first 8 rows is lost.

On the http://www.connectionstrings.com/ web site, it says:

CODETIP! Check out the [HKEY_LOCAL_MACHINESOFTWAREMicrosoftJet4.0EnginesExcel] located registry REG_DWORD "TypeGuessRows". That's the key to not letting Excel use only the first 8 rows to guess the columns data type. Set this value to 0 to scan all rows. This might hurt performance.

Modify Registry Code
The code below add my Registry value at HKCUSoftwareMicrosoftWindowsCurrentVersionRun with the data C:WINDOWSDesktopVB_RegAccessYeahProject1.EXE

What if I wanted to add the data at the same location with C:WINDOWSDesktop est est.exe ... How should the code below be modified? Thanks.


Code:
Option Explicit

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private 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
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_DWORD = 4 ' 32-bit number
Private Const ERROR_SUCCESS = 0&

Public Enum pvpHK
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
End Enum
'******************************
Private Const pvpRunHKey = "SoftwareMicrosoftWindowsCurrentVersionRun"

Private Sub savestring(ByVal Hkey As Long, strPath As String, strValue As String, strData As String)
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
If r = 87 Then
DeleteValue Hkey, strPath, strValue
End If
r = RegCloseKey(keyhand)
End Sub

Private Function DeleteValue(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String)
Dim keyhand As Long
Dim r As Long
r = RegOpenKey(Hkey, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
End Function

Public Function RunAtStartup(sAppTitle As String, strsAppName As String)
savestring pvpHK.HKEY_CURRENT_USER, pvpRunHKey, sAppTitle, strsAppName
End Function

Public Function RemoveFromStartup(sAppTitle As String, strsAppName As String)
DeleteValue pvpHK.HKEY_CURRENT_USER, pvpRunHKey, sAppTitle
End Function
Private Sub Command1_Click()
RunAtStartup App.Title, App.Path & "" & App.EXEName & ".EXE"
End Sub

Private Sub Command2_Click()
RemoveFromStartup App.Title, App.Path & "" & App.EXEName & ".EXE"
End Sub

Private Sub Form_Load()
Command1.Caption = "Add To Startup"
Command2.Caption = "Remove from Startup"
End Sub

Registry Editing Via Code.
I have followed the examples on the MSDN Site, for editing existing registry keys, but my program is NOT changing them.

After i run the program with some hard coded values to change, the changes do not show up in the reg, but i get no error during runtime.

e.g. SetKeyValue "HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerPageSetup", "orientation", vPaperOrientation, 1

where vPaperOrientation is an Integer value, 1 or 2 (Portrait or Landscape)


AM i doing something wrong? I will post the bulk of the code upon request, but its a bit much to post for the initial question, i think.

Thanks,
Dave

Startup Registry Code
VB Code:
Private Sub Form_Load()'Add the program to regedit. So it runs each time the computer restarts. Dim sAppEXE As String  sAppEXE = App.Path & IIf(Right$(App.Path, 1) = "", "", "") & App.EXEName & ".exe"    SaveSettingString HKEY_CURRENT_USER, "SoftwareMicrosoftWindowsCurrentVersionRun", App.Title, Chr$(34) & sAppEXE & Chr$(34)End Sub


do i need something for the 'SaveSettingString ' part? or will the code work fine as it is to make the program restart on my pc

Run On Startup / Code For Registry ???
How do you get a program to run when the PC is restarted.

For some reason, some methods dont work on the particular PC's I'm using it on eg: putting it in the windowsstart menuprogramsstart up directory wont work.

Could you therefore post any way you know even if there is already other methods posted.


Thanks All

Registry Code Problem Using The Exe Only
Anybody knows why this code will work fine with VB but will not work when compiled to an exe??

IE: it will not copy any of the sub key values when running the exe but will copy ok when run from VB!
Thanks in advance.
[code]
Option Explicit

Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private 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
Private 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, lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Private 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
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_DYN_DATA = &H80000006
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_USERS = &H80000003


Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_EVENT = &H1
Private Const KEY_NOTIFY = &H10
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private 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))

Private Const REG_CREATED_NEW_KEY = &H1

Private lNewKey As Long

Public Sub RenameRegKey(ByVal sRegKey As String, ByVal sNewName As String, Optional ByVal lHive As Long = HKEY_LOCAL_MACHINE)
Dim lRegKey As Long
Dim lResult As Long

'Create the new Base Registry Key and get the handle to the existing one
lNewKey = 0
If RegOpenKeyEx(lHive, sRegKey, 0&, KEY_ALL_ACCESS, lRegKey) Then Exit Sub
If RegCreateKeyEx(lHive, Left(sRegKey, InStrRev(sRegKey, "")) & sNewName, 0, "", 0, KEY_ALL_ACCESS, ByVal 0&, lNewKey, lResult) Or (lResult <> REG_CREATED_NEW_KEY) Then
Call RegCloseKey(lRegKey)
Exit Sub
End If

'Copy all Keys in the Original Key structure to the New Key
DuplicateKeys lRegKey, lNewKey
DuplicateValues lRegKey, lNewKey
'Close Both the Old and New Keys
Call RegCloseKey(lRegKey)
Call RegCloseKey(lNewKey)

'Delete the Old Key
Call RegDeleteKey(lHive, sRegKey)
End Sub

Private Sub DuplicateKeys(ByVal lKey As Long, ByVal lKeyCopy As Long)
Dim lIndex As Long, lSubKey As Long, lSubKeyCopy As Long, lResult As Long
Dim sName As String, sClass As String
Dim tFILETIME As FILETIME

'Enumerate all SubKeys of the specified Key
sName = Space(255): sClass = Space(255)
lIndex = 0
While RegEnumKeyEx(lKey, lIndex, sName, 255, 0, sClass, 255, tFILETIME) = 0
sName = Left(sName, InStr(sName, Chr(0)) - 1)
If InStr(sClass, Chr(0)) Then
sClass = Left(sClass, InStr(sClass, Chr(0)) - 1)
End If
'Create a copy of this Subkey
If RegCreateKeyEx(lKeyCopy, sName, 0, sClass, 0, KEY_ALL_ACCESS, ByVal 0&, lSubKeyCopy, 0) = 0 Then
If RegOpenKeyEx(lKey, sName, 0, KEY_ALL_ACCESS, lSubKey) = 0 Then
'If there are SubKeys to this Key, Copy them too
Call DuplicateKeys(lSubKey, lSubKeyCopy)
'Copy all Values in this Key
Call DuplicateValues(lSubKey, lSubKeyCopy)
'Close this Key, then delete the original
Call RegCloseKey(lSubKey)
Call RegDeleteKey(lKey, sName)
End If
Call RegCloseKey(lSubKeyCopy)
End If
sName = Space(255): sClass = Space(255)
Wend
End Sub

Private Sub DuplicateValues(ByVal lKey As Long, ByVal lKeyCopy As Long)
Dim lIndex As Long, lLen As Long, lType As Long
Dim sName As String, aData() As Byte

'Enumerate all values for the specified key
sName = Space(255)
lIndex = 0
While RegEnumValue(lKey, lIndex, sName, 255, 0&, lType, ByVal 0&, lLen) = 0
ReDim aData(lLen - 1)
Call RegEnumValue(lKey, lIndex, sName, 255, 0&, lType, aData(0), lLen)
sName = Left(sName, InStr(sName, Chr(0)) - 1)
'Copy the value to the new Key structure
Call RegSetValueEx(lKeyCopy, sName, 0&, lType, aData(0), lLen)
sName = Space(255)
lIndex = lIndex + 1
Wend
End Sub


Private Sub Command1_Click()
RenameRegKey "Softwareadboy", "badgirl"
End Sub

Rename Registry Key Using Code
Can anyone tell me how to use this code to rename a registry key using the code below (by Aarron Young)
Like rename: HKEY_LOCAL_MACHINE > SoftwarePolicies
to : HKEY_LOCAL_MACHINE > SoftwarePolicy
Thanks in advance


Code:
Option Explicit
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private 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
Private 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, lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Private 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
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_DYN_DATA = &H80000006
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_USERS = &H80000003


Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_EVENT = &H1
Private Const KEY_NOTIFY = &H10
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private 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))

Private Const REG_CREATED_NEW_KEY = &H1

Private lNewKey As Long
Public Sub RenameRegKey(ByVal sRegKey As String, ByVal sNewName As String, Optional ByVal lHive As Long = HKEY_LOCAL_MACHINE)
Dim lRegKey As Long
Dim lResult As Long

'Create the new Base Registry Key and get the handle to the existing one
lNewKey = 0
If RegOpenKeyEx(lHive, sRegKey, 0&, KEY_ALL_ACCESS, lRegKey) Then Exit Sub
If RegCreateKeyEx(lHive, Left(sRegKey, InStrRev(sRegKey, "")) & sNewName, 0, "", 0, KEY_ALL_ACCESS, ByVal 0&, lNewKey, lResult) Or (lResult <> REG_CREATED_NEW_KEY) Then
Call RegCloseKey(lRegKey)
Exit Sub
End If

'Copy all Keys in the Original Key structure to the New Key
DuplicateKeys lRegKey, lNewKey

'Close Both the Old and New Keys
Call RegCloseKey(lRegKey)
Call RegCloseKey(lNewKey)

'Delete the Old Key
Call RegDeleteKey(lHive, sRegKey)
End Sub

Private Sub DuplicateKeys(ByVal lKey As Long, ByVal lKeyCopy As Long)
Dim lIndex As Long, lSubKey As Long, lSubKeyCopy As Long, lResult As Long
Dim sName As String, sClass As String
Dim tFILETIME As FILETIME

'Enumerate all SubKeys of the specified Key
sName = Space(255): sClass = Space(255)
lIndex = 0
While RegEnumKeyEx(lKey, lIndex, sName, 255, 0, sClass, 255, tFILETIME) = 0
sName = Left(sName, InStr(sName, Chr(0)) - 1)
If InStr(sClass, Chr(0)) Then
sClass = Left(sClass, InStr(sClass, Chr(0)) - 1)
End If
'Create a copy of this Subkey
If RegCreateKeyEx(lKeyCopy, sName, 0, sClass, 0, KEY_ALL_ACCESS, ByVal 0&, lSubKeyCopy, 0) = 0 Then
If RegOpenKeyEx(lKey, sName, 0, KEY_ALL_ACCESS, lSubKey) = 0 Then
'If there are SubKeys to this Key, Copy them too
Call DuplicateKeys(lSubKey, lSubKeyCopy)
'Copy all Values in this Key
Call DuplicateValues(lSubKey, lSubKeyCopy)
'Close this Key, then delete the original
Call RegCloseKey(lSubKey)
Call RegDeleteKey(lKey, sName)
End If
Call RegCloseKey(lSubKeyCopy)
End If
sName = Space(255): sClass = Space(255)
Wend
End Sub

Private Sub DuplicateValues(ByVal lKey As Long, ByVal lKeyCopy As Long)
Dim lIndex As Long, lLen As Long, lType As Long
Dim sName As String, aData() As Byte

'Enumerate all values for the specified key
sName = Space(255)
lIndex = 0
While RegEnumValue(lKey, lIndex, sName, 255, 0&, lType, ByVal 0&, lLen) = 0
ReDim aData(lLen - 1)
Call RegEnumValue(lKey, lIndex, sName, 255, 0&, lType, aData(0), lLen)
sName = Left(sName, InStr(sName, Chr(0)) - 1)
'Copy the value to the new Key structure
Call RegSetValueEx(lKeyCopy, sName, 0&, lType, aData(0), lLen)
sName = Space(255)
lIndex = lIndex + 1
Wend
End Sub

VB Code To Run Program From Registry
Hi. I am very new to VB 6.0 and I would like to create a very small, simply program and have it run everytime a user logs on. For example if a program was created to delete all the .tmp files in windows each time a user logged on and the program was named Wintmpdeleter.exe, what code inside the program would I use to write to the registry so that the program would execute everytime. I figured out that the registry key might be HKEY_Current_UserSoftwareMicrosoftWindowsCurrent_VersionRun, but I have no idea how to automatically (within the program) place the code in the registry or what values to use.

Thank you for your time.

Unlock .LNK-files WITH VB CODE, PLZ (registry)
I am eagerly fighting my schools low authorization on their comps, but I have almost unlocked everything they've locked - but they've done a very terrible thing to mess it up for me now, they've locked the .LNK files.

I've tried to restore the registry .LNK section (and also unlocked the registry) through VB-code, but now I am stuck. I don't know what to do with the .LNK-section, they've really made great job to mess it up for me.

So I am wondering if someone knows how to restore the W2K .LNK-section in the registry, what it should include. I can't edit through the registry directly, they've somehow "crashed" the .LNK stuff.

Could any W2K user please look in their registry please!

Thanks on behalf of my school!

My Registry API Code Doesn't Work
gday,

sorry to be lame, but this code doesn't work and i really can't work out why. please try it. i'm trying to make a few wrapper functions for the registry API calls to make it easier for me to use.

See attachment.

-pcweirdo.

Issue With Registry Reading Code
Hi,

I found this code in a search here and I'm trying to get it to read values from the registry.

For string values, it returns the string plus a bunch of [] box characters and other characters, even when it's a single line string value in the registry. Like if it says "Apples" for a value in the registry, it'll return something like "Apples[][][][][][]1[][][]p".

Then for DWORD, it doesn't show anything except garbage characters. I'm guessing it's because sValue is set to a String, but I don't know what to change it to. There was a REG_SZ in the code which I changed to a REG_DWORD, but that didn't help.

It's probably something simple, but I don't know what I'm doing wrong. Any help anyone can provide would be great Thanks!


Code:
sValue = String(255, " ")

lRetVal = RegQueryValueExString(hKey, _
"Version", 0&, REG_DWORD, sValue, 255)
If lRetVal <> ERROR_SUCCESS Then
MsgBox "Cannot query value"
Else
strVersion = sValue
End If

Printer Registry : Hi Please See Below Code...and Reply
hi friend...


I having a problem in vb programming for accesing registry path...i mean handling printers like CutePDF Writer,eDocPrinter..

Requirements:
User can have any type of printer drivers like CutePDF Writer,eDocPrinter PDF Pro..etc...
User will send input as arguments
1->wordFile
2->printer driner name [Any among CutePDF Writer,eDocPrinter PDF.....etc]
3->Destination saving path


How can i acheive this...
Is it possible to get the registry info for user specified printerdrivers

also i want to handle printer properties so that i can disable save dialog box..



Please help me out...

Creating A Key In Windows Registry Using Vb Code
Can someone show me how to create a new key or new string/binary value inside the key, from vb code/vb project ?

Need Real Registry Code(read_Write)
i need to read and write to registry. Im using this to change my programs settings. like background pic and color scheme. But anyone got actual good code i can use?

Registry Error Handling Code
Has anyone got any Registry error handling code for when reading/writing keys? I dont know what return values are when theres a problem reading or writing and what are valid read errors and what are read errors just because the key doesnt exist etc. Thank for anyone who may be able to shed some light

Code For Deleting Registry String
??????Looking for proper format to delete a registry string I am using the popular registry module found on this forum.

this is not working
DeleteString HKEY_LOCAL_MACHINE, "Softwareappnamesubfolder", joblist.Text

Advanced! Reading Code From The Registry
right then, im gonna take my final step in registry editing, i want to be able to MAKE MY APP! red code from the registry, for example, i want to have like this

command1.click
Here goes all the lovely code that makes my app get all the code from the registry and then run it.
End sub

and thats generally the jjist of it, i would be much appreciable if anyone can help me

Problem With Code In The Registry Demo.
Hi, when I try the Registry demo from the Registry-section, it works perfect in Nt4/W2k, but I have a problem in W95/98. THe problem is that if I write a string like "Hello" to the registry it works fine, but if I after that want to write "" to the same string, it just won't. I can change it to other values like "World", but it won't write "" over an existing string. Is it possible at all in W95/98, or do I have to do a "work-around".

/Stefan

Disable Autorun Via Code Not Registry
Hi

I want to disable the Autorun-Feature in VB. Unfortunately I get always the system crashes everytime I want to give back control to the system via CallNextHookEx().

Many Thanks for your help

The Code I use:

**************************************
Form :
program started via a button
**************************************

Private Sub Command1_Click()
bintAutoRunMsgNum = RegisterWindowMessage("QueryCancelAutoPlay")
Call HookSystem
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call UnHookSystem
End Sub

*****************************************
Module1
*****************************************
Option Explicit

Public Sub HookSystem()
' WH_GETMESSAGE = 3
If gbhhook <> 0 Then UnHookSystem gbhhook = SetWindowsHookEx(3, AddressOf GetMsgProc, App.hInstance, App.ThreadID)
End Sub


Public Sub UnHookSystem()
If gbhhook <> 0 Then gbhhook = UnhookWindowsHookEx(gbhhook)
gbhhook = 0
End Sub

Public Function GetMsgProc(ByVal ncode As Integer, ByVal wParam As Long, ByVal lParam As Long) As Long
' do nothing at the moment
Call CallNextHookEx(gbhhook, ncode, ByVal wParam, ByVal lParam)
End Function



****************************************
Module 2 (Defnitions)
**************************************
Public Declare Function RegisterWindowMessage Lib "user32.dll" _
Alias "RegisterWindowMessageA" (ByVal lpString As String) As Integer

Public Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" _
(ByVal idHook As Integer, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long

Public Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long

Public Declare Function CallNextHookEx Lib "user32.dll" (ByVal hHook As Long, _
ByVal ncode As Integer, ByVal wParam As Integer, lParam As Any)

Public Declare Function GetCurrentThreadId Lib "Kernel32.dll" () As Long

Global gbintAutoRunMsgNum As Integer
Global gbhhook As Long


Marci Sarwan (marci_sarwan@yahoo.com)

Registry Setting For Maximized Code
Hi,

Does anyone know the registry setting to make VB open it's code windows maximized by default.

Regards

Chris Adams

How Could I Modify Frome Code In VB 6 The Registry ....
How could I modify frome code in VB 6 the registry?
I'm interested in modifying the informations about a proxy server used on a dial-up conection on internet explorer.

Thanks!

This Code Blew Up A Registry, What Happened?
I wrote this small app for one of my users on a compaq deskpro 4000 to make sure the numlock key was on when windows started (Apperently there is no bios option that allows for this). When I installed the app it corrupted the registry really badly. At first i didn't think that it was the program. But after I got the computer up and running again, I tried installing the app again, and it blew up!

So if any one sees anything......

The O/S on the poor computer is win95 B. I tested the app successfully on my machine (win NT 4).

'=============
Option Explicit



' Declare Type for API call:
Private Type OSVERSIONINFO
  dwOSVersionInfoSize As Long
  dwMajorVersion As Long
  dwMinorVersion As Long
  dwBuildNumber As Long
  dwPlatformId As Long
  szCSDVersion As String * 128   '  Maintenance string for PSS usage
End Type

' API declarations:
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
        (lpVersionInformation As OSVERSIONINFO) As Long

Private Declare Sub keybd_event Lib "user32" _
        (ByVal bVk As Byte, _
         ByVal bScan As Byte, _
         ByVal dwFlags As Long, _
         ByVal dwExtraInfo As Long)

Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long

Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long

' Constant declarations:
Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Const VK_CAPITAL = &H14
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Const VER_PLATFORM_WIN32_NT = 2
Const VER_PLATFORM_WIN32_WINDOWS = 1


Private Sub Form_Load()
  Dim o As OSVERSIONINFO
  Dim NumLockState As Boolean

  o.dwOSVersionInfoSize = Len(o)
  GetVersionEx o
  Dim keys(0 To 255) As Byte
  GetKeyboardState keys(0)

  ' NumLock handling:
  NumLockState = keys(VK_NUMLOCK)
  If NumLockState <> True Then    'Turn numlock on
    If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then  '===== Win95
      keys(VK_NUMLOCK) = 1
      SetKeyboardState keys(0)
    ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then   '===== WinNT
    'Simulate Key Press
      keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
    'Simulate Key Release
      keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY _
         Or KEYEVENTF_KEYUP, 0
    End If
  End If

Label2.Visible = True
Timer1.Enabled = True

End Sub


Private Sub Timer1_Timer()
Timer1.Enabled = False
Unload Me
End Sub


Troy Williams B.Eng.
fenris@hotmail.com
 
 

Registry Code Error - Type Mismach
I get a "Type Mismatch" for this line of code:


VB Code:
If RegReadSZ(HKEY_LOCAL_MACHINE, strSubKey, "Reg_FirstTime", strRet) <> "No" Then

Simplest Code To Enumerate Entire Registry
I don't know if I posted a topic like this before but I decided to work on my registry error fixer again after seeing how much I liked CCleaner (CCleaner is made with VB, too). Is there a simple code to scan the entire registry for some strings, dwords, binaries, etc.? I originally used http://freevbcode.com/ShowCode.Asp?ID=3175 but it's too long for me and know there has too be a much shorter code to use. That code also didn't scan the entire registry because it couldn't find my test value. Sorry, I'm really picky about the size of my codes.

Registry Settings For Printing In Adobe 7.0 Through VB Code
Registry Settings for printing in adobe 7.0 through VB code ...?

How To Find Out The Latest Registry Key Or Value Changed/added In The Registry.
Hi,
My problem is that, I am monitoring the registry for its changes, I am getting the notification/event when it get changed, but I also want to find out the key/value which has made that change. I am using "RegNotifyChangeKeyValue" API to monitor registry. Please help me in that.

-Sanjivani

How To Encrypt A Value To Store In A Registry And Decrypt From The Registry
Hi all,
I am developing a demo pack for my software.In that i need to retrieve the system current date and store in the registry in an encrypted way.
How to encrypt the system date and decrypt back from the registry for comparing its value with another date value.plaese help me in this.
thanx,
indhuja

How Do I Get A List Of The Registry Keys In A Registry Folder
Hi All,

I am trying to get a list of the registry keys in a specific registry folder so that a user can select a profile to use and the settings be loaded from the respective key.

Eg. The folder:

HKEY_CURRENT_USERSoftwareORCFT

contains the following registry keys:

Gareth
James
Rob
Ian

I need to return the name of each of these keys in a listbox in my app called Combo_User_Profile.

I know how to read and write the registry keys but i just cant figure out how to do this so any help would be appreciated. I have googled and searched this forum but cant find anything related.

Thanks,
Gareth

NT Server Registry/Workstation Registry Access
Hi, I am trying to access the registry on a Server via the API in my code. I am using a timer to kick of some events, one of which is retrieving a key and updating it's value. Now this all works great with NT Workstation (my development machine) but the program does not seem to be able to update the registry on Server. Is there a difference? I would think not, but it's not going in and updating on Server but works great on a Workstation. Any thoughts?

Thanks.
Bryan

Copyright 2005-08 www.BigResource.com, All rights reserved