3

I've looked through the forums and havn't found anything that quite helps me complete what I want to do. What I'm looking for is a way to start a the GUI for an application on a remote server. I've seen that I can do this with PsExec as long as I know what the session ID for my specific remote session is. However as Session IDs change this isn't something that I can use reliably. Is there any way to do the following:

  • Have a permanent session ID for a specific user
  • Find the session ID for a specific user
  • Other ways to start the GUI in my session on the server

Any help would be appreciated.

tylerauerbeck
  • 173
  • 4
  • 15
  • 1
    For anything looking for a solution to this - I used the code found here http://taskscheduler.codeplex.com/. It's a bit choppy having to go through task scheduler but it gets what I needed accomplished. – tylerauerbeck Mar 28 '13 at 13:42

1 Answers1

1

I used to implement something like this when needed to launch gui tests on remote machine.

You can use -i parameter of psexec, which would run command 'interactively' in the specified session, for a specific user, it looks like this:

psexec.exe \\<MachineName> -u <Username> -p <Password> -i <SessionNumber>

To get sessionNumber you can also use same psexec utility, you can execute "query session" with it on the remote machine for the specified user.

You may create .bat file which would return session number with the following code:

@echo off
setlocal enabledelayedexpansion

set username=%2
set password=%3
set machine=%1

psexec.exe \\%machine% -u %username% -p %password% query session %username%>sessid.txt

set /a counter=0
for /F "tokens=* skip=1" %%a in (sessid.txt) do (
for %%b in (%%a) do (
set /a counter+=1
if !counter! == 3 (
    echo !counter!:%%b
    exit %%b
)
)
)

This batch file works well for me, you can use it like this

getSessionNumber.bat <ServerName> <User> <Password>
paulitto
  • 4,585
  • 2
  • 22
  • 28