Solved

Changing local registry settings with a VB Script

Posted on 2004-09-17
14
241 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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