Logan 5

Loc: California
Registered on 03-10-08
|
03-11-08 09:59 PM - Post#161425
Help. I need to find a program that will stop our network's mandated screen saver from coming on after just 20 minutes.
I teach in a school district that has gotten annal about the network
(to preserve IT jobs during state budget cuts), implementing this new
screensaver for all pc's. Problem is that I have my pc hooked to an LCD
and use it to show powerpoint lessons, videos, Flash files, etc. to the
class. If I don't remember to go move the mouse within 19 minutes or
so, then I have to log back into the computer.
Any help would be greatly appreciated. Ironic how they tell us to use technology in the classroom, then limit its capability.
Thank you!
No Matter Where You Go, There You Are. |
|
Average Midget
Registered on 03-04-08
|
Re: Trying to Stop Network Screensaver 03-11-08 11:57 PM - Post#161436
In response to Logan 5
I'm going to assume this is Windows and probably not Vista.
It depends on how "hard" they've locked the computer down. I'm going to
also assume they've disabled the "Screen Saver" tab. There is something
that can be tried but if they remotely administer the settings, or have
some scripts that run at log on, to reset everything, I'm not sure
there's much you can do.
You might want to also think about the possibility of getting into
trouble before trying what I'm going to show you. I don't want to get
you fired for messing with the settings.
There's a good chance that the Admin has also disabled this, if so, this is moot; it doesn't hurt to try.
Go to "Start", "Run" and type gpedit.msc If
they've disabled the "Run" window, you can type the same thing into the
command promp (%SystemRoot%\System32\cm d.exe). This is the Group
Policy Editor. There are a lot of things that you can tweak in there,
so you (everyone) might want to browse through, you know, for fun!
Provided they haven't locked you out from starting it, you're going to
want to go to "User Configuration", "Administrative Templates",
"Control Panel", "Display".
On the right side you'll see some policies for the screen saver. If you
double-click on them, it'll bring up a dialog that lets you enable or
disable the policy. There's also a tab that explains what the policy
does, so you might want to give that a read.
If you wanted to go high-tech, and you knew windows programming, you
might be able to write a utility that requested a handle to the desktop
and used the SendMessage() API function and pass in a WM_LBUTTONUP
parameter. In theory, that would work. Of course, now I'm going to have
to try it and see, or it's going to drive me crazy. If it works, I'll
pass it on to you.
Just to be silly:
If you wanted to go MacGyver on it, you could get a timer and a motor,
from Radio Shack, and rig up a mouse pad that would move every 10
minutes. Who doesn't want to try that little project?
|
Curse

Loc: Louisiana
Registered on 03-11-05
|
Re: Trying to Stop Network Screensaver 03-12-08 06:31 AM - Post#161444
In response to Average Midget
How about disconnecting the laptop from the network?
|
Average Midget
Registered on 03-04-08
|
Re: Trying to Stop Network Screensaver 03-12-08 09:22 AM - Post#161461
In response to Curse
If they've got it locked down and they're running logon
scripts to reset everything, it wouldn't matter if you were connected,
or not.
So, I worked on my little idea. It turns out that sending a
WM_LBUTTONUP message, to the desktop, doesn't do it. I did find a way
to trap the screensaver messages (SC_SCREENSAVE and SC_MONITORPOWER),
which will stop it from coming on, but there is a problem. My program
will only capture those messages if it is the active window. If it's
minimized, or another window has focus, the screensaver will still come
on. I'll have to revisit that issue another time.
I'll attach it, in case you want to play with it. It is a stand-alone exe so feel free to run a virus scan before you run it.
It's quickly hacked together, so it's neither pretty or feature-rich.
|
Average Midget
Registered on 03-04-08
|
Re: Trying to Stop Network Screensaver 03-14-08 05:53 AM - Post#161672
In response to Average Midget
Just a little update on my progress...yes, I've
been up all night and I do have to go to work in 10 minutes. Good thing
I only have to use heavy machinery today.
I got it working! I'm actually very excited about this. My place of
employment has this same issue. If I walk away from my desk (which I
have to do quite often), for more than 15 minutes, it turns on the
screen saver and logs me out. It's very annoying, especially if I just
need to check something really quick.
Anyway, as stated before, the program traps the SC_SCREENSAVER and
SC_MONITORPOWER messages sent by windows. The problem was, I could only
capture them if my program was the currently active application. I
found a technique sometimes refered to as "dll injection". I had to
create a dll (dynamic-link library) that has a single "hook" function
that Windows "injects" into the currently running processes. It needs
to be seperate from the exe so that Windows can hand it to the other
running programs. Once it's injected into the programs, it monitors for
those same two messages (except this time globally) and filters them
out, before Windows can process them, thus stopping the screen saver
from coming on.
I'm not going to post it just yet, because I wanted to clean up the
code and also try to make it minimize to the system tray, to get it
completely out of the way. Cleaning up the code means I have every
intention to, not only post the program, but also post the source code.
It's written in C and Win32 with Visual Studio V6. That means it should
work on everything from Windows 95 to Vista. I will only be able to
test Windows 2000 and Windows XP. Like the other version posted, you
can still allow the screen saver to come on, if you want. It's really
close to the weekend, so I'm sure I'll be able to put more time in to
get this finished. Hopefully someone can use it, besides "Logan 5" and
myself.
Please excuse any mistakes I may have made, for I've been up for 24 hours.
Disclaimer: I do not program for a living. I actually work in a
completely different profession. Programming is just a hobby, that I
love. That basically means: while I'm trying my best not to write crap
code, I might not know any better. It has only been 1.5 years since I
started teaching myself C/C++.
|
SlyFerret

