Avatar of hardrock95
hardrock95

asked on 

copy registry key to desktop

Need vbscript that will copy a registry key to the desktop in .reg form.
Thanks ahead.
Troy
Programming

Avatar of undefined
Last Comment
hardrock95
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of hardrock95
hardrock95

ASKER

Do I need some sort of object shell definition and is the standard path to desktop c:\desktop?
Avatar of HainKurt
HainKurt
Flag of Canada image

here it is:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "regedit /e ""C:\...path_to_desktop...\myreg.reg"" 'HKEY_CURRENT_USER\Software\VB and VBA Program Settings'"
Avatar of HainKurt
HainKurt
Flag of Canada image

you can use this to find desktop

strDesktop = WshShell.SpecialFolders("Desktop")

then full code will be

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
WshShell.Run "regedit /e """ &  strDesktop  &"\myreg.reg"" 'HKEY_CURRENT_USER\Software\VB and VBA Program Settings'"
Avatar of HainKurt
HainKurt
Flag of Canada image

here is working, tested sample:

dim WSHShell, strDesktop

Set WSHShell = WScript.CreateObject("WScript.Shell")
strDesktop = WSHShell.SpecialFolders("Desktop")

strDesktop = WshShell.SpecialFolders("Desktop")
strCmd = "regedit /e """ &  strDesktop & "\myreg.reg"" HKEY_LOCAL_MACHINE\SOFTWARE\HAINKURT"

WSHShell.Run strCmd

Open in new window

Avatar of hardrock95
hardrock95

ASKER

It runs, and I have tried other keys, but I cannot find myreg.reg anywhere on my computer.
I am assuming that is what I am looking for.  Do I need to create it first?
Avatar of hardrock95
hardrock95

ASKER

Last example appears to have worked.  I will let you know if there are issues.
Thanks.
Troy
Avatar of HainKurt
HainKurt
Flag of Canada image

in the previous samples I used ' around reg path, which cause issues i guess... maybe we should use " instead of '

strCmd = "regedit /e """ &  strDesktop & "\myreg.reg"" HKEY_LOCAL_MACHINE\SOFTWARE\HAINKURT"

>>>

strCmd = "regedit /e """ &  strDesktop & "\myreg.reg"" ""HKEY_LOCAL_MACHINE\SOFTWARE\HAINKURT"""

if reg path has special characters (?) or spaces... if there is no space, we dont need any ' or " around it...
Avatar of hardrock95
hardrock95

ASKER

Great help as always.
Programming
Programming

Programming includes both the specifics of the language you’re using, like Visual Basic, .NET, Java and others, but also the best practices in user experience and interfaces and the management of projects, version control and development. Other programming topics are related to web and cloud development and system and hardware programming.

55K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo