Solved

VBScript Registry Change

Posted on 2011-03-10
15
1,009 Views
Last Modified: 2012-05-11
I need some help with VB Script
I  have to deploy following Registry changes to all the WS. I need to use VB Script to push all the changes

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
"Time"="SQL Native Client"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\OnBase]
"Driver"="C:\WINDOWS\system32\sqlncli.dll"
"Description"="Time"
"Server"="s016\\CM"
"Database"="Time"
"LastUser"="hsi"

0
Comment
Question by:VIJAY2766
  • 8
  • 7
15 Comments
 
LVL 8

Expert Comment

by:MarkieS
ID: 35094813
These two functions enable you to read and write to the Registry


Function WriteReg(RegPath, Value, RegType)
      'Regtype should be “REG_SZ” for string, “REG_DWORD” for a integer,…
      '”REG_BINARY” for a binary or boolean, and “REG_EXPAND_SZ” for an expandable string
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegWrite(RegPath, Value, RegType)
      WriteReg = Key
End Function

Function ReadReg(RegPath)
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegRead(RegPath)
      ReadReg = Key
End Function
0
 

Author Comment

by:VIJAY2766
ID: 35094878
How do i add my regestry settings to this script?
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35094890
So you would call the functions as

Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\Time","SQL Native Client","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Driver","C:\WINDOWS\system32\sqlncli.dll","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Description","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Server","s016\\CM","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Database","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\LastUser","hsi","REG_SZ")
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:VIJAY2766
ID: 35094938
IS THIS CORRECT
*************************************************************************************8


Function WriteReg(RegPath, Value, RegType)
      'Regtype should be “REG_SZ” for string, “REG_DWORD” for a integer,…
      '”REG_BINARY” for a binary or boolean, and “REG_EXPAND_SZ” for an expandable string
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")
      Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\Time","SQL Native Client","REG_SZ")
      Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Driver","C:\WINDOWS\system32\sqlncli.dll","REG_SZ")
      Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Description","Time","REG_SZ")
      Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Server","s016\\CM","REG_SZ")
      Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Database","Time","REG_SZ")
      Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\LastUser","hsi","REG_SZ")
      Key = objRegistry.RegWrite(RegPath, Value, RegType)
      WriteReg = Key
End Function
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35094940
So your whole script should be

'-------------------------------------------------------------
Option Explicit

Dim WshShell,Temp,Test,bWaitOnReturn

Set WshShell = WScript.CreateObject("WScript.Shell")

On error resume next


Temp = WriteReg("HKLM\SOFTWARE\ODBC\test\ODBC.INI\ODBC Data Sources\Time","SQL Native Client","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\test\ODBC.INI\OnBase\Driver","C:\WINDOWS\system32\sqlncli.dll","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\test\ODBC.INI\OnBase\Description","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\test\ODBC.INI\OnBase\Server","s016\\CM","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\test\ODBC.INI\OnBase\Database","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\test\ODBC.INI\OnBase\LastUser","hsi","REG_SZ")



Function WriteReg(RegPath, Value, RegType)
      'Regtype should be “REG_SZ” for string, “REG_DWORD” for a integer,…
      '”REG_BINARY” for a binary or boolean, and “REG_EXPAND_SZ” for an expandable string
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegWrite(RegPath, Value, RegType)
      WriteReg = Key
End Function

Function ReadReg(RegPath)
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegRead(RegPath)
      ReadReg = Key
End Function
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35094946
Sorry - Posted at the same time... ;-)
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35094955
Sorry again - remove the \TEST bit - I didnt want to deploy this to myself!!!  ;-)
0
 

Author Comment

by:VIJAY2766
ID: 35095007
Do you want me to remove Test from :            (Dim WshShell,Temp,Test,bWaitOnReturn)
                                                                                                          Test,b

0
 

Author Comment

by:VIJAY2766
ID: 35095074
I am getting error when I am running this script
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35095136
I've re-posted it - I had put in \ HKLM\SOFTWARE\ODBC\TEST\ODBC.ini\ODBC..... sorry!


'-------------------------------------------------------------
Option Explicit

Dim WshShell,Temp,Test,bWaitOnReturn

Set WshShell = WScript.CreateObject("WScript.Shell")

On error resume next


Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\Time","SQL Native Client","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Driver","C:\WINDOWS\system32\sqlncli.dll","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Description","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Server","s016\\CM","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Database","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\LastUser","hsi","REG_SZ")



Function WriteReg(RegPath, Value, RegType)
      'Regtype should be “REG_SZ” for string, “REG_DWORD” for a integer,…
      '”REG_BINARY” for a binary or boolean, and “REG_EXPAND_SZ” for an expandable string
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegWrite(RegPath, Value, RegType)
      WriteReg = Key
End Function

Function ReadReg(RegPath)
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegRead(RegPath)
      ReadReg = Key
End
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35095184
And that's the trouble when you keep getting interupted by your work colleagues!!!  

Try a copy and paste of everything below the line - It was missing the End Function

'-------------------------------------------------------------
Option Explicit

Dim WshShell,Temp,Test,bWaitOnReturn

Set WshShell = WScript.CreateObject("WScript.Shell")

On error resume next


Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\Time","SQL Native Client","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Driver","C:\WINDOWS\system32\sqlncli.dll","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Description","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Server","s016\\CM","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\Database","Time","REG_SZ")
Temp = WriteReg("HKLM\SOFTWARE\ODBC\ODBC.INI\OnBase\LastUser","hsi","REG_SZ")



Function WriteReg(RegPath, Value, RegType)
      'Regtype should be “REG_SZ” for string, “REG_DWORD” for a integer,…
      '”REG_BINARY” for a binary or boolean, and “REG_EXPAND_SZ” for an expandable string
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegWrite(RegPath, Value, RegType)
      WriteReg = Key
End Function

Function ReadReg(RegPath)
      Dim objRegistry, Key
      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegRead(RegPath)
      ReadReg = Key
End Function
0
 

Author Comment

by:VIJAY2766
ID: 35095274
I am still getting error
Invalid Character Line1 Char 1
0
 

Author Comment

by:VIJAY2766
ID: 35095375
Attached is sceen shot of error.

 erro1r.doc
0
 
LVL 8

Accepted Solution

by:
MarkieS earned 500 total points
ID: 35095454
It may be the charachters that you have cut/pasted - I have attached as a file...
Registry-ODBC.vbs
0
 

Author Comment

by:VIJAY2766
ID: 35098428
script is working fine.

Thanks for your help

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

777 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