VBS exporting a registry key from a value

hello experts ,
im trying to export a key froma pre defined varibale , but it cannot read its content . please help below is a sample script .

Option Explicit
dim user , objshell
user= "HKEY_USER"
Set objShell = CreateObject("WScript.Shell")
objshell.run reg export (" & user" c:\temp\test.reg)
rad0ssAsked:
Who is Participating?
 
Bill PrewCommented:
Try:

strDirectory = "c:\test\hku.reg" 
user1 = "HKEY_USERS\" & reg & "\printers"
Set objshell = CreateObject("WScript.Shell") 
objshell.run "reg export " & user1 &  " " & strDirectory

Open in new window


»bp
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Think it should be
Option Explicit
dim user , objshell 
user= "HKCU"
Set objshell = CreateObject("WScript.Shell") 
objshell.run "reg export " & user & " c:\temp\test.reg"

Open in new window

0
 
Bill PrewCommented:
Are you just trying to get the value of one key in the registry to work with in your VB script code?  What you have currently will export a LOT of keys and data from the registry to a text export file, was that what you wanted?


»bp
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
rad0ssAuthor Commented:
dears ,
thank you for your support ,
what is the below scenario missing ? its not replacing the value of strdirectory


strDirectory = "c:\test\hku.reg"
user1 = "HKEY_USERS\" & reg & "\printers"
Set objshell = CreateObject("WScript.Shell")
objshell.run "reg export " & user1 &  strDirectory
0
 
rad0ssAuthor Commented:
yes thank you , it worked like a charm ... definitely i needed a space between :p
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Yes, you do need a space as per #a42417250
objshell.run "reg export " & user & " c:\temp\test.reg"

Open in new window


You will probably need to add quotes too when you have spaces in file or registry path.
0
 
Hassan RaadCommented:
when im trying to import with the below command , it keeps saying object required : " , but i cant tell where to add it .
can you please advise .

strdirectory = "\\sharedfolder"
objShell.Run"regedit /s " & Chr(34) & strdirectory & Chr(34), 0, True
0
 
Bill PrewCommented:
Looks like you are missing:

Set objshell = CreateObject("WScript.Shell")


»bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.