Solved

VBScript Registry Change

Posted on 2011-03-10
15
1,005 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
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 simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now