06-04-19 12:07 AM
27-04-20 06:19 PM
@DavidVizcaíno - Below is the latest version I have, which includes a session check, as you found might be needed. The 20 windows are expected, unfortunately. In normal cases, you might be able to get away with only using the first one or two tsdiscon lines, though.
The only way I know of to launch something hidden, would be via additional code. For example, VB (also below). You could make a .vbs file to launch the bat file, then tie that into your task. I haven't tested it on this particular bat file, so I don't know if the child windows would also be hidden. "@ECHO off" only specifies that it shouldn't output text to the cmd window.
Have you checked that the task is running as administrator? It's required to use tsdiscon.
Dim startInfo As New ProcessStartInfo("unlockme.bat") startInfo.WindowStyle = ProcessWindowStyle.Hidden Process.Start(startInfo)
@ECHO off setlocal EnableDelayedExpansion for /f "tokens=2,4" %%a in ('QUERY USER ^| FINDSTR ">"') DO ( set "consoleTemp=%%a" set "connectionState=%%b" set "consoleType=!consoleTemp:~0,7!" ) SET consoleTypeCorrect=0 IF "!consoleType!"=="rdp-tcp" SET consoleTypeCorrect=1 SET connectionStateCorrect=1 IF %connectionState%==Active SET connectionStateCorrect=1 set TRUE=%connectionStateCorrect%%consoleTypeCorrect% IF %TRUE%==11 ( endlocal ) else ( start "" tscon 1 /dest:console start "" tscon 2 /dest:console start "" tscon 3 /dest:console start "" tscon 4 /dest:console start "" tscon 5 /dest:console start "" tscon 6 /dest:console start "" tscon 7 /dest:console start "" tscon 8 /dest:console start "" tscon 9 /dest:console start "" tscon 10 /dest:console start "" tscon 11 /dest:console start "" tscon 12 /dest:console start "" tscon 13 /dest:console start "" tscon 14 /dest:console start "" tscon 15 /dest:console start "" tscon 16 /dest:console start "" tscon 17 /dest:console start "" tscon 18 /dest:console start "" tscon 19 /dest:console start "" tscon 20 /dest:console )
27-04-20 06:21 PM
27-04-20 06:41 PM
Hi, Ami.
I understand. So, there is no login agent working here.
Best regards.
|
27-04-20 06:51 PM
27-04-20 09:44 PM
Ok, So, is this situation solved now?
Best regards.
|
27-04-20 09:58 PM
command = "powershell.exe -nologo -command unlockMe.bat" set shell = CreateObject("WScript.Shell") shell.Run command,0
Set oShell = CreateObject ("Wscript.Shell") Dim strArgs strArgs = "cmd /c unlockMe.bat" oShell.Run strArgs, 0, false
CreateObject("Wscript.Shell").Run "unlockMe.bat", 0, True
I'm running the task with elevated rights.
Question: When you tried this .bat, the windows flashing up didn't represent a problem??
27-04-20 10:45 PM
PowerShell.exe -windowstyle hidden { "-command unlockMe.bat" }
VB:
1) Create file: unlockme.vbs (or whatever you want to call it), and modify the path to the bat file:
CreateObject("Wscript.Shell").Run "c:\tools\unlockme.bat",0,False
2) Modify unlockme.bat
@ECHO off setlocal EnableDelayedExpansion for /f "tokens=2,4" %%a in ('QUERY USER ^| FINDSTR ">"') DO ( set "consoleTemp=%%a" set "connectionState=%%b" set "consoleType=!consoleTemp:~0,7!" ) SET consoleTypeCorrect=0 IF "!consoleType!"=="rdp-tcp" SET consoleTypeCorrect=1 SET connectionStateCorrect=1 IF %connectionState%==Active SET connectionStateCorrect=1 set TRUE=%connectionStateCorrect%%consoleTypeCorrect% IF %TRUE%==11 ( endlocal ) else ( tscon 1 /dest:console tscon 2 /dest:console tscon 3 /dest:console tscon 4 /dest:console tscon 5 /dest:console tscon 6 /dest:console tscon 7 /dest:console tscon 8 /dest:console tscon 9 /dest:console tscon 10 /dest:consol tscon 11 /dest:console tscon 12 /dest:console tscon 13 /dest:console tscon 14 /dest:console tscon 15 /dest:console tscon 16 /dest:console tscon 17 /dest:console tscon 18 /dest:console tscon 19 /dest:console tscon 20 /dest:console )
28-04-20 07:47 PM
28-04-20 07:50 PM