Solved

VB Script issue with REGEDIT

Posted on 2007-11-14
10
1,014 Views
Last Modified: 2008-02-01
The previous individual that held my position setup AD to use VB scripting for login purposes. All is working well, but I am not familiar with VB programming, and wanted to insert a REGEDIT line that would in effect merge a regkey file for all users. I have read a little about Sh.RegWrite key, but still do not understand how to use it. Here is the REGEDIT script that I am trying to import:

REGEDIT.EXE /s \\servername\sharednamedirectory\filename.reg
(the server & shared directory that the reg file is located in)

I would like to insert a correct entry into our current VB script that will merge this reg key without disrupting the rest of the script process. Hope this is somewhat understandable, but I will be happy to further elaborate.
Thanks for looking...
0
Comment
Question by:graniteit
[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
  • 6
  • 4
10 Comments
 
LVL 3

Expert Comment

by:bayesianmind
ID: 20285006
Here's a little script I found to input all the .reg files in a directory:

'***********************************************************
' EDIT YOUR PREFERENCES BELOW
'***********************************************************
WorkingDir = "C:\PathTo\MyRegFiles"
Extension = ".reg"
ExecCmd = "REGEDIT /S "
'***********************************************************
' DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
'***********************************************************
Dim fso, myFolder, fileColl, aFile

Set fso = CreateObject("Scripting.FileSystemObject")
Set myFolder = fso.GetFolder(WorkingDir)
Set fileColl = myFolder.Files
For Each aFile in fileColl
  ext = right(aFile.name, 4)
  if Ucase(ext) = Ucase(Extension) then
    Set WshShell = WScript.CreateObject("WScript.Shell")
    RetVal = WshShell.Run(ExecCmd & chr(34) & aFile & chr(34), 1, True)
    set WshShell = nothing
  end if
Next

Hope that helps.
0
 
LVL 3

Expert Comment

by:bayesianmind
ID: 20285017
Actually this one is probably better for your case (just one reg file)

strCommand = "regedit /s c:\sample.reg"
set objWshShell = WScript.CreateObject("WScript.Shell")
intRC = objWshShell.Run(strCommand, 0, TRUE)
if intRC <> 0 then
 WScript.Echo "Error returned from importing registry: " & intRC
else
 WScript.Echo "No errors returned from importing the registry file"
end if
0
 

Author Comment

by:graniteit
ID: 20301132
Thanks bayesianmind...one quick, dumb question: would i simply copy over the VB script above, edit the reg file name & import it into the VB login script in AD/GPO?
0
Industry Leaders: 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!

 
LVL 3

Expert Comment

by:bayesianmind
ID: 20306021
Yeah that should work.
0
 

Author Comment

by:graniteit
ID: 20320018
Bayesianmind:

When I copied over the script, I edited only the FQDN of the reg file, then inserted it into the VB login script. Had a user reboot and try logging to see if the process took place and received a VB Script error. Don't have the exact message at this time, but could reproduce if necessry. Not sure if it occurred because of where I placed the entry into the login script...
0
 
LVL 3

Expert Comment

by:bayesianmind
ID: 20321501
Which one did you use? Also when you put in the FQDN did you add any quotes that would mess with the quoting already in place?
0
 

Author Comment

by:graniteit
ID: 20322306
I copied the entire entry you posted line for line, with the only change being the directory that the .reg file is located at...did not modify the quotes around the regedit. Put the entire new entry into the AD/GPO login script after the drive mappings, so that the network drive that the .reg is on would be accessible by the pc.
0
 
LVL 3

Expert Comment

by:bayesianmind
ID: 20329024
Try the second shorter script I posted. Its specifically made for one .reg file.
0
 

Author Comment

by:graniteit
ID: 20344275
bayesianmind:

I actually used the shorter of the two scripts you provided. Just changed the path to the .reg file and inserted it as listed above, after network drive mappings run.
Thanks again...
0
 
LVL 3

Accepted Solution

by:
bayesianmind earned 100 total points
ID: 20344938
Not sure why it doesn't work, does anyone else know?

Give the first one a try, perhaps that one will work. Just make a special directory for it with only the one .reg file you need.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
which modules are active in VB6 project? 6 52
Logon script fails 23 61
Windows Server 2012 & 2000 Network HELP 55 92
Auto-merge multiple transaction ledgers in Excel 5 35
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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