Solved

Changing local registry settings with a VB Script

Posted on 2004-09-17
14
222 Views
Last Modified: 2010-05-02
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

0
Comment
Question by:neiljmcrae
  • 8
  • 5
14 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12082525
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
 

Author Comment

by:neiljmcrae
ID: 12083041
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
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12083099
This is just an example. You can use Win32Script.RegWrite,Win32Script.RegRead and Win32Script.RegDelete methods
0
 

Author Comment

by:neiljmcrae
ID: 12083154
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
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12083248
0
 

Author Comment

by:neiljmcrae
ID: 12083408
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:mladenovicz
ID: 12083461
You don't understand syntax

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

What key do you want to create?
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12083534
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
 

Author Comment

by:neiljmcrae
ID: 12083599
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
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12083661
Try this

Set Win32Script = CreateObject("WScript.Shell")
Win32Script.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\control.ini" & KeyName, SomeValue
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12083669
Oops
Win32Script.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\control.ini\" & KeyName, SomeValue
0
 

Author Comment

by:neiljmcrae
ID: 12085786
Didn't work - I think i have manged to do it through active directory instead which seemed to do the job........


0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 500 total points
ID: 12563765
I don't know. Code I posted works for me, but not for neiljmcrae.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now