SystemParametersInfo Failing in VB.net

G

Guest

I'm using a SystemParametersInfo call to attempt to manage the screen saver.
All I want to do is modify the ScreenSaveActive bit in the registry and have
the OS recognize it (and occasionally set it back to -0-). Theoretically this
should be easy to accomplish through the call shown below. If I trace the
call with SysInternals (si)Registry Monitor I can see the call being made.
Unfortunately in the si QueryValue for the key
HKCU\Software\Policies\Microsoft\Windows\Control
Panel\Desktop\ScreenSaveActive I'm getting a result of BUFOVRFLOW (which I
assume is the trace tool unable to read the value). The value in the registry
does not change.

We do have a forced screen saver GPO applied which I suspect may be causing
the failure. I have checked registry permissions and all is ok on this key.
I've used the SPIF_SENDWININICHANGE parameter with no luck. The following
call is about as basic as I can get for troubleshooting this problem. Any
ideas?

VB.net 1.1, Win2KPro (and XPPro) Also tried C++6.0 and VB6.0.


VB.net call

Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal _
uParam As Long, ByVal lpvParam As Long, ByVal fuWinIni As _
Long) As Long

Private Function SetScreenSaver(ByVal Active As Boolean) As Long
Dim lActiveFlag As Long = 0
If Active = True Then lActiveFlag = 1
Return = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, 0, 0)
End Function


-Mike
 
I

Imran Koradia

Change all the Longs to Integers. Longs from VB 6.0 convert to Integers in
VB.NET (both are 32-bit integers). That should most likely be the reason for
the failure in VB.NET.

hope that helps..
Imran.
 
G

Guest

Thanks for the quick response Imran!

Actually the code I posted was from one of the tests where I had just
changed those from integers. Unfortunately it didn't make a difference but
I'll post the corrected code below.

Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal _
uParam As Integer, ByVal lpvParam As Integer, ByVal fuWinIni As _
Integer) As Integer

Private Function SetScreenSaver(ByVal Active As Boolean) As Integer
Dim iActiveFlag As Integer = 0
If Active = True Then iActiveFlag = 1
Return SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, iActiveFlag, 0, 0)
End Function
 
I

Imran Koradia

Try using this instead:

Private Const SPI_SETSCREENSAVEACTIVE As Integer = 17
Private Const SPIF_SENDWININICHANGE As Integer = &H2
Private Const SPIF_UPDATEINIFILE As Integer = &H1

Return SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, iActiveFlag, _
0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)


hope that helps..
Imran.
 
G

Guest

Still no luck. The call looks like it's going through to user32.dll, but it's
not executing completely or properly. I am getting a return value of 0.

When I look at the registry trace I'm seeing a successful "OpenKey" request
to HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop. The next
entry "QueryKey" HKCU\Software\Policies\Microsoft\Windows\Control
Panel\Desktop\ScreenSaveActive fails with a result of BUFOVRFLOW. The third
and final trace entry of "CloseKey"
HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop completes
successfully.
 
I

Imran Koradia

Ok..I'm officially stumped :-S

One reason for BUFOVRFLOW is that the key does not exist in the registry. On
my machine, I have the ScreenSaveActive key under HKCU\Control Panel\Desktop
which is different from whats showing in your registry trace. I'm not sure
if this has got anything to do with that. Its working fine on my machine -
the value changes from 1 to 0 and vice versa correctly.
Any viruses, trojans, etc? Corrupt registry, etc?

Can't think of anything else..sorry.

Imran.
 
G

Guest

I have a feeling it may have to do with the application of the screen saver
GPO. Whatever is telling user32.dll to look at the policy location in the
registry may also be saying - do not modify. Obviously if a policy was
applied, you wouldn't want a local application to overwrite it. Conversely, I
can edit the registry directly without a problem but the OS doesn't get
notified until a logoff/logon or reboot (and then the policy is reapplied).

I've gone the other route and modified the registry directly and used
SendMessage to notify the OS about the change. Unfortunately it reads just
about every configuration entry in the registry except the screen saver one.

I've tested on several PC's (5), off domain, on domain, off policy, separate
location, etc. All of them incur the same issue. No known viruses, trojans or
corrupt registries on any of them.

Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top