sanfilip / cassia

Automatically exported from code.google.com/p/cassia
0 stars 0 forks source link

session.applicationname throws "parameter incorrect" when no application listed #64

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
  Dim tsmanager As TerminalServicesManager = New TerminalServicesManager
        Using Server As ITerminalServer = tsmanager.GetRemoteServer("servername")
            Server.Open()
            For Each Session As ITerminalServicesSession In Server.GetSessions()
                Try
                    Response.Write(String.Format("{0} {1}", Session.UserName, Session.ApplicationName))
                    Response.Write("<BR>")
                Catch ex As System.ComponentModel.Win32Exception
                    If ex.Message = "The parameter is incorrect" Then
                        Continue For
                    End If

                End Try

            Next
        End Using

I would expect the property to return a null or string.empty result not an 
exception

What version of Cassia are you using (e.g. 2.0.0.60)? 2.1.0.119

On what Windows version is your code running? 2008r2 and 2003 sp 2

Is your code running as a Windows service, an ASP.NET application, or a
standalone application? asp.net 4.0

What Windows version is running on the remote server you are trying to
access (if any)? 2003

System.ComponentModel.Win32Exception was unhandled by user code
  ErrorCode=-2147467259
  Message=The parameter is incorrect
  NativeErrorCode=87
  Source=Cassia
  StackTrace:
       at Cassia.Impl.NativeMethodsHelper.QuerySessionInformation[T](ITerminalServerHandle server, Int32 sessionId, WTS_INFO_CLASS infoClass, ProcessSessionCallback`1 callback)
       at Cassia.Impl.NativeMethodsHelper.QuerySessionInformationForString(ITerminalServerHandle server, Int32 sessionId, WTS_INFO_CLASS infoClass)
       at Cassia.Impl.TerminalServicesSession.GetApplicationName()
       at Cassia.Impl.LazyLoadedProperty`1.get_Value()
       at Cassia.Impl.TerminalServicesSession.get_ApplicationName()
       at Jlo_30.jlo30test_2.find45sessions() in C:\Work\Jay\Jlo_30\jlo30test_2.aspx.vb:line 41
       at Jlo_30.jlo30test_2.btn1_Click(Object sender, EventArgs e) in C:\Work\Jay\Jlo_30\jlo30test_2.aspx.vb:line 17
       at DevExpress.Web.ASPxEditors.ASPxButton.OnClick(EventArgs e)
       at DevExpress.Web.ASPxEditors.ASPxButton.RaisePostBackEvent(String eventArgument)
       at DevExpress.Web.ASPxClasses.ASPxWebControl.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

Original issue reported on code.google.com by jay3...@gmail.com on 2 Nov 2012 at 5:21

GoogleCodeExporter commented 8 years ago
I understand what you're saying and appreciate the desire to avoid dealing with 
Win32Exceptions. However, the general design philosophy of Cassia has been to 
filter the underlying API behavior as little as possible, except where 
necessary to provide consistent functionality across different Windows 
versions. The behavior of ITerminalServicesSession.ApplicationName is 
consistent across all versions of Windows, as far as I know, so I'm not 
planning to change the implementation of 
ITerminalServicesSession.ApplicationName. You could work around that by adding 
an extension method if you like -- maybe something like 
ITerminalServicesSession.SafeApplicationName().

Original comment by danports on 2 Nov 2012 at 6:47