Solved

VB Script issue with REGEDIT

Posted on 2007-11-14
10
1,011 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 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