Don't know if this will work under vista - it does on XP pro 32 bit. C# WinForms app, removed Form1 (not used) and put this in Program.cs
//Program.cs
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace NoSaverLock
{
static class Program
{
private const uint SPI_GETSCREENSAVEACTIVE = 0x0010;
private const uint SPI_SETSCREENSAVEACTIVE = 0x0011;
private static bool keepRunning = true;
private static bool screenSaverOn;
[STAThread]
static void Main()
{
SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
bool tmpBool = false;
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, ref screenSaverOn, 0);
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, ref tmpBool, 0);
LockWorkStation();
while (keepRunning)
{
System.Threading.Thread.Sleep(1000);
}
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, Convert.ToUInt32(screenSaverOn), ref tmpBool, 0);
SystemEvents.SessionEnding -= SystemEvents_SessionEnding;
SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
}
static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
if (e.Reason == SessionSwitchReason.SessionUnlock)
keepRunning = false;
}
static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
keepRunning = false;
}
[DllImport("user32.dll")]
static extern void LockWorkStation();
[DllImport("user32.dll")]
private static extern bool SystemParametersInfo(
uint uAction, uint uParam, ref bool lpvParam, uint fuWinIni);
}
}
Is there a 'no programming answers in the lounge' rule? If so - sorry!
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modif