Loc: Delaware, Ohio
Registered on 12-19-06
|
Re: Trying to Stop Network Screensaver 03-14-08 07:57 AM - Post#161695
In response to Average Midget
Am I the only one that is bothered by the fact
that a user on a network is trying to install programs and override
configuration options that have been put into place by the IT
department?
Please keep in mind that depending on your organization's policies on
use of computer equipment, this type of thing can be "career limiting".
Too many people want to think that the computers at work are just like
their computer at home. The computer does not belong to you, and you do
not have the right to modify or override policies that are set in place
by the IT department.
Move the mouse ever 19 minutes and get on with life.
-SF
Had this been an actual emergency, we would have fled in terror, and you would not have been notified. |
|
Average Midget
Registered on 03-04-08
|
Re: Trying to Stop Network Screensaver 03-14-08 07:29 PM - Post#161740
In response to SlyFerret
I should point out that this software does not
install anything, it does not write anything to the registry and it
does not write anything to the file system. It is a single exe and a
single dll that, when run, stay completely in memory, nothing else.
I, personally, don't have an issue with turning off a dopey screen
saver. I might add that I could easily do far worse things, to get
around it. One of which would be to run a bootable linux CD and reset
the Admin password, that's stored in the SAM file. I feel as if I'm
being considerate, by trying to find a polite way to make my day a
little more productive. I don't work on highly classified documents in
a public forum. I work in a locked building, with about 40 people, that
all have access to the same data that I do. I'm not sure I really need
to worry about someone coming over to my desk and spying on what I'm
doing, while I'm away. I make very frequent trips away from my computer
and it's a huge hassle to be forced to supply a user name and password,
even though I may only be coming back to verify a measurement.
I hit a snag in my software. I took it to work today, and tested it on
my workstation. What worked perfectly here at home, did not work at all
at work. My workstation locks the computer, after it's been idle for a
while. From what I read, having this option enabled bypasses the two
Windows messages that I filter out. I believe I've found a way around
it but, as I've not been to sleep yet, that is going to take priority
over testing.
If I'm figuring this out for myself, and no one is even interested in
this, I'll be glad to stop posting here, about it. It would also save
having to upload the files to Leo's site. If you want to let me know,
either way, feel free.
|
SlyFerret

Loc: Delaware, Ohio
Registered on 12-19-06
|
Re: Trying to Stop Network Screensaver 03-14-08 07:51 PM - Post#161742
In response to Average Midget
I work in the IT department for a bank. I suppose
maybe that's why I get a little jumpy when users start messing around
with the computers on the network.
-SF
Had this been an actual emergency, we would have fled in terror, and you would not have been notified. |
|
Curse

Loc: Louisiana
Registered on 03-11-05
|
Re: Trying to Stop Network Screensaver 03-14-08 10:38 PM - Post#161750
In response to Logan 5
have you tried asking the network admin? there is certain protocols most likely if he/she is professional about it
|
Logan 5

Loc: California
Registered on 03-10-08
|
Re: Trying to Stop Network Screensaver 03-16-08 09:32 PM - Post#161943
In response to Average Midget
Sorry I haven't replied to my own thread since
starting it. Two kids and the end of a grading period for the students
will keep you mighty busy.
Average Midget - Thanks for working on this problem and posting all the
info you have so far. I truly appreciate it! My sidebar knowledge is
HTML so I'm no help. I tried C++ but didn't get past week 5; just lost
interest. I did make it though 1 semester of VB5.
Oh, BTW - our new pc's are running Vista, but my older pc still has XP.
Also, I tried using the gpedit trick and it's locked. Funny, IT didn't
disable the RUN command.
Keeping my fingers crossed on your fix! 
SlyFerret - I worked in IT/Networking several years back so I know both
sides of the fence. It's one thing to secure a network, but another to
over secure it so it interferes with the users functionality and
productivity. That is where our districts' network is at now. Just last
year I didn't have to get IT's permission and spend my entire 40 min
lunch on the phone with them just to get a useful Firefox pluggin or
the latest grading program installed on my pc. Also, when was the last
time you showed a 21+ minute video to a class and had the login
screensaver come up, killing the visuals but letting the audio still
run? This just happened to me 3 times Friday.
Curse - We talked to Admin when we first heard they were going to
implement this "feature". They said we would just get used to it and
that was that.
Here's a funny... California has a $14 Bill deficit this year, so
school districts are having to cut about 10% from their budgets and
laying off teachers galore. This password screensaver keeps the
computer in active mode and never lets it enter sleep mode, so it's
always using full power. A fellow teacher figured out that our district
could save about $185,000 in power usage if the pc's were allowed to
sleep.
No Matter Where You Go, There You Are. |
|
Average Midget
Registered on 03-04-08
|
Re: Trying to Stop Network Screensaver 03-16-08 11:37 PM - Post#161945
In response to Logan 5
Since you posted, I'll give a little update on my progress.
I have since abandoned my previous way of injecting a hook (via a dll)
and capturing the messages that way. It wasn't quite working out. I did
a bunch of reading and found a far easier way of getting what I wanted.
I have put most of my weekend into tweaking this thing to get it
"nice". I have it fully working, here at home; I'll try it out and work
tomorrow. I believe my work is about as locked down as yours is. The
application is still a bit ugly, right now, so I'll have to spend some
time cleaning it up.
How it works, in case you were curious:
When the screen saver and "stand by" mode are enabled (I also enabled
the password feature for my tests), and the activation times are set
(set to turn on after 15 minutes, for example), Windows watches the
timers for each setting. If an application triggers or the user moves
or clicks something, those timers are reset. If nothing happens,
Windows will, of course, turn on the screen saver or activate stand by
mode. There are a few API calls that can let Windows know that your
application, even though it may not be triggering anything, is still
working away and it needs the system.
SystemParametersInfo() is called and passed a value of
SPI_SETSCREENSAVEACTIVE, along with a few others. This tells Windows to
enable, or disable, the screen saving feature. The odd thing is, it's
not the same one that is located on the "Screen Saver" tab. They appear
to be different settings. You can also pass in SPI_GETSCREENSAVEACTIVE
and get the current setting. That's how I found out they are not the
same. When I had the screen saver set to never come on, it reported as
being active. I use that API call to store the original setting, before
I even change it and, subsequently return it back to its original state
when either the user asks or the program exits.
SetThreadExecutionState() is an interesting one; I'm surprised your
media application doesn't call this one. You can pass in several
options (all grouped together in one unsigned long value. It just flips
different bits, depending on what you pass it). The arguments are
ES_SYSTEM_REQUIRED, ES_DISPLAY_REQUIRED and ES_CONTINUOUS. The first
two just reset the internat timers. ES_SYSTEM_REQUIRED tells Windows to
reset the timer that it watches to activate the standby mode and
ES_DISPLAY_REQUIRED resets the timer that tells Windows to shut off the
monitor. Those two are only temporary calls. That's where ES_CONTINUOUS
comes in. When ES_CONTINUOUS is passed in, along with either (or all)
of the other two, it tells Windows that the application is going to
need everything active for a while and that we'll reset the timers when
we're done. This does not effect the screen saver, that's why I had to
use the other API call.
It should work with Vista because they're all win32 API calls. The only
thing that might make it not work with Vista is the UAC (User Access
Control). I, unfortunately, won't have access to a vista machine for
over a week.
As I said, the application needs polishing but it is working. When you
minimize the application, it goes to the notification tray (down by the
clock) and you're able to enable and disable it from there. If you
hover over the icon, it will tell you the current state (either enabled
or disabled). Double-licking the icon will restore it to the desktop,
where you have several ways to enable and disable it (either by
right-clicking anywhere on the application or from within the menu).
I'm working on a graphical way of showing the current state...better
than what I have now.
That was a long-winded update..
|
HAL 9000

