• Importing Registry Settings

    Home » Forums » AskWoody support » Windows » Windows – other » Importing Registry Settings

    Author
    Topic
    #383643

    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

    Viewing 1 reply thread
    Author
    Replies
    • #654937

      Jambo,
      IF:
      ————————————————–
      i ain’t got a clue with registry stuff – Yet!
      _________________________________

      I would suggest that if you ain’t got a clue with registry yet, That you don’t mess around with the registry until you DO have a clue.
      Be careful in the Reg ! sorry

      Bob

    • #655010

      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 crybaby

      • #655028

        I think i came across wrong, i ain’t afraid to tinker with the registry, i’ve been reading/writing VBA code from/to the registry for a while now but i just ain’t got a clue how to do it from a .bat file! Any ideas!

        Jambo

        • #655157

          You can always Export and Import to a .reg file, BUT… if you are comfortable with VBA, why not use VB or VBS to do this????? I don’t think you can use a regular batch file…

          • #655227

            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

            • #655251

              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. smile

            • #655256

              I have tried making sense of the VB Help but it ain’t happening, it only helps with settings that have been wrote to the registry with VB. I have to read a path from the registry that have been wrote by other programs. Any idea’s?

              Jambo

            • #655273

              Getting out of my depth here, I thought you just wanted to check the correct syntax.

              But, if you do know the appname, section, etc, then regardless of what wrote the values to the registry, shouldn’t VB be able to read them? If you don’t know the appname, etc, then I’ve got no idea.

            • #655293

              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

        • #655282

          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.

        • #655410

          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.

          • #655422

            I don’t want to modify the registry, only read a path from it! I am using VB 5 and have tried looking at the references in some of the above replys but i ain’t come up with squat! Must be me, i think i’ll ask one of my fellow I.T. ers in work on monday!

            Jambo

            • #655436

              I don’t think it is possible to read the registry from a BAT file.

              Why does it have to be from a bat file? What are you trying to do?

            • #655438

              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

            • #655453

              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.

            • #655456

              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

            • #655462

              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.

            • #655479

              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.

            • #655498

              It may quite possibly be easier to the WSH, but I work in an environment where it is disabled, so I don’t use it and more importantly, don’t know how to use it.

            • #658425

              Sorry guys, been away on hols for two weeks. I tried the API way and it looks way too complicated, and all machines the program needs to run on has WSH. How would i do it the WSH way, i’ve never came accross it or tried messing with it b4.

              Thanks in Advance
              Jambo

            • #658747

              Did you try out Post #227468?

            • #658892

              Cheer’s, i will start messing about with VBS and try to do what i’m doing. Is there a VBS editor like the one in VBA or VB? This would be much better as the auto complete would help a heck of alot.

              Thanks
              Jambo

            • #659055

              There was a Microsoft Script Editor (MSE), but I’ve lost track of where I got it and where it disappeared to… For the most part, I either write it as VBA first and then change it to VBScript (not too many changes are required) or just do it the hard way in Notepad.

            • #659115

              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

            • #659116

              Typically, the MSE is included with Office – see this article at MSDN and this from ZDNet

              Chances are, you already have it installed.

              (Not sure where you were searching, but Googling for “Microsoft Script Editor” brought those up on the first page…)

            • #659232

              You guys rock, i found it under the VBA Editor in Excel, it was there all the time.

              Cheers Guys
              Jambo

            • #659348

              Glad you found it. For future reference, the answer to your request is “heck, no, I’m a copyright attorney!” laugh

            • #659406

              If you have to pay for it i wouldn’t expect you to send it to me, i thought it was free. Nevermind, thanks anyway.

              jambo

    Viewing 1 reply thread
    Reply To: Reply #659232 in Importing Registry Settings

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel