Results 1 to 7 of 7

Thread: Screen Savers

  1. #1
    Guest
    I need to keep users from changing the screen saver on win9x machines. I know that the screen saver pathe is in the system.ini and that is where Windows looks for the current saver. I have tried to use the getprivateprofilestring on a timer with the writeprivateprofilestring if the screen saver is changed. The problem is that it looks like it is reading the file from cache and of wirting to the file in cache. Maybe I am heading in the wrong direction or I am missing something with the I/O on the ini file thing. Help?
    Private Sub Form_Load()
    timeStamp = FileDateTime(WinPath & "\system.ini")
    End Sub
    Private Sub RegTimer_Timer()
    Dim Ret As Variant
    Dim RetStr As String
    Dim NetPath As String
    Dim NowStamp

    NowStamp = FileDateTime(WinPath & "\system.ini")
    If NowStamp = timeStamp Then
    Exit Sub
    End If

    Const BufSize = 500
    RetStr = Space(BufSize)
    Ret = GetPrivateProfileString("boot", "scrnsave.exe", "", RetStr, BufSize, WinPath & "\system.ini")
    NetPath = Left(RetStr, Ret)

    If NetPath = WinPath & "\My.scr" Then
    ' Reset the time stamp check on file.
    timeStamp = FileDateTime(WinPath & "\system.ini")
    Exit Sub
    Else
    WritePrivateProfileString "boot", "scrnsave.exe", WinPath & "\My.scr", WinPath & "\system.ini"
    MsgBox "The Screen Saver cannot be changed!", vbCritical, "Notice:"
    timeStamp = FileDateTime(WinPath & "\system.ini")
    End If
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Rather then looking to see if the user has changed your screensaver, why not just remove the option in the control panel. All you have to do is set on registry key, and users will have to manually edit the system.ini in order to make any changes. The registry key to edit (or add if missing) is:

    Path:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System
    Key:
    NoDispScrSavPage
    Value:
    REG_DWORD
    0=disabled (screensaver option is in the control panel)
    1=enabled (screensaver option is removed from control panel)

    I know this works for NT/Win2000, but I have never tried it on Win95/98.

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Ok, then I have two suggestions.
    1) When you are changing the system.ini file, you have to notify windows of the change. Otherwise, changes in the file will have no effect. (Until windows finally gets around to looking). This is done using the sendmessage API call. Try inserting it after writing the new value to the system.ini file and see if that helps.

    2) Checking the system.ini file will only be successful if your users are using Win95/98 machines. In Win2000 (what I use), the screensaver info is not saved in the system.ini file, but I believe is stored in the registry. I think that this is probably true for WinNT as well.

    Hope this helps.

  4. #4
    Guest

    Question Sounds good but...

    The sendmessage sounds what I need. Can you give me an example?

  5. #5
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Sure:

    Here is an example that I use to change the default printer that is written in the win.ini:

    For the module:

    Code:
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Const WM_WININICHANGE = &H1A
    Public Const HWND_BROADCAST = &HFFFF&
    For the form:
    (Please note that fWriteValue and fReadValue are custom functions that I use to read/write ini. files. Substitute whatever you are using to read/write ini file here.)

    Code:
    Dim lResult As Long
    Dim lRes As Long
    
    lResult = fReadValue("C:\Windows\Win.ini", "Windows", "device", "S", "", sSetting)
    lResult = fWriteValue("C:\Windows\Win.ini", "windows", "device", "S", "HP LaserJet 5M, HPPCL5G,HP_12360D_IP")
    lRes = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "Windows")
    Hope this helps.

  6. #6
    Guest

    I am missing something....

    I get the sendmessage idea but in the module with the Public Const WM_WININICHANGE = &H1A is the &H1A an address for the file and if it is how do find it for the system.ini or any other file for that matter.

    I am still new at this, please be patience with me, Thanks.

  7. #7
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Sorry,

    The WM_WININICHANGE is used to broadcast changes in the
    win.ini file.

    Unfortunately, there isn't a const variable that works just for the system.ini file (at least none that I am aware of. So what you will want to do is use the following syntax:

    Code:
    Private Sub Command1_Click()
    Dim lResult As Long
    Dim sSetting As String
    
    Dim lRes As Long
    lResult = fReadValue("C:\Windows\system.ini", "boot", "SCRNSAVE.EXE", "S", "", sSetting)
    lResult = fWriteValue("C:\Windows\system.ini", "boot", "SCRNSAVE.EXE", "S", "HP LaserJet 5M, HPPCL5G,HP_12360D_IP")
    lRes = SendMessage(HWND_BROADCAST, 0, 0, ByVal "Windows")
    
    End Sub
    Instead of using the WM_WININICHANGE, I used a 0. This tells windows to broadcast the change over all of windows, rather then just broadcasting a specific change. You will have to test it, but this might not work for Win95. I know that it has a different broadcast structure then Win98+. But this does work for Win98, and NT(Win2000) machines.

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width