Solved

VBScript Registry Change

Posted on 2011-03-10
15
1,016 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
[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
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
This collection of functions covers all the normal rounding methods of just about any numeric value.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Suggested Courses

632 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