0

I have this registery (.reg) file that I use to modify screensaver properties:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\Desktop]
"ScreenSaveActive"="1"
"ScreenSaveTimeOut"="900"
"ScreenSaverIsSecure"="1"
"SCRNSAVE.EXE"="C:\\windows\\system32\\scrnsave.scr"

The registry works fine.

My Question: is it possible to make this registry to Visual Basic Script .vbs file? If yes how, please advice.

PS this is my first question in this forum.

Maytham Fahmi
  • 111
  • 1
  • 5
  • This sounds suspiciously like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What is it that you're trying to accomplish? Where will this script run? If it's in an AD environment, you can probably use group policy to accomplish your goal. – austinian Jul 27 '15 at 18:33
  • @austinian true, I use it in AD environment and yes under group policy. It was a temporary solution, and I was thinking to make it as vbs. – Maytham Fahmi Jul 27 '15 at 20:56
  • @austinian I disagree with you regarding XY problem, this reg is working fine. We are going move every thing to VBS so we have master VBS for login script as vbs, but I wanted to start testing .reg and see how it works as vbs, and quietly convert the rest of the login script. If you think this is the wrong way to go, I would like to hear your opinion. – Maytham Fahmi Jul 27 '15 at 21:02
  • First off, [VBScript is in maintenance mode, and may soon disappear](http://blogs.technet.com/b/heyscriptingguy/archive/2010/04/16/hey-scripting-guy-april-16-2010.aspx). So, learning VBScripting now may not be the best use of your time. As for logon scripts vs gpo, I'd recommend typing in exactly that into google to see a broader array of opinions, the first page has links to good articles and discussions. If you're converting a script to a GPO, and the script has conditional logic in it, then you can use item level targeting in most cases to apply the policy in the same manner the script does – austinian Jul 27 '15 at 22:35
  • OK @austinian That was useful, thank you I have just been out of date with my old day vbs we still running windows 2003/2008 servers, I am a bit old school, I need to update my self. – Maytham Fahmi Jul 27 '15 at 22:39
  • 1
    I completely understand, I've got several perfectly working vbscripts hanging around that are on the list of things to fix with a deadline of *eventually*. I highly recommend learning Powershell. It's not only available in 2003 up to version 2, but each successive version gets more and more powerful in its management capabilities, and in Windows 7+, you can even run your logon scripts asynchronously, so that the users don't have to wait for scripts to finish executing before their environment continues to load. – austinian Jul 27 '15 at 23:00
  • 1
    Check out [this article](http://www.atumvirt.com/index.php/2013/11/dramatically-reducing-logon-time-to-desktop-by-moving-from-group-policy-preferences-to-powershell-logon-script/) for a nice hybrid approach of GPO and scripted login. – austinian Jul 27 '15 at 23:00

1 Answers1

2

This was answered to a degree here at Super User but I recommend using reg query, reg import and reg add in MS-DOS/Command Prompt.

EDIT: To elaborate, you can manually add the keys one by one or you can import a .reg file with a simple batch script (if not a one liner)

If this is in an AD environment, it can be done, perhaps more reliably, with group policy. In an environment where there's remote management but no AD, personally what I'd do is host the .reg file on a network share and either copy it or import it directly if possible (I'm not sure if reg import supports that.

EDIT: Let's make this a bit more complete. You'd import the reg key with

reg import \\Sharename\regkey.reg

In command prompt/batch.

Here's an example I tested this solution with.

FINAL EDIT: It's been brought to my attention there's an off chance someone comes here and, in their right mind, actually wants to do this with VBS. I linked two links, but here's one of the solutions

Vbs Script:

Set oShell = CreateObject("Wscript.Shell")

'Your .Reg file and path goes here as in the example below
sRegFile = "C:\Temp\MyFile.Reg"

'This line runs Regedit in silent mode
oShell.Run "regedit.exe /s " & Chr(34) & sRegFile & Chr(34), 0, True 
Michael Bailey
  • 462
  • 2
  • 12
  • 1
    I don't know enough to say. I think if this is for your personal machine or for a single machine basis, it's better in Super User. Server Fault is generally for managing larger information systems. – Michael Bailey Jul 27 '15 at 16:41
  • @maytham I improved my answer in a much more catch-all manner. – Michael Bailey Jul 27 '15 at 19:57
  • https://jagspage.wordpress.com/2013/08/09/importing-reg-file-silently-using-vbscript/ and http://webcache.googleusercontent.com/search?q=cache:PnPr1Mx7yloJ:myitforum.com/cs2/blogs/dhite/archive/2006/09/01/Using-Vbs-To-Silently-Import-Reg-Files.aspx+&cd=1&hl=en&ct=clnk&gl=us both explain how to do it in VBS in multiple ways, most of which invoke ShellRun, which will literally run as you would run in Command Line. – Michael Bailey Jul 27 '15 at 19:58
  • To make the answer more complete and less reliant on the link as an answer and more as a source, you should include the vbs objects that can be used to modify the registry. For instance, GetObject("winmgmts:\\.\root\default:StdRegProv") if you use WMI to modify the registry, or CreateObject("WScript.Shell") if you want to use a shell object to modify the registry. – austinian Jul 27 '15 at 20:26
  • I actually intentionally didn't add that because I don't want to promote vbs as a solution to this person's use case. I will add example syntax for cmd however. – Michael Bailey Jul 27 '15 at 20:34
  • @austinian how's this look? See OP – Michael Bailey Jul 27 '15 at 20:43
  • The issue I have with this is that the OP specifically asked for VBS. While I 100% agree with you that VBS is not the right course to pursue, especially [since it's in maintenance mode now and may become deprecated at any time](http://blogs.technet.com/b/heyscriptingguy/archive/2010/04/16/hey-scripting-guy-april-16-2010.aspx), the OP is asking for a VBS solution. Fixing the question first is the best approach, IMHO. – austinian Jul 27 '15 at 22:26
  • 1
    It's already accepted but God forbid someone comes and somehow can't use powershell and batch, I'll include the content of one or two of those links.. I understand where you're coming from. – Michael Bailey Jul 27 '15 at 23:26