Solved

VB Script issue with REGEDIT

Posted on 2007-11-14
10
1,009 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now