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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical SpecialistCommented:
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 PrewIT / Software Engineering ConsultantCommented:
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
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
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Bill PrewIT / Software Engineering ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rad0ssAuthor Commented:
yes thank you , it worked like a charm ... definitely i needed a space between :p
0
Shaun VermaakTechnical SpecialistCommented:
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 PrewIT / Software Engineering ConsultantCommented:
Looks like you are missing:

Set objshell = CreateObject("WScript.Shell")


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.