Loc: Chicago Illinois
Registered on 04-04-05
|
Re: Trying to Stop Network Screensaver 03-17-08 08:37 AM - Post#161966
In response to SlyFerret
Am I the only one that is bothered by the fact that a user on a network
is trying to install programs and override configuration options that
have been put into place by the IT department?
Move the mouse ever 19 minutes and get on with life.
-SF
Slys right
Its a good way to find yourself truly embarrassed WHEN the IT department finds out.
They read logs ya know...
Get permission from IT before you do something like that.
These policys are probably in place to make sure there isnt anyone logging in to your pc when your at lunch etc...
|
The Techxorcist

Loc: Winnipeg, MB
Registered on 03-10-05
|
03-19-08 02:27 PM - Post#162189
In response to HAL 9000
there are programs out there already that prevent
a screensaver from activating, most of them i've seen just nudge the
mouse a bit every couple minutes and can be run off a USB thumbdrive.
would that work instead of messing with anything on the network or
installing something?
"Patriotism is the last refuge of a scoundrel."
~ Samuel Johnson, 1775 |
|
chrishch
Loc: Toronto, Canada
Registered on 03-11-05
|
Trying to Stop Network Screensaver 03-20-08 09:21 AM - Post#162245
In response to The Techxorcist
I do understand why such a policy is needed and
it actually makes sense. I am the network admin at my company and I had
to implement this policy, but a lot of people "B" and moan about it.
However, I don't really have a choice, as it's a requirement as part of
internal controls for being a publicly traded company.
Anyway, are you allowed to change which screen saver to use and is the "(None)" screen saver still available?
If yes, then you can set it to (None) and even if your network admin
has set implemented a screen saver policy in Group Policy, and you
can't change the number of minutes to wait before the screen saver
kicks in, if you set the actual screen saver to "None", your
workstation will not get locked automatically. (Sorry, that's one long
sentence).
Just remember to set in the power options in the Control Panel that
your screen shuts off before the screen saver kicks in so that nobody
will suspect you have disabled the screen saver.
Just to be clear, I don't do this on my laptop, but it's a
"work-around" (read: loophole) that's available in Windows, and have
seen people use. I just wish they have an understanding why this is
needed.
Edited by chrishch on 03-20-08 09:25 AM. Reason for edit: No reason given.
|
Average Midget
Registered on 03-04-08
|
03-20-08 01:25 PM - Post#162262
In response to The Techxorcist
It's funny that you mention the "nudge" method.
That's ultimately what I...kind of...ended up doing. I tried to do it
the polite way, by asking Windows not to turn it on, but it never
respected my request. I should say, it worked at my house, but it
didn't work here, at work. I didn't test it, but I suspect it's because
they actually call out specific settings in the Group Policy Editor.
No, my IT guy doesn't know about that and has left it unlocked. That
means I can go in and change the settings, but I don't want to be a
total jerk.
I will post the program here when I get home. I actually made two
versions. One has a graphical interface and one is run in a command
prompt window. The command prompt one uses a little less memory, if
you're paranoid about that, but it doesn't have the option of hiding
itself in the notification tray. I'll point out that the GUI version
only uses 2mb when it's shown normal but only around 400kb when
minimized...we're not talking about a lot. I'm sure I can lean it out
more, but I've already put way too many hours into getting this thing
to work in different environments.
Again, there is no installation, nor does it write anything to the hard drive, or change any user settings.
If there's interest, I'll post the code. It was written all in Win32 and procedural C, with Visual Studio v6.0.
|
Average Midget
Registered on 03-04-08
|
Trying to Stop Network Screensaver 03-20-08 10:19 PM - Post#162297
In response to Average Midget
Here it is! The zip file contains both the GUI version and the
"lean" console version...plus a ReadMe.txt file that talks about some
options, for the GUI version. I hope there aren't any bugs, but there
probably are. Nothing that showed up during all of my testing. I don't
have a lot of error checking, because that's usually considered to be
around 80% of your code and, I really don't have that much time. If
there are any issues with it (aside from the obnoxiously gaudy
interface) let me know.
It should work on Windows NT, Windows 2000, Windows XP. It should
physically run on Vista but, according to the MSDN, the SendInput()
function could get rejected by the UIPI (User Interface Privilege
Isolation).
Quote from the MSDN library:
Microsoft Windows Vista. This function is subject to UIPI.
Applications are permitted to inject input only into applications that
are at an equal or lesser integrity level.
I'm not exactly sure what levels of "integrity" are out there, or where this application fits.
Once again, for clarity, there is no installation (it just runs), no
writing of files, no modification of user preferences, no registry
changes, no no no of anything...it just runs.
[EDIT]
I'm a little sad that Windows doesn't honor it's functions that
explicitly say "Use these functions if you want to let Windows know
that your application still needs the display". I really wish those
would've worked. I feel as if, what ended up working, is a hack
approach. That's it for my little soap box speech.
How it works: When started, the application asks Windows for the number
of seconds of inactivity before Windows turns on the screen saver. It
then multiplies that by 0.8 and, when the screen saver is disabled,
uses that, now lower, value as the number of seconds before injecting a
virtual mouse move event. This is done with the SendInput() function,
passing in an INPUT structure with a mouse move value of zero pixels.
It doesn't actually move the cursor, it just injects the mouse message
into the Windows message queue, thus resetting the timers.
[/EDIT]
Edited by Average Midget on 03-20-08 10:34 PM. Reason for edit: Added content
|
SlyFerret

