Issue 81 in cassia: Access Denied error only when trying to log off a user

151 views
Skip to first unread message

cas...@googlecode.com

unread,
Jun 12, 2015, 8:50:32 AM6/12/15
to cassi...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 81 by jather...@northpennlegal.org: Access Denied error only when
trying to log off a user
https://code.google.com/p/cassia/issues/detail?id=81

What steps will reproduce the problem?
1. Code to log off disconnected user
2. Try to log them off
3. Receive "Access Denied" error even when local using elevated privileges.

What is the expected result? What happens instead?
The user should be logged off, Receive "Access Denied error, even when
privileges are elevated.

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

On what Windows version is your code running?
Windows 8.1 and/or Windows 2012 R2 both 64bit

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

Stand alone

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

Windows 2012 R2

Please provide any additional information below. If you are running into an
exception, please include a stack trace (at least the portion of it that
relates to Cassia).

Looked through documentation for an area to put an administrative UID and
password but found nothing. I also searched through existing tickets and
found some information but all that seems to be "All Connections" I only
get it when trying to log someone out.

Thank you for your time.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

cas...@googlecode.com

unread,
Jun 12, 2015, 9:04:13 AM6/12/15
to cassi...@googlegroups.com

Comment #1 on issue 81 by danports: Access Denied error only when trying to
Access denied errors generally indicate either a firewall issue or a
permissions issue. Issue 34 has some information on how to impersonate
other users (e.g. administrators). Is your code running as an account that
has administrator privileges on the local/remote machine? Did you make any
changes to the standard Remote Desktop permissions? (See
https://technet.microsoft.com/en-us/library/cc753032.aspx)

cas...@googlecode.com

unread,
Jun 12, 2015, 11:29:50 AM6/12/15
to cassi...@googlegroups.com

Comment #2 on issue 81 by jather...@northpennlegal.org: Access Denied error
only when trying to log off a user
https://code.google.com/p/cassia/issues/detail?id=81

This is the code I used based on the code used in Issue 34, No matter what
combination I try it still shows access denied, Firewall is off at the
moment. As I stated, I am an administrator from the remote development pc
as well as the actual Terminal Server. Any help would be appreciated...


Private Sub btnConnectRemote_Click(sender As Object, e As EventArgs)
Handles btnConnectRemote.Click
Dim serverName As String = InputBox("Connect to Server")
Dim usrName As String = String.Empty
Dim token As IntPtr


If Not NativeMethods.LogonUser("Administrator",
serverName, "adminpassword", NativeMethods.LogonType.NewCredentials,
NativeMethods.LogonProvider.Default, token) Then
Throw New Win32Exception
End If

Try
Dim tokenDuplicate As IntPtr

If Not NativeMethods.DuplicateToken(token,
NativeMethods.SecurityImpersonationLevel.Impersonation, tokenDuplicate) Then
Throw New Win32Exception()
End If

Try
Using impersonationContext As WindowsImpersonationContext =
New WindowsIdentity(tokenDuplicate).Impersonate
Using serverInstance = iTSM.GetRemoteServer(serverName)
serverInstance.Open()

rtbList.Text = "Retreiving User List..."
For Each session As ITerminalServicesSession In
serverInstance.GetSessions
If session.ConnectionState =
ConnectionState.Disconnected Then
usrName = session.UserName
session.Logoff(True)
rtbList.Text &= String.Concat(usrName, "
has been logged off...")
End If
Next

For Each session As ITerminalServicesSession In
server.GetSessions
rtbList.Text &=
String.Concat(session.UserAccount, vbTab, vbTab, " Session ID: ",
session.SessionId, vbTab, vbTab, " Connection State:",
session.ConnectionState, vbCrLf)
Next

serverInstance.Close()
End Using
impersonationContext.Undo()
End Using
Catch ex As Exception
rtbList.Text &= String.Concat("Error Occured:", ex.ToString)
Finally
If tokenDuplicate <> IntPtr.Zero Then
NativeMethods.CloseHandle(tokenDuplicate)
End If
End Try

Catch ex As Exception

Finally
If token <> IntPtr.Zero Then
NativeMethods.CloseHandle(token)
End If
End Try

End Sub

cas...@googlecode.com

unread,
Jun 12, 2015, 1:05:52 PM6/12/15
to cassi...@googlegroups.com

Comment #3 on issue 81 by jather...@northpennlegal.org: Access Denied error
only when trying to log off a user
https://code.google.com/p/cassia/issues/detail?id=81

Close this ticket, I found that it was attempting to disconnect a system
user with no username attached, I have added code to address this issue,
and it seems to be working now. Thank you for your information.

cas...@googlecode.com

unread,
Jun 12, 2015, 1:15:29 PM6/12/15
to cassi...@googlegroups.com
Updates:
Status: Invalid

Comment #4 on issue 81 by danports: Access Denied error only when trying to
Thanks for the update.
Reply all
Reply to author
Forward
0 new messages