Coder Social home page Coder Social logo

laplock's Introduction

laplock

Author: Etienne Dechamps (a.k.a e-t172) [email protected]

https://github.com/dechamps/laplock

This extremely small (102 lines, 21KB binary) C++ program allows you to automatically lock your Windows computer on two events:

  • The computer is a laptop and its lid is closed;
  • The computer screen is turned off. Note that this probably won't work with the power button of your monitor since the system is not notified when this happens; however, it works when the screen is turned off automatically after the delay specified in the Windows power management options.

laplock runs on Windows Vista, 7, and probably later versions; it won't work on Windows XP, since it doesn't implement the necessary power management interface.

Compilation

There is only one C++ file and it should compile using any Windows compiler. Project files are provided for Microsoft Visual C++ 2010. Note that you'll need the Windows SDK version 7.0 or greater.

Usage

Just run it. At first, nothing will happen; this is normal as laplock runs silently in the background (you can check this using the Windows task manager). laplock will keep running until you log off or kill it. It is recommended to add laplock to your Startup folder; then you can happily forget about it.

Note that laplock listens intelligently for events; meaning, it doesn't consume any CPU at all while waiting.

laplock's People

Contributors

dechamps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laplock's Issues

Locking After signing in

Hi,

If I start my laptop while it's on a docking station when I login laplock will start then lock the device, is there a way to prevent that ? If I login when the laptop is on the docking station it should not lock only once I open and close it again.

also thank you for all your work on this, it is very much appreciated!!!

New release?

Could you generate a new release (.exe file)? I noticed a number of commits since the initial release and it would be nice to have a new binary to go with the new source code for those of us who don't have access to a development system.

Unable to disable it

I wanted to disable it, so I disabled it via Task Manager, and it's still locks. Can someone help me about that!? (I'm on Windows 10)

Code snippet for preventing multiple instances running

This simple app is very useful.

Here's the code I added to my project to prevent multiple instances from running.

I tested it briefly and it seems to work...it should be cleaned up to your standards. My Win10 machine appears to remove the mutex if the executable is ended using Task Manager so it should do so if the executable somehow crashes.

The code is basically the bottom of 'WinMain'.

========================= code added below here ===================================

wchar_t* convertCharArrayToLPCWSTR(const char* charArray)
{
wchar_t* wString = new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 4096);
return wString;
}

}
}

int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR commandLine, int cmdShow)
{
CHAR szUniqueNamedMutex[] = "laplockUniqueNamedMutexZZTopRox";
LPCWSTR lpcwstr_app = laplock::convertCharArrayToLPCWSTR(szUniqueNamedMutex);
HANDLE hHandle = CreateMutex(NULL, TRUE, lpcwstr_app);
if (ERROR_ALREADY_EXISTS == GetLastError())
{
// Program already running somewhere
return(1); // Exit program
}

return laplock::WinMain(instance, prevInstance, commandLine, cmdShow);

// Upon app closing:
ReleaseMutex(hHandle); // Explicitly release mutex
CloseHandle(hHandle); // close handle before terminating
return(1);

}

Log Errors to Windows Eventlog

Hi and many thanks for this nice piece of software.

I have found, that errors will be locked to file, but only when a logfile is definied.

It would be better to log errors always in the windows eventlog and additionally to the logfile.

Thanks

Still there after Removing

After removing the exe from Autostart, its still doing the same thing as your tool did, but its not even running anymore in Taskmanager, im kinda spooked, whats happening ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.