Loc: Delaware, Ohio
Registered on 12-19-06
|
Re: Trying to Stop Network Screensaver 03-21-08 06:44 AM - Post#162314
In response to Average Midget
I'm still a little nervous about condoning such behavior, but, I do have to say... Pretty cool solution!
-SF
Had this been an actual emergency, we would have fled in terror, and you would not have been notified. |
|
Logan 5

Loc: California
Registered on 03-10-08
|
Re: Trying to Stop Network Screensaver 03-22-08 12:21 AM - Post#162391
In response to Average Midget
Awesome! Thank you, Thank you, Thank you in
advance. I won't be able to try this out until Monday but I'll let you
know how it goes. I have a Vista pc and access to an XP, so I'll try it
on both. Fingers crossed!
No Matter Where You Go, There You Are. |
|
Average Midget
Registered on 03-04-08
|
Re: Trying to Stop Network Screensaver 03-22-08 03:32 PM - Post#162448
In response to Logan 5
Awesome, indeed. I'm glad someone can use it. Plus it was a huge learning experience for me.
I just tested it on my wife's Fujitsu lifebook tablet, which has Vista
Ultimate...And it worked. I can't say that it'll work on all Vista
installs, but there is nothing special about hers. She's not set up
with elevated privileges, nor does she have limited privileges; it was
a default install. That's promising.
I've attached a new compile of ScrSlayerLean.exe. I did so because
there was a chunk of code that I forgot to take out. If you're going to
use it, I strongly recommend replacing it with this version.
This was a problem when you selected 'q' to quit the program. There
were a number of Sleep() calls that I left in there, for testing. It
would cause the application to take a long time to end, when the 'q'
option was selected. I've also gone through and changed a bit of the
code to make sure that the thread was ended in a peaceful manner, even
if the user closed the application without selecting the 'q' option.
Windows is good about cleaning up all things related to the main
process, when that process is ended, these changes were just insurance.
Here is the code for ScrSlayerLean.exe
main.h
Code:
// Save As: main.h
//
#ifndef MAIN_H
#define MAIN_H
#define _WIN32_WINNT 0x0500
#define WIN32_LEAN_AND_MEAN
// Include the following header files
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <process.h>
#include <math.h>
// Define the preprocessor macros
// These will do a "Find and Replace" before
// the compiler gets the code.
//
// That means that, any time you see SIXTY_SECONDS in the
// code, the preprocessor will replace it with the numer 60
// before compile time
#define SIXTY_SECONDS 60
#define THIRTY_SECONDS 30
#define DIVISION_AMOUNT 0.08
// Global variables used in the application
DWORD dwThreadID = 0;
HANDLE hTimerThread = NULL;
BOOL isEnabled = FALSE;
UINT scrTimerSeconds = NULL;
// Function prototyping. The functions need to be defined
// before they can be used inside the application.
VOID CALLBACK TimerProc(HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime);
unsigned _stdcall TimerThread(LPVOID lpParam);
UINT GetScreenSaverTimeOut(void);
BOOL EnableScreenSaver(HANDLE hThread);
BOOL DisableScreenSaver(HANDLE hThread);
void ExitCleanUp(void);
#endif // End of MAIN_H
main.cpp
Code:
// Save As: main.cpp
//
// Tell the preprocessor to include the main.h file
// this is where all function prototyping and global
// variables are defined.
#include "main.h"
// Main entry point into the application
int main(int argc, char* argv[])
{
// Register an exit function to do necessary cleanup
// when the application is terminated.
atexit(ExitCleanUp);
// Get the number of seconds before Windows is scheduled
// to turn on the screen saver feature
scrTimerSeconds = (UINT)GetScreenSaverTimeOut();
// Test the value returned by Windows and do the
// appropriate calculations.
if (scrTimerSeconds > SIXTY_SECONDS)
{
scrTimerSeconds = (UINT)floor(scrTimerSeconds / DIVISION_AMOUNT);
}
else
{
// Sixty seconds is the lowest Windows will let you
// set the screen saver timeout, so we should never
// get to this point. If something went wrong, though
// we assign the value of thiry seconds.
scrTimerSeconds = THIRTY_SECONDS;
}
// Create a new thread to handle the timer that
// injects the mouse move event.
hTimerThread = (HANDLE)_beginthreadex(NULL,
0,
(unsigned int (__stdcall *)(void *))TimerThread,
(LPVOID)scrTimerSeconds,
0,
(PUINT)&dwThreadID);
// Test if the handle to the thread is valid. If it's
// not, we terminate the process. It would be an
// extreme case, if this failed.
if (!hTimerThread)
{
printf("Cannot start time thread.\n");
return -1;
}
// Create a variable to handle the user input
char in = 'a';
// Start a loop to react to the user input. If the
// variable 'in' is 'q' the program will exit. All
// other options process the request and return to the
// loop.
while ('q' != in)
{
// Clears the console screen.
system("cls");
// Outputs the information to the screen.
std::string message = (isEnabled == TRUE) ? "Screen saver is currently enabled" : "Screen saver is currently disabled";
std::cout << message.c_str() << std::endl << std::endl;
std::cout << "Please select from the following options..." << std::endl << std::endl;
message = "";
message = (isEnabled == FALSE) ? "e = Enabled screen saver" : "d = Disable screen saver";
std::cout << message.c_str() << std::endl;
std::cout << "q = Quit the application" << std::endl << std:: endl;
message = "";
// Waits for the user to select an option.
std::cin >> in;
// Checks that option and reacts to it appropriately.
switch (in)
{
// 'e' = Enable the screen saver; allow it to come on.
case 'e':
EnableScreenSaver(hTimerThread);
isEnabled = TRUE;
break;
// 'd' = Disable the screen saver; do not allow it to come on.
case 'd':
DisableScreenSaver(hTimerThread);
isEnabled = FALSE;
break;
// 'q' = Quit the program
case 'q':
// The atexit() function will handle the thread
// cleanup, so we just return 0, which means to
// exit the program.
std::cout << "Waiting to exit..." << std::endl;
return 0;
break;
default:
// Handles all other values, by starting the while loop
// all over again
break;
}
}
// End the application
return 0;
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// TimerProc()
//
// Called by the SetTimer() function. This is called every
// time the timer reaches the end of its time interval.
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
VOID CALLBACK TimerProc(HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime)
{
// Create the INPUT structure and assign it the values
INPUT input = {0};
input.type = INPUT_MOUSE;
input.mi.dx = 0; // the number of pixels to move in the x direction
input.mi.dy = 0; // the number of pixels to move in the y direction
input.mi.dwFlags = MOUSEEVENTF_MOVE;
// Send the INPUT structure to inject the mouse move.
SendInput(1, &input, sizeof(input) );
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// TimerThread()
//
// Called by the _beginthreadex() as the starting function
// of the newly created thread. Basically, that means that,
// when the thread is created, the threads purpose is to
// handle the execution of this function
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
unsigned _stdcall TimerThread(LPVOID lpParam)
{
// Create the timer and send it the scrTimerSeconds,
// passed in with the lpParam function argument.
SetTimer(NULL, 0, (UINT)lpParam, (TIMERPROC)TimerProc);
// Start a message loop to keep the thread alive and
// also listen for the WM_QUIT message
MSG theMsg;
while (GetMessage(&theMsg, NULL, 0, 0))
{
DispatchMessage(&theMsg);
}
// Turn off the timer
KillTimer(NULL, 0);
return 0;
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// GetScreenSaverTimeOut()
//
// Requests the number of seconds before Windows turns on
// the screen saver, after inactivity
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
UINT GetScreenSaverTimeOut(void)
{
UINT seconds = 0;
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, NULL, (PVOID)&seconds, NULL);
return (UINT)seconds;
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// EnableScreenSaver()
//
// Enables the screen saver by suspending the timer thread
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
BOOL EnableScreenSaver(HANDLE hThread)
{
SuspendThread(hThread);
return TRUE;
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// DisableScreenSaver()
//
// Disables the screen saver by resuming the timer thread
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
BOOL DisableScreenSaver(HANDLE hThread)
{
ResumeThread(hThread);
return TRUE;
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
// ExitCleanUp()
//
// Performs the necessary cleanup when the application is
// terminated
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void ExitCleanUp(void)
{
// Check to see if the isEnabled flag is set to TRUE.
// If it is, that means the thread is suspended and
// will not recieve the WM_QUIT message.
if (isEnabled == TRUE)
{
DisableScreenSaver(hTimerThread);
}
// Safely stop the thread by sending it the WM_QUIT message.
PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
// Wait for the thread to exit.
WaitForSingleObject(hTimerThread, INFINITE);
// Clean up by closing the thread handle.
CloseHandle(hTimerThread);
// Output the final message because the thread was closed
std::cout << "Thread closed and cleaned up." << std::endl << std::endl;
}
To get it to compile in Visual Studio V6.0, you'll have to set your
project settings to multithreaded, since it uses a seperate thread to
handle the timer.
I'll post the source for the GUI version, if anyone wants it, but
there's a lot more code and resource files, for the graphics, so it's a
larger upload. If there is interest, I'll go ahead and post it.
I know there are stupid things, in this code. An example would be
returning true, when I never tested if the function succeeded. If I was
trying to sell it, I'd make it better...it's free.
|
Logan 5

Loc: California
Registered on 03-10-08
|
Re: Trying to Stop Network Screensaver 03-24-08 09:44 PM - Post#162660
In response to Average Midget
It Works!!! I tried it on both a XP and Vista pc
and both stopped giving me the damn login screensaver. I was able to
keep some info up on the LCD screen for the 30+ minutes w/o having to
remember to "wiggle" the mouse.
Thank you! And my fellow teachers are stoked too, and thank you!
No Matter Where You Go, There You Are. |
|
|