Solved

Set Windows 7 Screen Saver Programmatically

Posted on 2013-12-05
3
715 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count7 challenge 12 70
Put text in a picture ASP.NET C# 2 37
WPF issue with Trigger 2 69
using web browser with BING 40 89
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now