Solved

Changing local registry settings with a VB Script

Posted on 2004-09-17
14
218 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now