Esempio n. 1
0
        public RemoteMessageBoxResult MessageBox(string text, string caption, RemoteMessageBoxButtons buttons,
                                                 RemoteMessageBoxIcon icon, RemoteMessageBoxDefaultButton defaultButton, RemoteMessageBoxOptions options,
                                                 TimeSpan timeout, bool synchronous)
        {
            var timeoutSeconds = (int)timeout.TotalSeconds;
            var style          = (int)buttons | (int)icon | (int)defaultButton | (int)options;
            // TODO: Win 2003 Server doesn't start timeout counter until user moves mouse in session.
            var result = NativeMethodsHelper.SendMessage(_server.Handle, _sessionId, caption, text, style,
                                                         timeoutSeconds, synchronous);

            // TODO: Windows Server 2008 R2 beta returns 0 if the timeout expires.
            // find out why this happens or file a bug report.
            return(result == 0 ? RemoteMessageBoxResult.Timeout : result);
        }
Esempio n. 2
0
 public void Connect(ITerminalServicesSession target, string password, bool synchronous)
 {
     if (!Local)
     {
         throw new InvalidOperationException("Cannot connect sessions that are running on remote servers");
     }
     if (IsVistaSp1OrHigher)
     {
         NativeMethodsHelper.Connect(_sessionId, target.SessionId, password, synchronous);
     }
     else
     {
         NativeMethodsHelper.LegacyConnect(_server.Handle, _sessionId, target.SessionId, password, synchronous);
     }
 }
Esempio n. 3
0
        private void LoadWinStationInformationProperties()
        {
            var wsInfo = NativeMethodsHelper.GetWinStationInformation(_server.Handle, _sessionId);

            _windowStationName.Value  = wsInfo.WinStationName;
            _connectionState.Value    = wsInfo.State;
            _connectTime.Value        = NativeMethodsHelper.FileTimeToDateTime(wsInfo.ConnectTime);
            _currentTime.Value        = NativeMethodsHelper.FileTimeToDateTime(wsInfo.CurrentTime);
            _disconnectTime.Value     = NativeMethodsHelper.FileTimeToDateTime(wsInfo.DisconnectTime);
            _lastInputTime.Value      = NativeMethodsHelper.FileTimeToDateTime(wsInfo.LastInputTime);
            _loginTime.Value          = NativeMethodsHelper.FileTimeToDateTime(wsInfo.LoginTime);
            _userName.Value           = wsInfo.UserName;
            _domainName.Value         = wsInfo.Domain;
            _incomingStatistics.Value = new ProtocolStatistics(wsInfo.ProtocolStatus.Input);
            _outgoingStatistics.Value = new ProtocolStatistics(wsInfo.ProtocolStatus.Output);
        }
Esempio n. 4
0
 public void StopRemoteControl()
 {
     if (!Local)
     {
         throw new InvalidOperationException(
                   "Cannot stop remote control on sessions that are running on remote servers");
     }
     if (IsVistaSp1OrHigher)
     {
         NativeMethodsHelper.StopRemoteControl(_sessionId);
     }
     else
     {
         NativeMethodsHelper.LegacyStopRemoteControl(_server.Handle, _sessionId, true);
     }
 }
        private IPAddress GetClientIPAddress()
        {
            WTS_CLIENT_ADDRESS clientAddress =
                NativeMethodsHelper.QuerySessionInformationForStruct <WTS_CLIENT_ADDRESS>(_server.Handle, _sessionId,
                                                                                          WTS_INFO_CLASS.WTSClientAddress);
            AddressFamily addressFamily = (AddressFamily)clientAddress.AddressFamily;

            if (addressFamily == AddressFamily.InterNetwork)
            {
                byte[] address = new byte[4];
                Array.Copy(clientAddress.Address, 2, address, 0, 4);
                return(new IPAddress(address));
            }
            // TODO: support IPv6
            return(null);
        }
        public TerminalServicesSession(ITerminalServer server, int sessionId, string windowStationName,
                                       ConnectionState connectionState)
        {
            _server            = server;
            _sessionId         = sessionId;
            _windowStationName = windowStationName;
            _connectionState   = connectionState;
            _clientBuildNumber = new LazyLoadedProperty <int>(GetClientBuildNumber);
            _clientIPAddress   = new LazyLoadedProperty <IPAddress>(GetClientIPAddress);
            _clientDisplay     = new LazyLoadedProperty <IClientDisplay>(GetClientDisplay);
            _clientName        =
                NativeMethodsHelper.QuerySessionInformationForString(_server.Handle, _sessionId,
                                                                     WTS_INFO_CLASS.WTSClientName);

            // TODO: MSDN says most of these properties should be null for the console session.
            // I haven't observed this in practice on Windows Server 2000, 2003, or 2008, but perhaps this
            // should be considered.
            if (Environment.OSVersion.Version >= new Version(6, 0))
            {
                // We can actually use documented APIs in Vista / Windows Server 2008+.
                WTSINFO info =
                    NativeMethodsHelper.QuerySessionInformationForStruct <WTSINFO>(server.Handle, _sessionId,
                                                                                   WTS_INFO_CLASS.WTSSessionInfo);
                _connectTime    = NativeMethodsHelper.FileTimeToDateTime(info.ConnectTime);
                _currentTime    = NativeMethodsHelper.FileTimeToDateTime(info.CurrentTime);
                _disconnectTime = NativeMethodsHelper.FileTimeToDateTime(info.DisconnectTime);
                _lastInputTime  = NativeMethodsHelper.FileTimeToDateTime(info.LastInputTime);
                _loginTime      = NativeMethodsHelper.FileTimeToDateTime(info.LogonTime);
                _userName       = info.UserName;
                _domainName     = info.Domain;
            }
            else
            {
                WINSTATIONINFORMATIONW wsInfo = NativeMethodsHelper.GetWinStationInformation(server.Handle, _sessionId);
                _connectTime    = NativeMethodsHelper.FileTimeToDateTime(wsInfo.ConnectTime);
                _currentTime    = NativeMethodsHelper.FileTimeToDateTime(wsInfo.CurrentTime);
                _disconnectTime = NativeMethodsHelper.FileTimeToDateTime(wsInfo.DisconnectTime);
                _lastInputTime  = NativeMethodsHelper.FileTimeToDateTime(wsInfo.LastInputTime);
                _loginTime      = NativeMethodsHelper.FileTimeToDateTime(wsInfo.LoginTime);
                _userName       =
                    NativeMethodsHelper.QuerySessionInformationForString(server.Handle, _sessionId,
                                                                         WTS_INFO_CLASS.WTSUserName);
                _domainName =
                    NativeMethodsHelper.QuerySessionInformationForString(server.Handle, _sessionId,
                                                                         WTS_INFO_CLASS.WTSDomainName);
            }
        }
