Lock windows from command line

Как заблокировать компьютер с Windows 10 с помощью командной строки

Одно из первых правил кибербезопасности — всегда блокировать компьютер перед тем, как выйти. Хотя это может быть не самый быстрый способ заблокировать компьютер с Windows 10, вы можете сделать это с помощью командной строки.

Сначала откройте командную строку на своем ПК, открыв меню «Пуск», набрав «cmd» в строке поиска Windows, а затем выбрав «Командная строка» в результатах поиска.

Командная строка откроется. Здесь запустите эту команду, чтобы заблокировать компьютер с Windows 10.

После выполнения ваш компьютер будет заблокирован. Вам нужно будет снова войти в систему, используя свой PIN-код, пароль или любой другой способ входа, который вы обычно используете.

Установите настройку тайм-аута экрана блокировки с помощью командной строки

После того, как вы заблокировали свой компьютер, экран блокировки обычно отображается в течение определенного времени, прежде чем он истечет. Вы можете установить время, которое должно пройти до истечения тайм-аута, с помощью командной строки.

Для этого вам нужно открыть командную строку от имени администратора. Сделайте это, набрав «cmd» в строке поиска Windows, а затем щелкнув правой кнопкой мыши «Командная строка» в результатах. Затем в появившемся меню выберите «Запуск от имени администратора».

Открыв командную строку, запустите эту команду.

Замените желаемое время в секундах. Это означает, что если вы хотите отключить экран блокировки по истечении двух минут, вы должны ввести эту команду:

Примечание. Эта команда устанавливает время ожидания блокировки экрана для вашего ПК, если он подключен к источнику питания. Чтобы установить время ожидания блокировки экрана для вашего ПК, если он работает от батареи, измените значение /SETACVALUEINDEX на /SETDCVALUEINDEX и выполните команду как обычно.

Затем запустите эту команду:

Теперь ваш экран блокировки будет отключен по истечении установленного времени. Попробуйте!

How to lock your computer using command line

Step 1 – Open a DOS promot for launching a special command line. One simple way you can do it would be by clicking Start/Run, typing CMD.

Step 2 – Enter the command line for locking your station:

rundll32.exe user32.dll, LockWorkStation

and your computer will be locked.

44 Responses to “How to lock your computer using command line”

The information was very useful for me and helped me to develop a small tool which I hope will be very useful in my work.

Читайте также:  Url принтера как узнать linux

do yopu think i can make a batch of this?

To unlock the stations just re-enter the username and password for the locked profile, this command is very useful when using remote software when you don’t have other means of locking the station being worked on.

will it work in windows 7??…if not wt to do for windows 7.

The application will work the method with the bat file depending on the rights on the system.

rundll32.exe is a windows-based dynamic library link…of course it will work on windows

…how to unlock?…
press CTRL ALT DEL and log in just like normal…. :0)

windows key + l also works and is much faster and easier

You unlock by logging in.

You will ether press Ctrl, Alt and Delete if your using windows Pro or Ultimate or you just click on your Username Icon if your using windows Home

Then enter your password if you have one.

This will not work on windows7 as-is. It will instead shut windows7 down.

windows key + L works fine, but not if you want another program to enter that command for you. the sendkeys method doesn’t support pressing “windows key + character”.

works for Windows XP not W7 though. thanks.

Re: Windows key+l

Yea, but that won’t be as helpful as the cmd in case you are running a remote desktop from your PC.

This works just fine for me with windows 7.
Open Notepad
Copy and paste this:
Rundll32.exe User32.dll,LockWorkStation

then save the file as lock.bat (or whatever as long as at it ends in .bat)
I put it on the desktop. Double click on the file and the computer locks.

how to unlock it

Thanks, nice tip. Also using it for remote sessions. Tested and works on vista x86
Another nice tip is using texter (get it from lifehacker.com), add eg. “lock” as trigger and it will type rundll32.exe user32.dll, LockWorkStation for you 🙂

is possible run this command from remote pc ( of the same lan ) ?

Do you guys know how to unlock it via the same batch file that locks it?

My scenario is that I want to run some automated tests and the tool requires a “real” window to be opened. I would then unlock the computer, run my scripts and then for security reasons, I want to lock it again.

Any ideas would be greatly appreciated

Thanks it works 🙂

Nice post…….
This is what i was looking from long time…….
but is there any command to unlock the system.

My keyboard has some extra buttons that can be customized to run a program I choose. I put in this command as the program, and it works great for one-touch locking of my workstation! Thanks! (For the record, it’s a Logitech MX3000 keyboard on Windows 7 x64 Pro.)

