Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable screensaver using vbs

Status
Not open for further replies.

thuis

Technical User
Jan 19, 2005
7
NL
Hi,

I am looking for a way to disable the screensaver on computernames. This can't be done using GPO because this is a user setting. I specificaly want this on "computername".

We are using XP. I've allready tested some scripts from this site but none of them seem to work for me.

Does someone has any idea or can help me with this problem.

Thanks in advance
 
there are a number of posts on this matter giving details of which reg keys to set to change the screensaver.
what scripts have you been using and what specifically is your 'problem'???
 
The problem is that the script is adjusting the registry setting as it's supposed to. But nothing happens.

When I look in the registry everything is set correctly. When I look in the GUI it's still the same.

Sorry for not making this clear.
What i am looking for is a script that will take a look at a txt/xls file to see on what computernames the screensaver needs to be disabled.

Thanks,
 
Currently i am using this script to disable the screensaver... this is working perfectly!

************************************************************
'********************************set up varaibles for computer****************************************
HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")



'**********************Create screensaver active key and set to active********************************'

objReg.createkey HKEY_CURRENT_USER, strKeyPath, ValueName

'***set variable strkeypath***
strKeyPath = "Control Panel\Desktop"

'***set variable valuename***
ValueName = "ScreenSaveActive"

'***set variable strvalue***
strValue = "0"

'***update registry with settings***
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue

End If
*********************************************************

Can you maybe help with creating something that the normal logon script will look at a txt document. When the computer how is logging on is in that file, the screensaver will be disabled.
have any idea's?

thanks
 
you could maintain a txt file in your %logonserver%\netlogon share. then use FSO.OpenTextFile
strIniFileName = WshShell.ExpandEnvironmentStrings("%logonserver%\netlogon\ssavermnames.ini")
If FSO.FileExists(strIniFileName) Then
Set tsIni = FSO.OpenTextFile(strIniFileName)
Do While Not tsIni.AtEndOfStream
sLine = ""
sLine = Trim(tsIni.ReadLine)
If sLine <> "" Then
If LCase(sLine) = LCase(strComputerName)
'call your registry sub?
Call writeRegistry()
Exit Do
End If
End If
Loop
tsIni.Close
Set tsIni = Nothing
End If
 
to be honest with you i would advise against using the WMI way of changing registry keys. mainly cause it is slower compared to a basic WshShell.RegWrite. if your using this for a logonscript i would suggest speed is one of the key factors. plus not using WMI reduces an additional dependancy
 
I'm really new in this scripting so to be honest back to you I don't know what you mean... :)

We allready had an logon script and I'm just trying to get this implemented in the logon script.

Is it possible to let the Logon script look at the txt file, and when the computername is in there, it's starting a different .vbs (the one that will disable the scr saver).

I just hoped that this could all be done using GPO but unfortinatly Microsoft didn't make this possible.

What would you reccomend?
Thanks for you help so far!!
 
calling an additional vbscript will take more time.
especially if the user is on a RAS connection or something.
for this small task i would advise including all the code into your existing logon script.

have 2 subs

Sub machineCheck()
'containing the code i posted
'this sub then calls the
End Sub

Sub writeRegistry()
'containing your registry changes
End Sub

if you keep them in 2 seperate subs and call the first sub at the end of you logonscript then you maintain some level of extraction
 
**********************************************************
HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strIniFileName = WshShell.ExpandEnvironmentStrings("\\nlsaso002m\nlsasoscrips\ssavermnames.ini")

If FSO.FileExists(strIniFileName) Then
Set tsIni = FSO.OpenTextFile(strIniFileName)
Do While Not tsIni.AtEndOfStream
sLine = ""
sLine = Trim(tsIni.ReadLine)
If sLine <> "" Then
If LCase(sLine) = LCase(strComputerName)
'call your registry sub?
objReg.createkey HKEY_CURRENT_USER, strKeyPath, ValueName

'***set variable strkeypath***
strKeyPath = "Control Panel\Desktop"

'***set variable valuename***
ValueName = "ScreenSaveActive"

'***set variable strvalue***
strValue = "0"

'***update registry with settings***
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue

Exit Do
End If
End If
Loop
tsIni.Close
Set tsIni = Nothing
End If

************************************************************

Should this be working? I've implemented a file on the \\nlsaso002m\nlsasoscripts\ that is containing the computernames.
Some how it's not working yet.
I don't know exactly what you mean by using 2 subs??

As you probably allready noticed I've never used .vbs before.. Sorry for my probably 'stupid'questions :)

thanks Again!
 
you only need to create the objReg (which takes the time) if the machine name is found in the ssavermnames.ini file.
do you have a FSO object and WshShell object already declared at the top of the script?
do you already have a strComputerName declared? if yes then you will not need the first 3 lines


Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
strComputerName = WshShell.ExpandEnvironmentStrings("%computername%")

strIniFileName = WshShell.ExpandEnvironmentStrings("\\nlsaso002m\nlsasoscrips\ssavermnames.ini")

If FSO.FileExists(strIniFileName) Then
Set tsIni = FSO.OpenTextFile(strIniFileName)
Do While Not tsIni.AtEndOfStream
sLine = ""
sLine = Trim(tsIni.ReadLine)
If sLine <> "" Then
If LCase(sLine) = LCase(strComputerName)
'call your registry sub?
HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.createkey HKEY_CURRENT_USER, strKeyPath, ValueName

'***set variable strkeypath***
strKeyPath = "Control Panel\Desktop"

'***set variable valuename***
ValueName = "ScreenSaveActive"

'***set variable strvalue***
strValue = "0"

'***update registry with settings***
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
Set objReg = Nothing
Exit Do
End If
End If
Loop
tsIni.Close
Set tsIni = Nothing
End If
 
Thanks for the help!

I've got only "one" problem left.... The screensaver isn't disabeling.'The registry settings are adjusting correctly but the screensaver still pops up.

I'm looking for the right key now and when I find this I'll change the script and then it should be working fine.

Thanks a lot
 
Well I'm in the last stage now.
the script is created and is working perfectly. Now the only problem that is still here is the following:

You have to have administrator rights to adjust the registry. Looking in this forum I don't find a solution for this "small" :) problem.

Do you know a workaround? I've tried "runas" but this doesn't do the trick.

thanks again!
 
Which key did you end up changing to make it work? I was working with this a few weeks ago, and the only one I thought worked was changing the screen saver executable path name to be nothing. Worked on my machine, but the end users said that it was still popping up on their machines. I eventually just said forget it and did it by username....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top