Solved

VBScript Registry Change

Posted on 2011-03-10
15
1,011 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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to delete emails stored in my Hotmail account 10 47
Excel object stays open 19 82
SCCM2012 sp2 CU3 cant see boot images missing tabs 3 108
IT Desktop Support 11 105
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…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

679 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