Solved

VB Script issue with REGEDIT

Posted on 2007-11-14
10
1,006 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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…

762 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

19 Experts available now in Live!

Get 1:1 Help Now