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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I update Win2K registry value? 2

Status
Not open for further replies.

Nittany92

MIS
May 28, 2002
10
US
I'd like to use VB 6.0 to update the registry value ScreenSaveTimeOut located in HKEY_CURRENT_USER\Control Panel\Desktop.

How do I do that? What, if any, references or components do I need to include, etc.?

I'm still relatively new to VB programming, so I'll need as much detail as you are willing to type.

Thank you in advance!
~Nittany92~
 
Wow! That's more involved than I expected. Anyhow, thanks for the info! %-)
 
For something as straightforward as this there are easier methods

Here's how to read it:
Code:
[blue]Debug.Print CreateObject("WScript.Shell").RegRead("HKCU\Control Panel\Desktop\ScreenSaveTimeout")[/blue]
Here's how to write it:
Code:
[blue]CreateObject("WScript.Shell").RegWrite "HKCU\Control Panel\Desktop\ScreenSaveTimeout", 600[/blue]
 
Thanks! That worked great. Now, how do I "apply" that change so that Windows knows I changed the value? Or, how do I get Windows to use the new value?
 
Ah,, well now you are moving into a different area. Probably easiest to achieve all this with the SystemParametersInfo API call, eg:
Code:
[blue]Option Explicit

Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

Public Const SPI_GETSCREENSAVETIMEOUT = 14
Public Const SPI_SETSCREENSAVETIMEOUT = 15
Public Const SPI_GETSCREENSAVEACTIVE = 16
Public Const SPI_SETSCREENSAVEACTIVE = 17
Public Const SPIF_SENDWININICHANGE = &H2
Public Const SPIF_SENDCHANGE = SPIF_SENDWININICHANGE

Public Sub UpdateScreenSaverSettings()
    'a demo
    
    Dim lCurrentTimeout As Integer
    Dim lDummy As Long
    Dim lNewTimeout As Long
    
    ' Get the current timeout
    SystemParametersInfo SPI_GETSCREENSAVETIMEOUT, lDummy, lCurrentTimeout, 0&
    Debug.Print lCurrentTimeout
    
    ' Set a new timeout
    lNewTimeout = 600
    SystemParametersInfo SPI_SETSCREENSAVETIMEOUT, lNewTimeout, lDummy, 0&

    ' Make the screen saver active, and advertise that we have changed system settings
    SystemParametersInfo SPI_SETSCREENSAVEACTIVE, True, lDummy, SPIF_SENDCHANGE
End Sub
[/blue]
 
That's a very useful piece of information. I've emailed it to myself for reference. And you get a star. Thanks.



Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
strongm,

First, thank you! I appreciate your help. Second, I copied your code exactly and pasted it into a module and created a button to Call UpdateScreenSaverSettings.

I get:
[blue]Run-time error '49':
Bad DLL calling convention[/blue]

I stepped through each line in debug mode and the error occurs right after the End Sub of UpdateScreenSaverSettings.

However, if I copy the code from UpdateScreenSaverSettings and paste it directly to the Command1_click subroutine, it works.

Two questions though...
[ol]
[li]Why can't I call the UpdateScreenSaverSettings from a button click?[/li]
[li]The ScreenSaverTimeout value in the registry didn't change, but if I look at the screen saver properties from Control Panel it reflects the new timeout value. What's going on? Where is it storing the new value?[/li]
[/ol]

~Nittany92~

 
Oops.

Change

Dim lCurrentTimeout As Integer

to

Dim lCurrentTimeout As Long
 
Hey, that worked. Thanks.
If you have a minute, can you fill me in on my second question above?
 
Strongm is on vacation I believe, try changing:

Dim lCurrentTimeout As Integer

to

Dim lCurrentTimeout As Long




Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Never mind.[blush]



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top