-1

I'm getting error when I ran the batch file like this,

Could not connect session Id 12 to session name console, error code 5
Error [5]: access denied

and I'm attaching the batch file.

This is my code, I need disconnect ane lock the vm by using this batch file code

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
    %windir%\System32\tscon.exe %%s /dest:console
)
rem Rundll32.exe user32.dll, LockWorkStation
jeb
  • 78,592
  • 17
  • 171
  • 225
Raja S
  • 1
  • 2

1 Answers1

0

I have a similar need and what I'm doing is logoff the session.

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
  %windir%\System32\tscon.exe %%s /dest:console
)
KhaledMostafaMe
  • 572
  • 5
  • 9
  • Hi Khaled, I want lock and disconnect can you please tell me how can I do, log off batch file is running fine but as per my company policies auto login is won't use – Raja S Mar 25 '21 at 08:28
  • I found this answer https://stackoverflow.com/a/65389223/6906583 , and add this line at the end Rundll32.exe user32.dll, LockWorkStation – KhaledMostafaMe Mar 25 '21 at 08:38
  • I attached one file right in that last line if I remove rem from that script system will lock but its not disconnected. – Raja S Mar 25 '21 at 09:24