0

I'm trying to run some automated GUI tests without a screen by using the command

tscon 3 /dest:console 

This worked great on a Windows Server 2008 (32bit) but I'm trying to move everything to Windows Server 2008 R2 (64bit) and running into a problem with this. On the original machine it was no problem to run the tests without a screen for multiple times (without entering the machine by RDP). Now on the new machine the tests are also able to run with the same command for one time but when trying it for a second time (without entering the machine by using RDP) I get the error:

Error [7045]:The requested session access is denied.

I tried to use the following script found on this issue:

for /f %%i in ('qwinsta ^| grep "^>" ^| awk "{print $4}"') do set VAR=%%i
tscon %var% /dest:console

but it also only works the 1st time. The second time it also returns ID 3 but then I get the access is denied error.

Nicholas
  • 157

2 Answers2

0

I've found the solution, use the command with runas! runas /savecred /user:yogurt\administrator "tscon.exe 3 /dest:console" , to pass the password for the administrator use the script on http://www.sysopt.com/showthread.php?153867-quot-runas-quot-command-line-without-manually-typing-a-password

Nicholas
  • 157
0

Create bat file with the following code:

 (for /f %%i in ('qwinsta ^| grep "^>" ^| awk "{print $4}"') do set VAR=%%itscon %var% /dest:console)

This will close the RDP session and create session with Console as Active. You can check by executing command qwinsta. Lets name that file KeepSessionAlive.bat.

Now create one powershell script with below code where we will check whether the console session is Active or not.If it's not active than we will execute above bat file else we won't.

$val = qwinsta
$flag = $True
for ($i=0;$i-lt $val.Count;$i++)
    {
    if ($val[$i] -Match 'Console')
    {
        if($val[$i] -Match 'Active')
        {
            Write-Output $val[$i]
            $flag = $False
        }
    }
}
If ($flag){
    Write-Host 'Activating Session's
    'Bat file create above'
}
Dominique
  • 2,373