Читайте также:  Драйвер rx570 для windows 10

Works Great in Win 7.

You can’t script the unlock of a PC. Unless you know the password. Which would require you saving your password in clear text on your PC. NOT A SECURE THING TO DO!

Thanks… I just created a little .bat file using command: rundll32.exe user32.dll, LockWorkStation. It runs great on my 2 computers ( using Win 7 ultimate X64 and X32).

You could also add a message …

Be right back, away from keyboard

heres the edited script…

rundll32.exe user32.dll, LockWorkStation
msg * AFK, BRB

Excellent!! Thanks for the tip

How would I implement this in a batch file that will be set to start my screensaver AND lock my workstation?

RE: rundll32.exe user32.dll, LockWorkStation

No one mentioned this but in windows 7 I create a shortcut which I add a icon to (Shell32.dll has a pretty lock in it) and pin it to the task bar or publish the shourtcut to my users useing Critix or SCCM – works great!

Thanks for the info.. came in handy on a ServerCore 2008 r2 via Hyper-v..

here is the one :
rundll32.exe user32.dll LockWorkStation
just copy the above one and run on DOS prompt.

It works in Windows XP and 7

Can we time this window lock command? Donot want to create any executable, just want to execute on cmd prompt

I mean if I want system gets locked after say 10 mins like we have command to shutdown
shutdown -s -t where t is time in sec after which machine gets shut down

Great Information! Works great on Win 7

I created a bat file and saved on my user profile folder.

Then created a mail rule in outlook to execute the bat if I receive a email with a specific word on the subject.

Now if I leave my computer unlocked, I can just send myself and email from my phone at it locks remotely.

Works fine for me in W7, created a desktop shortcut as well as remote use

Could anyone please tell me the command to unlock system (i can pass username and password as arguments)
Once we have locked the system after some delay it will automatically unlocked(command required to unlock)

Works for windows 7, sadly not for XP D:

Akash: You can use the ‘timeout’ command in Windows 7 or higher. If timeout doesn’t exist, try ‘sleep’. They are generally the same command.

one easy way is to launch the On-Screen keyboard from the start menu in the workstation/server, and then click windows button + L

here is the one :
user32.dll rundll32.exe LockWorkStation
just copy the above one and run on DOS prompt.

Читайте также:  Упало быстродействие компьютера windows 10

how to lock window screen in c++

Is there any command line code to unlock our windows system. I want to set timer that executes a batch to unlock my computer automatically.

Can you help me on the below? I have a similar req.

I have an Excel file in the shared folder.

I dont anyone to keep the file open and lock their system and go off. So, I want to prevent people locking their system, if the file is open.

8 Ways to Lock Computer in Windows 10

Locking your PC protects it from unauthorized use when you need to step away from the PC, and don’t want to sign out or shut down. So let me show you how to lock your Windows 10 PC in different ways.

Way 1: Lock Computer in Ctrl+Alt+Del options

Step 1:В Hold Ctrl and Alt, then press Delete. After options appear on the screen, select Lock from the options.

Way 2:Lock Computer on Screen Saver Settings

Step 1: Input lock computer in the search box and choose Lock the computer when I leave it alone for a period of time.

Step 2: In the Screen Saver Settings dialog, choose On resume, display logon screen and hit OK.

Way 3: Via the User Icon to Lock Computer

Step 1:Open the Start Menu, click/tap on your user name, and click/tap on Lock.

Way 4: Using Windows Key + L

Step 1: В Hold down Windows Key and press L for a quicker way of locking your screen.

Way 5: To Lock Computer from Task Manager

Step 1:В Type task manager in the search box.

Step 2:В Enter the Task Manager, click on the Users tab.

Step 3: Right click your account, and click/tap on Disconnect.

Step 4: Click on Disconnect user to confirm.

Way 6: To Lock Computer with Command

Step 1: Input cmd in the search box and click Command Prompt to open it.

Step 2: Type rundll32.exe user32.dll,LockWorkStation in the Command Prompt window and press Enter.

Way 7: Access Run Window to Lock Computer

Step 1:В Press Windows + R key to open Run command box.

Step 2: In the Run dialog box, type rundll32.exe user32.dll,LockWorkStation and then press Enter key to lock computer.

Way 8: Go to Control Panel through the Settings Panel

Step 1: Right-click any blank area of the Desktop. Select New > Shortcut.

Step 2: For the location of the item type C:\Windows\System32\rundll32.exe user32.dll,LockWorkStation and click Next.

Step 3: Give the icon a name, like Lock computer, then click Finish.

Step 4: Now you have a Screen Lock icon, you can double-click whenever you lock your computer.

Оцените статью