Does anyone know if you can inport registry settings into a batchfile for use in installing software and stuff? And if anyone knows could you please explain how to as i ain’t got a clue with registry stuff – Yet!
Thanks in Advance
Jambo
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Windows » Windows – other » Importing Registry Settings
As viking and cowboy have both said,
If you aren’t comfortable with th registry, stay away from it.
If you want to read a tale of woe by someone who was quite comfortable with the registry and managed to kill his laptop, have a look at post 204857. It was written within hours of it happening
It turns out that I couldn’t recover any data from the HD. I lost about a month’s worth of development. I toasted it but good
i thought f doing that but would rather try to use a batch file first. I want to pull an install path of a game from the registry in order to patch the program’s executable file! And guess what i went to try to do it with VB today and i can’t remember how to, it’s been a while since i’ve had to read somthing in from the registry, i’ll have to ask in the VB forum, any ideas here though? i think u use the “GetSetting(appname, section, key[, default])” or “GetAllSettings(appname, section)” command but can’t remember exactly and all my reference books are in work at the mo. any idea’s anyone?
Jambo
Not direct help to your problem. But re your ref books at work, I’ve found the command reference in the help for VBA comprehensive enough for most of my needs when I’ve had to stuff around with code. It gives full syntax and descriptions for both commands you quote. I assume the VB editor should have similar help.
I don’t think a batch file can READ the registry for you and MODIFY the registry. You want to use Visual Basic (or VBS) to do all of this.
You have two options:
1) RegRead and RegWrite (from Windows Script Host) — in VB or VBS
2) using the “API” — only with VB
For simple tasks, I just use the WSH “Reg” commands. For more complicated things, you need to use the API. I’ll get you references on both… BUT, I think Jeff is right — you should be using VBScript and not messing with the API.
___________________________
OK, I like “devguru’s” explanation of the WSH Shell commands:
WshShell.RegRead
WshShell.RegWrite
Then, the MSDN gives you an overview here: Reading and Modifying the Windows Registry Through Visual Basic
Quick and Dirty information on accessing and modifying the registry using the API is far more difficult to locate, but just to give you an idea of how it works:
Accessing the Windows Registry with the API in Visual Basic
MSKB – HOWTO: Use the Registry API to Save and Retrieve Setting
The answer is VBScript. See the following: Post #121209; Post #177457; Post #145958. Your target machine needs to have cscript.exe installed somewhere in the default path.
I haven’t done this in a long time and this is from memory.
If you use REGEDIT to export a hive from the registry into a .REG file, then open that file with WordPad, you will see what the file needs to look like. Then in the batch file, simply use the START batch file command to run a .REG file to import that data into the Registry.
I have about 500 zip files containing Unreal Tornament maps, i want to unzip these into the correct directories inside the Unreal Install path but i don’t want to ask the user for the install path. Instead i want to read the install path from a registry entry created when Unreal Tornament was installed! I have already done this with a .bat file and command line support for winzip but i still have to ask the user for the install path. I think this makes sense, any queries just ask.
Thanks
Jambo
How’s this:
Use the APIs to get the path from the registry and put it into a variable, strPath
Edit your .bat file and everywhere you have the path, replace it with %1
Then call your .bat like this:
strFull = “””c:fullpathtoyourtest.bat”” ” & strPath
Shell strFull
You may need to get the 8.3 path for this to work, which IIRC is another API call.
That would be perfect, but i’m not very familier with VB, i don’t know what API’s are, i program VBA & SQL for work but simple stuff, mainly code to automate statistics compilation and querying our main vehicles database also values that i read from the registry are wrote to the registry using the “SaveSetting” method & read using the “GetSetting” method. Could you post the code to read the Path from the registry?
The path is contained in the key “Folder” in the “HKEY_LOCAL_MACHINESOFTWAREUnreal TechnologyInstalled AppsUnrealTournament” section of the registry.
Thanks In Advance
Jamie
OK, be forewarned there is quite a lot of code, so here goes:
In the General Declarations section of a module place the following
Option Explicit
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const ERROR_NONE = 0
Public Const KEY_QUERY_VALUE = &H1
Declare Function RegCloseKey Lib “advapi32.dll” _
(ByVal hKey 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
Now add the following two procedures:
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 – 1)
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
Function QueryValue(Key As Long, sKeyName As String, sValueName As String)
Dim lRetVal As Long ‘result of the API functions
Dim hKey As Long ‘handle of opened key
Dim vValue As Variant ‘setting of queried value
lRetVal = RegOpenKeyEx(Key, sKeyName, 0, KEY_QUERY_VALUE, hKey)
lRetVal = QueryValueEx(hKey, sValueName, vValue)
QueryValue = vValue
RegCloseKey (hKey)
End Function
Function QueryValue(Key As Long, sKeyName As String, sValueName As String) As String
Dim lRetVal As Long ‘result of the API functions
Dim hKey As Long ‘handle of opened key
Dim sValue As String ‘setting of queried value
lRetVal = RegOpenKeyEx(Key, sKeyName, 0, KEY_QUERY_VALUE, hKey)
lRetVal = QueryValueEx(hKey, sValueName, sValue)
QueryValue = sValue
RegCloseKey (hKey)
End Function
Now in your code, you use it like this:
strPath = QueryValue (HKEY_LOCAL_MACHINE, “SOFTWAREUnreal TechnologyInstalled AppsUnrealTournament”, “Path”)
you will need to substitue the last parameter “Path” for the name of the specific key the path is in.
It is not possible to just use “RegRead” from the WSHost to get this path?? It looks to me — at least on the surface — that all he needs to do is read a given value in the registry — the “Path” value. Cannot he create a simple VBScript which returns the path value??
Working with the API is — as seen above — far more complicated… Just thoughts from the sidelines.
Did you try out Post #227468?
could you email it to me at Jamie.Aston@NtlWorld.Com please. I’ve been looking for it on the net but ain’t had any luck yet.
Jambo
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.