Jump to content

batch script to run reg keys


Recommended Posts

Ok here is the deal my boss asked me if I could make it so people can not change the theme's on our work computer cause we have a custom made theme for our company with is on every pc. I know how to edit the reg to set a defult theme and how to take away the display properties theme and desktop tabs. But want I wanted to do to make this easy to put on the many computers we have is have a batch script run or add the keys silent.

so here are my 3 keys and their file names which I made

defult_theme.reg

no_theme_tab.reg

no_background.reg

let say they live at C:\ (so when you help me you know the path to where they are)

So can anyone help me write the code to the batch script?

It should add each one of those reg files to the registry silently

Once I have got help with that I would also like to know(cause I made those reg files in regedit.exe and exported them)

if there is away to write to the registry useing a batch script with out having .reg files made or using any other file then the batch

script itsself

The first reg file lives here

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System

the Value name is

SetVisualStyle

the Value data is

C:\WINDOWS\Resources\Themes\whatever theme.msstyles

Well thats what I want to do so any help would be great

Thanks Jay Dogg

Link to comment
Share on other sites


Ok well that first part was easy

all I needed was

REGEDIT /S no_background_tab.reg

but I would still like to know if there is away to write to the registry using a batch script with out having .reg files made or using any other file then the batch script itsself

here are the 3 I would like add to the reg with just a batch script

Reg key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System

string value

Value name

SetVisualStyle

Value data

C:\WINDOWS\Resources\Themes\whatever theme.msstyles

Here is the second one

Reg Key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\

System

DWORD value

Value name

NoDispBackgroundPage

Value data

1

and the last one

Reg Key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

DWORD value

Value name

NoThemesTab

Value data

1

Link to comment
Share on other sites

If you want to try a VBS script for your Reg, this is using the values you provided.

Save As CustomTheme.vbs

Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Key :Key = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies"
Act.RegWrite Key & "\System\SetVisualStyle", "C:\WINDOWS\Resources\Themes\whatever theme.msstyles", "REG_EXPAND_SZ"
Act.RegWrite Key & "\NoDispBackgroundPage", 1, "REG_DWORD"
Act.RegWrite Key & "\Explorer\NoThemesTab", 1, "REG_DWORD"

Link to comment
Share on other sites

  • 3 weeks later...

Well I need a little more help

So I wanted to add ResHacker to the rightclick on all files

I have it working but I would like to use reg add in a batch script to add it to the reg

here is what I did

I went to HKEY_CLASSES_ROOT\*\shell

and added a key call ResHacker which left me with

HKEY_CLASSES_ROOT\*\shell\ResHacker

I then added a key call command with a data value of C:\\Program Files\\ResHacker\\ResHacker.exe \"%1\"

And that worked just great

so I exported the key and named it ResHacker.reg

which looks like this in notepad

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\ResHacker\command]

@="C:\\Program Files\\ResHacker\\ResHacker.exe \"%1\""

So I made a batch script which looks like this

REGEDIT /s Reshacker.reg

but it does nothing

I know the Reshacker.reg works cause when I double click it

it ask's if I want to add it to the reg and when I click yes it does

So can any one show me how to make this work and even better if

someone could show me how to do it with reg add (which I tried but couldnt get to work)

Here is what I had

reg add HKEY_CLASSES_ROOT\*\shell\ResHacker /v command /t REG_SZ /d C:\\Program Files\\ResHacker\\ResHacker.exe \"%1\"

So please help me make a .cmd or .bat file that add this to the reg without promt

Thanks Jay Dogg

Link to comment
Share on other sites

reshack.cmd

@Reg add "HKLM\SOFTWARE\Classes\*\shell\Open with ResHacker\command" /ve /d "\"C:\Program Files\ResHacker\ResHacker.exe\" \"%%1\"" /f>Nul

This is a single line so replace any carriage return with a single space if wrapping occurs.

Link to comment
Share on other sites

It may not work for you, but it works on all of my systems running three different Operating Systems.

Did you try rebooting or restarting explorer.exe in order for the context menu entry to be added. If you are running Vista you will need to run the batch file as administrator too because you will not have access to that branch of the registry.

