After a lot of research I have figured out (sort of) How to get and then set then screen saver time out using VB.Net. What I have doesn't seem to be working. I have managed to figure out that what I have done is VB6 code and not VB.Net. I just can't seem to figure out how and where to convert it.
'Declare Monitor Resolution Function"
Public Function GetScreenSize(ByVal ScreenNumber As Integer) As String '<-- this function returns a string
Dim resX As Integer = Screen.AllScreens(ScreenNumber).Bounds.Width
Dim resY As Integer = Screen.AllScreens(ScreenNumber).Bounds.Height
Return resX.ToString & " X " & resY.ToString '<-- the integers should be converted to a string
End Function
'Declare System Parameters Funtion For Get and Set Screen Saver'
Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" (ByVal uAction As Integer, _
ByVal uParam As Integer, ByRef lpvParam As Integer, _
ByVal fuWinIni As Integer) As Integer
Private Const SPI_GETSCREENSAVETIMEOUT = 14
Private Const SPI_SETSCREENSAVETIMEOUT = 15
Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPIF_SENDWININICHANGE = &H2
'Declare Function to return the screen saver's timeout value in seconds
Public Function GetScreenSaverTimeOut() As Integer
'Returns Screen Saver Time Out in minutes
Dim lRet As Integer
Dim lSeconds As Integer
lRet = SystemParametersInfo _
(SPI_GETSCREENSAVETIMEOUT, 0, lSeconds, 0)
If lRet > 0 Then
GetScreenSaverTimeOut = lSeconds / 60
Else
'return -1 to indicate error condition
GetScreenSaverTimeOut = -1
End If
End Function
Public Function SetScreenSaverTimeOut(ByVal NewValueInMinutes _
As Integer) As Boolean
'Sets Screen Saver Timeout in Minutes
Dim lRet As Integer
Dim lSeconds As Integer
lSeconds = NewValueInMinutes * 60
lRet = SystemParametersInfo _
(SPI_SETSCREENSAVETIMEOUT, lSeconds, ByVal 0&, _
SPIF_UPDATEINIFILE + SPIF_SENDWININICHANGE)
SetScreenSaverTimeOut = lRet <> 0
End Function
I am calling the GetScreenSaverTimeOut() function and comparing it to <> 14 for fourteen minutes. If it is it continues if it doesnt it will diplay a button to adjust it to 14 mins. That part is working.
For the SetScreenSaverTimeOut I am getting an "Expression Error" at "ByVal 0&". I have been reading for hours and cant figure out how and where to convert it.
Rab