Runas in another Windows session

For simplicity, suppose the user is Administratorlogged into a terminal session 2. Another user Bodalogs into a terminal session 3.

Is it possible to execute a runasprogram in a session 3from a session 2?

For simplicity, suppose I want to start calc.exein a session 3(in a Boda session). How should I do it? Can this be done with runas?

+4
source share
5 answers

Like Harry Johnston in the commentary, you can do this using the tool psexec

: Patrick, cmd.exe , ( ). enter image description here

+9

RunInSession. SessionId, . , . , :

RunInSession

- Windows XP, 2003, Vista 2008.

Localsystem, . WTSQueryUserToken . , CreateProcessAsUser, .

:

+5

, . , psexec.exe .

, , .

powershell script:

param (
    [string]$Computer = ($env:computername),
    [string]$User = "",    
    [string]$Command,
    [string]$Args
 )

$script_task = 
{

    param (
        [string]$User = "",
        [string]$Command,
        [string]$Args
     )

    #Action
    $Action = New-ScheduledTaskAction –Execute $Command
    if($Args.Length > 0) { $Action = New-ScheduledTaskAction –Execute $Command -Argument $Args}

    #Principal
    $P = New-ScheduledTaskPrincipal -UserId $User -LogonType Interactive -ErrorAction Ignore

    #Settings
    $S = New-ScheduledTaskSettingsSet -MultipleInstances Parallel -Hidden

    #Create TEMPTASK
    $TASK = New-ScheduledTask -Action $Action -Settings $S -Principal $P

    #Unregister old TEMPTASK
    Unregister-ScheduledTask -TaskName 'TEMPTASK' -ErrorAction Ignore -Confirm:$false

    #Register TEMPTASK
    Register-ScheduledTask -InputObject $TASK -TaskPath '\KD\' -TaskName 'TEMPTASK'

    #Execute TEMPTASK
    Get-ScheduledTask -TaskName 'TEMPTASK' -TaskPath '\KD\' | Start-ScheduledTask

    #Unregister TEMPTASK
    Unregister-ScheduledTask -TaskName 'TEMPTASK' -ErrorAction Ignore -Confirm:$false

}

#The scriptblock get the same parameters of the .ps1
Invoke-Command -ComputerName $Computer -ScriptBlock $script_task -ArgumentList $User, $Command, $Args

:

file.ps1 -User USER_NAME -Command notepad.exe -Computer REMOTE_COMPUTER
+4

I do not know how you can manage another open cmd session. However, you can use runasto start it as another user.

+1
source

This can be archived using Microsoft's Sysinternals tools. Besides running lists of commands and scripts remotely, they are useful for many things. As administrators, they have been my savior several times.

#To run a command on single computer remotly
psexec \\RemoteComputerName Path_Of_Executable_On_Remote_Computer Argument_list

#To run a command on list of computers remotely.
psexec @Remote_Computer_list Path_Of_Executable_On_Remote_Computer Argument_list /AcceptEULA

#To run list of commands on list of remote computer. make sure you copy batch file before you run command below.
psexec @Remote_Computer_List Path_Of_Batch_On_Remote_Computer Argument_list
+1
source

All Articles