Solved

Set Windows 7 Screen Saver Programmatically

Posted on 2013-12-05
3
763 Views
Last Modified: 2013-12-06
Experts, i made a program a long time ago to run under Windows XP. The program ran a timer and every so often it would look at a text file on an ftp server to get the string text to set the marquee screen saver. The program would then force the screen saver back to marque and set the text to what it retrieved from the text file. I would like to get this running on my Windows 7 64 bit machine. I know that the marquee screen saver is gone so i would use the 3D text screen saver that comes with Windows 7. I'm embarrassed but i dont really understand what i was doing here exactly. Would one of you please run through this code with me and point out any changes that need to be made to use it on my windows 7 machine and to use the 3D text screen saver instead of the marquee.

Thanks...

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const ERROR_SUCCESS = 0&
Private Const REG_SZ = 1
Private XX As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private WithEvents ftp As ChilkatFTP
Private WithEvents systemTimer As ccrpTimer

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Sub Form_Load()

    Me.Hide
    
    App.TaskVisible = False
    
    Set ftp = New ChilkatFTP
    
    ftp.HostName = "ftp.myFtp.com"
    ftp.Username = "FTPme"
    ftp.Password = "FTPaccess"
    
    Set systemTimer = New ccrpTimer
    
    systemTimer.Interval = 900000
    systemTimer.Enabled = True

End Sub

Private Sub Form_Unload(Cancel As Integer)

    If systemTimer.Enabled = True Then systemTimer.Enabled = False
    If ftp.IsConnected = True Then ftp.Disconnect

    If Not systemTimer Is Nothing Then Set systemTimer = Nothing
    If Not ftp Is Nothing Then Set ftp = Nothing

End Sub

Private Sub MousePos(ByRef X As Long, ByRef Y As Long)

    Dim Mouse As POINTAPI
    
    GetCursorPos Mouse
    X = Mouse.X
    Y = Mouse.Y

End Sub

Private Sub RealMousePos(ByRef Point As POINTAPI)

    Point.X = Point.X * (65536 / GetSystemMetrics(0))
    Point.Y = Point.Y * (65536 / GetSystemMetrics(1))

End Sub

Private Sub SaveString(Hkey As Long, strpath As String, strValue As String, strData As String)

    Dim keyhand As Long
    Dim r As Long

    XX = RegCreateKey(Hkey, strpath, keyhand)
    XX = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    XX = RegCloseKey(keyhand)

End Sub

Private Sub SetX(X As Long)

    Dim Mouse As POINTAPI
    
    GetCursorPos Mouse
    Mouse.X = X
    RealMousePos Mouse
    mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0

End Sub

Private Sub systemTimer_Timer(ByVal Milliseconds As Long)

    systemTimer.Enabled = False
    
    Dim fileStr As String
    
    On Error GoTo ftpError
    
    success = ftp.Connect
    
    If success = 1 Then
        
        ftp.ChangeRemoteDir "Transfer"
        
        fileStr = ftp.GetRemoteFileTextData("accessFile.txt")
        
        systemProcess (fileStr)

    End If
    
    systemTimer.Enabled = True
    
    Exit Sub
    
ftpError:

    systemTimer.Enabled = True

End Sub

Private Sub systemProcess(strData As String)

    Dim X As Long, Y As Long, lngHWand As Long
    
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "Text", strData
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "TextColor", "255 0 0"
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "BackgroundColor", "0 0 0"
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "Speed", "3"
    SaveString HKEY_CURRENT_USER, "Control Panel\Desktop", "SCRNSAVE.EXE", "C:\WINDOWS\system32\ssmarque.scr"
    SaveString HKEY_CURRENT_USER, "Control Panel\PowerCfg", "CurrentPowerPolicy", 1
    
    'Wait for netsh to finish creating the text file.
    lngHWnd = Shell("powercfg.exe /CHANGE Portable/Laptop /monitor-timeout-ac 0", vbHide)
    
    MousePos X, Y
    
    SetX X + 5

End Sub

Open in new window

0
Comment
Question by:Basicfarmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 39702125
total bluff:

change
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "Text", strData
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "TextColor", "255 0 0"
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "BackgroundColor", "0 0 0"
    SaveString HKEY_CURRENT_USER, "Control Panel\Screen Saver.Marquee", "Speed", "3"
    SaveString HKEY_CURRENT_USER, "Control Panel\Desktop", "SCRNSAVE.EXE", "C:\WINDOWS\system32\ssmarque.scr"
    SaveString HKEY_CURRENT_USER, "Control Panel\PowerCfg", "CurrentPowerPolicy", 1

Open in new window


to

    SaveString HKEY_CURRENT_USER, "Control Panel\Desktop", "SCRNSAVE.EXE", "C:\WINDOWS\system32\ssText3d.scr"
    SaveString HKEY_CURRENT_USER, "Control Panel\PowerCfg", "CurrentPowerPolicy", 1

Open in new window

0
 

Author Closing Comment

by:Basicfarmer
ID: 39702228
Hi MerijnB, thanks for your help. I figured that was all i need at that point but i was a little lost regarding the settings for the 3DText screen saver. I thought i would set my screen saver on my machine to be 3DText and then set the text property to something that would not be in the registry like "Diet Dr Pepper". Then i searched the registry for that string and found all of the settings.

I made this program a long time ago and i was able to piece meal it together with a lot of searching on EE. It is actually quite a fun program. There is a guy in our office that likes to go around when people are out of town and change their screen savers. That is why i wanted control of mine in this fashion. I also send it different messages every so often addressed directly to him so that when he looks at my pc it might say something like "Dont Mess With Me Dave". It has really messed with his head because he might get the screen saver changed and then the next time he walks by my pc it is put right back and has another message for him. The word around the office is that people will check in every now and then to see what my screen saver says about him next. I have a couple of confidants in the office that will feed me information about what he is doing or something so that i can send relevant messages.

I noticed you said it was a bluff, i didn't realize what i was doing was so obvious. Anyway i appreciate your help.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 39702235
Great it worked :)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

732 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