Changing local registry settings with a VB Script

Hi,

I am using a vbs login for my local network of 50 users.  Recently i have added the following to the script.


Dim fso
set fso = CreateObject("Scripting.FileSystemObject")
fso.copyfile "K:\winexit.scr", "c:\Program Files\"
set fso = nothing

This of course copies the screen saver winexit.scr to the local machine and the group policy sets it running after an hour of inactivity...user then has an hour to cancel the auto log off process.  

Works fine for an admin but not for a local user...i need to change the registry to create subkey and set value permissions.  

There is a lot on the net (and in these forums) but i have not found a definitive solution that works after a couple of hours of trawling the net.

Is there any way that this can be done in the script and what would the code be?


Regards,

Trojan

neiljmcraeAsked:
Who is Participating?
 
mladenoviczConnect With a Mentor Commented:
I don't know. Code I posted works for me, but not for neiljmcrae.
0
 
mladenoviczCommented:
Here is an example (registry access with WSh)

Win32Script.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run & "\Display Name", C:\test.exe
Win32Script.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run & "\Display Name")
Win32Script.RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run & "\Display Name")
0
 
neiljmcraeAuthor Commented:
Is this the correct registry entry to amend or is it just an example of what i could do?  Should I replace the test.exe path with my own file path on the users local machine?

Regards,

T
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mladenoviczCommented:
This is just an example. You can use Win32Script.RegWrite,Win32Script.RegRead and Win32Script.RegDelete methods
0
 
neiljmcraeAuthor Commented:
Sorry - I have very little ability with VBS and am struggling to do what you suggested - I only know that vbs can be used but the implementation is scary!!   I have put in the code as it was written and it is telling me that there is an error - expected end of statement - what do i need to do to make it work?
0
 
mladenoviczCommented:
0
 
neiljmcraeAuthor Commented:
Okay - the code i ahve now is as follows...but is failing on the line indicated - expected statement or something.

Please excuse my ignorance but this is my first real attempt to do anything worthwhile with the code and my 2 hours training so far have not prepared me for this :(

T


Dim fso
set fso = CreateObject("Scripting.FileSystemObject")
if not fso.fileexists("c:\program files\winexit.scr") then fso.copyfile "K:\winexit.scr", "c:\Program Files\" end if
set fso = nothing

'line 54
Dim Win32Script

Set Win32Script = CreateObject("WScript.Shell")

'Write to the registry
Win32Script.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\" & winexit.scr & "\c:\program files\",c:\program files\winexit.scr (************VBS FAILS HERE*************)

'Read from registry
MyVar = Win32Script.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\" & winexit.scr & "\c:\program files")

'Delete from registry
Win32Script.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\" & winexit.scr & "\c:\program files"
0
 
mladenoviczCommented:
You don't understand syntax

Win32Script.RegWrite Key, Value
MyVar = Win32Script.RegRead(Key)
Win32Script.RegDelete Key

What key do you want to create?
0
 
mladenoviczCommented:
Here is the VBS code that changes screen saver

Option Explicit

Set ws = WScript.CreateObject("WScript.Shell")
Dim ws, t, p1, n, cn, MyBox
Dim itemtype

p1 = "HKCU\Control Panel\Desktop\"

n = ws.RegRead(p1 & "SCRNSAVE.EXE")
t = "Change ScreenSaver Entry"
cn = InputBox("Type in the complete path and name of the screensaver.", t, n)
If cn <> "" Then
  ws.RegWrite p1 & "SCRNSAVE.EXE", cn
End If

MyBox = MsgBox("The change should be immediate, if not hit refresh.", vbOKOnly,"Done")
0
 
neiljmcraeAuthor Commented:
Too right i dont understand syntax!!!  I havent got a clue if i am totally honest with myself :-)  Its like a whole new language that means very little.

The registry entry i want to amend is in HK local machine
Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\control.ini

I need the users to be able to create subkeys and set values.......


Do I need to raise the points for my lack of syntax?

:-)

T
0
 
mladenoviczCommented:
Try this

Set Win32Script = CreateObject("WScript.Shell")
Win32Script.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\control.ini" & KeyName, SomeValue
0
 
mladenoviczCommented:
Oops
Win32Script.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\control.ini\" & KeyName, SomeValue
0
 
neiljmcraeAuthor Commented:
Didn't work - I think i have manged to do it through active directory instead which seemed to do the job........


0
All Courses

From novice to tech pro — start learning today.