Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Script to check registry for existing key and add if not exist

Posted on 2008-10-09
2
Medium Priority
?
1,026 Views
Last Modified: 2012-05-05
Hi,

I have a little amount of vbs skill but am in a hurry today, so 500 big ones to the person who helps me write a vbs to do the following in accordance with the M$ article

http://support.microsoft.com/kb/932842/en-us?spid=2530&sid=95

The entry needs to be in the following subkey

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Options

the key should be

UpdateHeaderFooter

with a value of 1

Of course I'd like to check the key exists before the operation so that it isnt done unessecarily

Many Thanks
0
Comment
Question by:BarkersIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 1000 total points
ID: 22679499
Paste the script below into a text file with a .vbs extension.  Running it will set the desired value.  Registry writes are fast enough that checking whether the value exists first isn't worthwhile.

You can also do this in batch with the command
reg add HKCU\Software\Microsoft\Office\11.0\Word\Options /v UpdateHeaderFooter /t REG_DWORD /d 1 /f


Const HKEY_CURRENT_USER = &H80000001
 
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Office\11.0\Word\Options"
strValueName = "UpdateHeaderFooter"
strValue = 1
 
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue

Open in new window

0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 1000 total points
ID: 22682009
Hi, if you want to check the value first (although there's not much of a performance difference there for a single DWord value) you can use this.

Regards,

Rob.
Const HKEY_CURRENT_USER = &H80000001
 
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Office\11.0\Word\Options"
strValueName = "UpdateHeaderFooter"
strValue = 1
 
intReturn = objRegistry.GetDWordValue(HKEY_CURRENT_USER, strKeyPath, strValueName, strCurrentValue)
If intReturn = 0 Then
	If CInt(strCurrentValue) <> CInt(strValue) Then
		objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
	Else
		WScript.Echo strKeyPath & "\" & strValueName & " is already set to " & strCurrentValue
	End If
Else
	WScript.Echo strKeyPath & "\" & strValueName & " is not set.  Setting to " & strValue
	objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
End If

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question