Page 1 of 1

locking my screen not with Win L

Posted: 05 Nov 2019, 09:48
by AmDeG 11
how can I lock my screen with a single shortcut?

the following is not working:

Code: Select all

#a::DllCall("LockWorkStation")

Re: locking my screen

Posted: 05 Nov 2019, 14:05
by Kobaltauge
Win+l

Re: locking my screen

Posted: 05 Nov 2019, 15:32
by AmDeG 11
I re-design Win 1 to another purpose...

if someone can help me out with the code

Re: locking my screen

Posted: 05 Nov 2019, 15:49
by flyingDman
DllCall("LockWorkStation") works here.

You might want to reconsider reassigning Win L (which is the native Windows shortcut for locking the PC).
I re-design Win 1 to another purpose...
I presume you meant Win l rather than win 1.

Re: locking my screen

Posted: 05 Nov 2019, 16:04
by boiler
Try this:

Code: Select all

#a::#l
(as flyingDman pointed out, that's a lower case L, not the number 1)

Re: locking my screen

Posted: 07 Nov 2019, 20:59
by AmDeG 11
I overrode the native shortcut #l to be another thing

for that reason I would like to know the way to execute locking screen with another # key

Re: locking my screen

Posted: 07 Nov 2019, 21:26
by boiler
AmDeG 11 wrote:
07 Nov 2019, 20:59
I overrode the native shortcut #l to be another thing
I'd be interested in hearing how you did that. I'm not able to. It is supposedly protected by Windows. Did you have to use some other method than a regular remap or hotkey? Perhaps whatever you did is also the reason DllCall("LockWorkStation") isn't working for you.

Re: locking my screen

Posted: 08 Nov 2019, 11:54
by AmDeG 11
interesting comment

I disabled from here

http://www.howtogeek.com/howto/windows-vista/disableenable-lock-workstation-functionality-windows-l/

If I enable it, is there another way to move locking screen to ANOTHER WINDOW KEY so as to have Win L for another purpose?

Re: locking my screen

Posted: 08 Nov 2019, 13:04
by boiler
What you showed is why I asked how you accomplished that. Apparently the reason that DllCall("LockWorkStation") is not working for you is that you disabled the ability to lock the workstation altogether when you edited the registry. It can't be locked by using Win+L, not via the Start menu, , not via Ctrl+Alt+Delete, and not by the DllCall. It won't lock no matter what key it is assigned to because the function has been disabled. I know it's not the answer you want, but it seems to be the reason for what is happening.

If you enable it, the Win+L combination appears to be always captured by Windows to lock the workstation. At least from what I can see, you can assign a hotkey to it, but it will also lock the workstation. That's why I asked how you were able to reassign it without having it also lock.

Re: locking my screen

Posted: 08 Nov 2019, 17:27
by AmDeG 11
ok I got it

so is there any no solution?

can I reasign Lockstation to another key and use Win L for another purpose?

maybe a somewhat similar function to Lockstation that can temporarily freeze my machine?

Re: locking my screen

Posted: 08 Nov 2019, 17:33
by boiler
You can assign it to another key like this:
#a::#l
and you can assign a hotkey to #l, but it will perform the hotkey code in addition to locking the workstation. Perhaps someone else knows away to intercept the key at a lower level such that Windows won't see it and lock it, but I don't know how.

Re: locking my screen

Posted: 08 Nov 2019, 18:21
by AmDeG 11
but as long as Win L continues locking the computer I cannot see any purpose to try to have it done another action

Re: locking my screen

Posted: 08 Nov 2019, 19:18
by boiler
Yes, exactly. Unless someone else knows a way to do it, it looks like you would just have to leave it as is.

Re: locking my screen

Posted: 13 Nov 2019, 12:29
by AmDeG 11
does anyone know a way to simulate the function LockScreen been disabled the default Win L shortcut?

Re: locking my screen

Posted: 13 Nov 2019, 12:35
by boiler
If it is disabled using the method shown in the link you have given, you are not disabling the Win+L shortcut, you are disabling the ability for LockScreen to be performed by any method at all, including keyboard shortcuts, DLL calls, via the start menu, via Ctrl+Alt+Delete, or any other method. There will be no way to invoke a LockScreen when you have disabled it in that manner.

Re: locking my screen not with Win L

Posted: 13 Nov 2019, 15:32
by AmDeG 11
ok, imagine I enabled (delete disable) Win L

now, how can I force Win L to be Right Arrow and Win S to be LockScreen ?

Re: locking my screen

Posted: 13 Nov 2019, 16:15
by boiler
To quote my earlier post:
boiler wrote:
08 Nov 2019, 13:04
If you enable it, the Win+L combination appears to be always captured by Windows to lock the workstation. At least from what I can see, you can assign a hotkey to it, but it will also lock the workstation.
You're really just asking the same questions again. It is looking like you just have to accept that as long as LockScreen capability is enabled, Windows is always going to link Win+L to it. You can link another key to locking the screen, but you can't simultaneously remove that function from Win+L.

Re: locking my screen not with Win L

Posted: 14 Nov 2019, 21:18
by AmDeG 11
Boiler,
I asked to OTHER people that MIGHT have a solution. I know that you don't have it. However, at your answer you even expressed that MAYBE another could have a solution, saying: "At least from what I can see [it is not possible]"

thanks!

Re: locking my screen not with Win L  Topic is solved

Posted: 21 Nov 2019, 02:53
by jeeswg
Changing the DisableLockWorkstation value to 1, in the registry, disables the Win+L hotkey, but appears to have the side effect of disabling all means of locking the workstation.

With Win+L disabled, you can choose an alternative hotkey to lock the workstation. It needs to set DisableLockWorkstation to 0, call LockWorkStation, and then set DisableLockWorkstation to 1.

The script below will run smoothly if run as admin. Otherwise you have to respond to 2 run as admin prompts.

Code: Select all

;Win+L
#l:: ;a new purpose for Win+L
MsgBox, % "a new purpose for Win+L"
return

;Ctrl+Win+Alt+L
^#!l:: ;lock workstation (note: requires 2 'run as admin' registry writes)
;tested with Windows 7

;enable 'lock workstation' (and enable Win+L hotkey):
RegRead, vIsDisabled, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation
if vIsDisabled
	try RunWait, % "*RunAs " A_ComSpec " /c REG ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableLockWorkstation /t REG_DWORD /d 0 /f",, Hide ;enable Win+L
	;RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0 ;enable Win+L

;lock workstation:
DllCall("user32\LockWorkStation")

;disable 'lock workstation' (and disable Win+L hotkey):
RegRead, vIsDisabled, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation
if !vIsDisabled
	try RunWait, % "*RunAs " A_ComSpec " /c REG ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableLockWorkstation /t REG_DWORD /d 1 /f",, Hide ;disable Win+L
	;RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1 ;disable Win+L
return
If there is *some way* to lock the workstation, even when DisableLockWorkstation is set to 1, that would be interesting. Cheers.

Re: locking my screen not with Win L

Posted: 05 Jun 2020, 15:21
by eugenesv
jeeswg wrote:
21 Nov 2019, 02:53
[/code]
If there is *some way* to lock the workstation, even when DisableLockWorkstation is set to 1, that would be interesting. Cheers.
I think there is a better way where you need neither an elevated script nor two UAC prompts. The trick is creating two tasks in the Task Scheduler that would flip the bit in the registry, e.g.
  • Name: WinLock Disable
  • Run with highest privileges check mark set
  • Actions: start a program(this is the default)
  • Program/script: REG
  • Add arguments: ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableLockWorkstation /t REG_DWORD /d 00000001 /f
and
  • Name: WinLock Enable
  • Run with highest privileges check mark set
  • Actions: start a program(this is the default)
  • Program/script: REG
  • Add arguments: ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableLockWorkstation /t REG_DWORD /d 00000000 /f
(by the way, instead of manually creating the second task it might be easier to export the first, edit the command in the text editor and then import it with a new name, might save a clik :) )

Then you would adjust your script to execute:

Code: Select all

...
Run('schtasks /Run /TN "\PathTo\WinLock Enable"') ;\PathTo\ in case you created your tasks in a separate folder not to mix with others, "quotes" in case youre task names have spaces
...
Run('schtasks /Run /TN "\PathTo\WinLock Disable"')