Esempio n. 7
0
        private void LoadWtsInfoProperties()
        {
            var info = NativeMethodsHelper.QuerySessionInformationForStruct <WTSINFO>(_server.Handle, _sessionId,
                                                                                      WTS_INFO_CLASS.WTSSessionInfo);

            _connectionState.Value    = info.State;
            _incomingStatistics.Value = new ProtocolStatistics(info.IncomingBytes, info.IncomingFrames,
                                                               info.IncomingCompressedBytes);
            _outgoingStatistics.Value = new ProtocolStatistics(info.OutgoingBytes, info.OutgoingFrames,
                                                               info.OutgoingCompressedBytes);
            _windowStationName.Value = info.WinStationName;
            _domainName.Value        = info.Domain;
            _userName.Value          = info.UserName;
            _connectTime.Value       = NativeMethodsHelper.FileTimeToDateTime(info.ConnectTime);
            _disconnectTime.Value    = NativeMethodsHelper.FileTimeToDateTime(info.DisconnectTime);
            _lastInputTime.Value     = NativeMethodsHelper.FileTimeToDateTime(info.LastInputTime);
            _loginTime.Value         = NativeMethodsHelper.FileTimeToDateTime(info.LogonTime);
            _currentTime.Value       = NativeMethodsHelper.FileTimeToDateTime(info.CurrentTime);
        }
 public void Disconnect(bool synchronous)
 {
     NativeMethodsHelper.DisconnectSession(_server.Handle, _sessionId, synchronous);
 }
 public void Logoff(bool synchronous)
 {
     NativeMethodsHelper.LogoffSession(_server.Handle, _sessionId, synchronous);
 }
Esempio n. 10
0
 private int GetClientBuildNumber()
 {
     return(NativeMethodsHelper.QuerySessionInformationForInt(_server.Handle, _sessionId,
                                                              WTS_INFO_CLASS.WTSClientBuildNumber));
 }
Esempio n. 11
0
 private string GetClientDirectory()
 {
     return(NativeMethodsHelper.QuerySessionInformationForString(_server.Handle, _sessionId,
                                                                 WTS_INFO_CLASS.WTSClientDirectory));
 }
Esempio n. 12
0
 private int GetClientHardwareId()
 {
     return(NativeMethodsHelper.QuerySessionInformationForInt(_server.Handle, _sessionId,
                                                              WTS_INFO_CLASS.WTSClientHardwareId));
 }
Esempio n. 13
0
 private EndPoint GetRemoteEndPoint()
 {
     return(NativeMethodsHelper.QuerySessionInformationForEndPoint(_server.Handle, _sessionId));
 }
Esempio n. 14
0
 private string GetApplicationName()
 {
     return(NativeMethodsHelper.QuerySessionInformationForString(_server.Handle, _sessionId,
                                                                 WTS_INFO_CLASS.WTSApplicationName));
 }
Esempio n. 15
0
 private string GetInitialProgram()
 {
     return(NativeMethodsHelper.QuerySessionInformationForString(_server.Handle, _sessionId,
                                                                 WTS_INFO_CLASS.WTSInitialProgram));
 }
 private int GetClientBuildNumber()
 {
     return(NativeMethodsHelper.QuerySessionInformationForClientBuildNumber(_server.Handle, _sessionId));
 }
Esempio n. 17
0
 private short GetClientProductId()
 {
     return(NativeMethodsHelper.QuerySessionInformationForShort(_server.Handle, _sessionId,
                                                                WTS_INFO_CLASS.WTSClientProductId));
 }
Esempio n. 18
0
 public void Shutdown(ShutdownType type)
 {
     NativeMethodsHelper.ShutdownSystem(Handle, (int)type);
 }
 public void Kill(int exitCode)
 {
     NativeMethodsHelper.TerminateProcess(_server.Handle, _processId, exitCode);
 }