9 Replies Latest reply on Feb 10, 2010 3:27 PM by Mach6

    Simple batch file creation

    Apprentice

      Hello,

       

      I'm new to creating batch files. I'm trying to make a simple registry change. I want to create a batch file to summon the .reg file and have it run silently. How would I type the command to summon the .reg file? I tried the following script but didn't appear to work.

       

      This is what I have in the .bat file:

       

      regedit.exe /s http://coreservername/landesk/files/nicconet.reg

       

      but when it runs the batch I get this message:

       

      '\\coreservername\ldmain\landesk\files'
      CMD.EXE was started with the above path as the current directory.
      UNC paths are not supported.  Defaulting to Windows directory.

      C:\Windows>regedit.exe /s http://coreservername/landesk/files/nicconet.reg



      What am I missing in the script?

       

      I have both the .bat file and .reg file in the same location

       

      http://coreservername/landesk/files/nicconet.reg

        • 1. Re: Simple batch file creation
          Employee

          Are you running from source?  Windows doesn't like to allow you to explicitly assume the same path if you are running from a network share.  Try download from source and let me know if it works.  Alternately you could specify the full path to the .reg file as a full UNC path.

           

          If it was me I'd take a little different approach: Use the reg add command.  Unless you've got a LOT of values to import from .reg file it will most likely be easier using the reg add command, and then you don't need the .reg rile at all!  Try doing reg add /? from a command line, it's easy to use.

           

          Lemme know if either option helps.

           

          Thanks!

          • 2. Re: Simple batch file creation
            Apprentice

            All I'm basically doing is changing the homepage on IE in

             

            [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main]
            "Start Page"="http://www.nicconet.com"

             

            So how do I go about doing so using your method?

            • 3. Re: Simple batch file creation
              Employee

              HKCU is going to be tricky, because we generally don't run as any user, we run as the LocalSystem (computer) account.  It won't have access to HKCU.  Whether you use my method or your own you'll need to run as the currently logged on user or it won't work.

               

              Outside of that problem here is what you'd need to put in the batch file:

              reg add "hkcu\software\microsoft\internet explorer\main" /v "Start Page" /t REG_SZ /d "http://www.nicconet.com" /f

              • 4. Re: Simple batch file creation
                Apprentice

                Created a new batch distribution package using the .bat file created using the script given. When attempting to push it out, is fails with this message:

                 

                result:

                Hash of file in cache did not match hash received on command line

                 

                return code:

                16417

                 

                any ideas what could have caused this?

                • 5. Re: Simple batch file creation
                  Employee

                  Did you reset the package hash on the distribution package?  (Right click on the package, choose "Reset package hash")

                  • 6. Re: Simple batch file creation
                    Apprentice

                    I just reset the hash by right clicking the package. I resent to the client. Landesk says it completed successfully. But when checking the registry, it still hasn't changed.

                    • 7. Re: Simple batch file creation
                      Employee

                      Did you set the package to run as current user?  As I mentioned a few posts ago HKCU is going to be difficult because we don't run as the user, we run as LocalSystem (by defualt).  Change the distribution package to run as logged on user.  It's in the distribution package under Accounts.

                      • 8. Re: Simple batch file creation
                        Apprentice

                        I see. What if no one is logged on? How can I still be able to change the homepage for all users on the client? I assumed HKCU was the place to change the key for all users on the client. Is there another place in the registry that would be better to change to affect all users?

                        • 9. Re: Simple batch file creation
                          Employee

                          Alright, you've hit on the big problem.  If no one is logged on the task will fail and say that no one is logged on.

                           

                          To set the value for every user you need to:

                           

                          1 - Open HKEY_USERS.

                           

                          2 - List all subkeys

                           

                          3 - Determine which of the subkeys are legitimate users keys

                           

                          4 - Open each one of the legitimate ones and treat that as your HKCU key

                           

                          5 - Everything else should be the same.

                           

                          This is extremely difficult to do in a "simple batch file".  It's relatively easy to do in VBScript or AutoIt, depending on your level of skill with those utilities.