Solved

Changing local registry settings with a VB Script

Posted on 2004-09-17
14
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for VB6 code to read SQL table export it to ascii 8 47
vbModal 12 66
backup program with robocopy 6 74
Powerpoint 2013: Change cell reference in excel link 3 122
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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