There is a common theme here, your 'working' exported reg file isn't working and my '100% definitely working' script isn't either. If the above advice doesn't work for you, then I'd suggest you start to provide us with a lot more information to work with.

Link to comment
Share on other sites

Just to do a little test would you mind uploading your cmd file, so I can download it and run it to see if it works for me.

If it doesnt I guess I will be giving up a lot of info for you guys

Thanks Jay Dogg

Link to comment
Share on other sites

well thank you for the up loaded cmd file, but it still didnt work =( Im going to try it on my other pc. But this make me wonder why it will not work on my pc. What info do you need to help me get this thing working? In the end this is going into windows xp disk I made using nlite but if I cant get it working I will just drop the reg files on the desktop or C drive and run them myself and by the way thanks for all the help.

P.S.

I guess I will test the batch and cmd files I made on my other pc to see if they work

Link to comment
Share on other sites

Just checked the script submitted by Yzöwl on my systems, works fine (No reboot required).

Please explain in more detail as to what is not working.

Does the right-click menu have the "Open with ResHacker" item listed?

Does the registry have the "Open with ResHacker" key under:

"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\"?

And the command subkey with the proper default value?

Note: Your original registry file was using "HKEY_CLASSES_ROOT\*\shell\ResHacker"...

Link to comment
Share on other sites

ok like I said I was going to do I just tested your cmd file on my work laptop and it worked just fine and so did my batch file so I guess it just my pc.

Now here is what was happend on my pc when I ran it, I would double click it and it appears to run. A cmd.exe box would flash open really fast and close.

Then I check the reg before and after reboot and nothing at all gets writen to the reg so Im really not sure what is going on. But it shouldnt really matter cause im going to at it to my xp disk so it should work just fine. I just thought I wasnt writing the code right but like I said my batch file with the .reg file worked just fine. and Yzöwl's cmd worked too. So I guess I will just add it to my disk and do a test install and see if they get writen into the reg. Hey

Yzöwl thanks for all the help. And if you wouldnt mind doing a break down of your cmd file for me cause when I made my cmd file it looked like this

reg add HKEY_CLASSES_ROOT\*\shell\ResHacker /v command /t REG_SZ /d C:\\Program Files\\ResHacker\\ResHacker.exe \"%1\"

and your's looked like this

@Reg add "HKLM\SOFTWARE\Classes\*\shell\Open with ResHacker\command" /ve /d "\"C:\Program Files\ResHackerW\ResHacker.exe\" \"%%1\"" /f>Nul

What is the @ do and what is /ve and does it have to be in "" and what is the "\" before C:\Program Files and you have 2 % before the number 1 and so on. Dont trip if you dont have time to explain everything but hey if you do have the time Im always down to learn something new

Thanks Jay

Edited by JayDogg
Link to comment
Share on other sites

Technically you shouldn't add things directly to HKEY_CLASSES_ROOT, this key is mapped from HKEY_LOCAL_MACHINE\SOFTWARE\Classes, so you should add it there as a rule.

If it makes it easier for the explanation then we'll use this:

@Reg add "HKCR\*\shell\Open with ResHacker\command" /ve /d "\"C:\Program Files\ResHacker\ResHacker.exe\" \"%%1\"" /f>Nul

The preceding @ is there to prevent the following command from being echoed to the console window.

The key name is in double quotes because I used one or more spaces in its name.

/ve is used to add a blank/default value name which is what you're after

this is shown as @ in a reg file and (Default) directly in the Registry Editor

Backslashes are used to escape the internal double quotes.

Because the value data string is contained within double quotes we need to make sure that those containing quotes are maintained and read correctly by reg.exe

/d "\"C:\Program Files\ResHacker\ResHacker.exe\" \"%%1\""

The additional percent, (%), is used to to escape a single percent as required in batch files.

You'll note it usually in a For loop, when you'll require a single one directly in the console [For %A In (], but in a batch file doubling up is required. [For %%A In (]

I hope this helps you a little.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...