6

I want to write code or a script to lock the PC when my C++ program receives a specific command from Ethernet.

Is there any way to show the Login screen from the command line? I want to lock the screen from a c++ code. Actually I want to do something like Ctrl + Alt + L programmatically (from a c++ code). Thanks

Edit: I found the way. For those who want to know, as Lubuntu uses LXDE desktop, it has some methods to do thing like it. The command for locking the screen is lxlock.

fossfreedom
  • 174,526
oMatrix
  • 65

3 Answers3

1

In accordance with what @gertvdijk said, you can use DBus:

qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock

I have used that in my lock and off project.

0

Your question as it is written now is a bit unclear. I'll try to guess what you want and give you a couple answers to try.

  1. Ctrl + Alt + L will lock the screen. Everything is still running, you are logged in, but the screen is locked.
  2. Ctrl + Alt + T opens the Terminal, then type gnome-session-quit

Note that if #2 is what you want, this is an exact duplicate of this question 'How can you log out via the terminal', which is where I copied the second answer from.

Please edit your question so it is clearer, or so we can close it as a duplicate.

Tom Brossman
  • 13,297
-3

I found the way. For those who want to know. As Lubuntu uses LXDE desktop, it has some methods to do thing like it. The command for locking the screen is lxlock.

oMatrix
  • 65