Access is denied message connecting to remote server using impersonation

295 views
Skip to first unread message

Tony

unread,
Dec 27, 2011, 12:37:07 PM12/27/11
to Cassia Users
my remote endpoints are all win 7. i'm running the following code:
string[] servers =
ConfigurationManager.AppSettings["ServerNames"].Split(',');
string serverUser =
ConfigurationManager.AppSettings["UserName"];
string serverPassword =
ConfigurationManager.AppSettings["Password"];
MakeDataTable();
foreach (string server in servers)
{
ITerminalServicesManager mgr = new
TerminalServicesManager();
IntPtr token;
if (!NativeMethods.LogonUser(serverUser, server,
serverPassword, NativeMethods.LogonType.NewCredentials,
NativeMethods.LogonProvider.Default, out token))
{
throw new Win32Exception();
}
try
{
IntPtr tokenDuplicate;

if (!NativeMethods.DuplicateToken(token,
NativeMethods.SecurityImpersonationLevel.Impersonation, out
tokenDuplicate))
{
throw new Win32Exception();
}

try
{
using (WindowsImpersonationContext
impersonationContext = new
WindowsIdentity(tokenDuplicate).Impersonate())
{
using (ITerminalServer serverInstance =
mgr.GetRemoteServer(server))
{
try
{
serverInstance.Open();
IList<ITerminalServicesSession>
sessions = serverInstance.GetSessions();
}
catch (Exception exp)
{
string msg = exp.Message;
string trace = exp.StackTrace;
}
...
when i invoke serverInstance.GetProcesses or any other method on the
serverInstance object, i get an exception. The user i'm connecting as
is an administrator user on the windows 7 remote server. i'm pulling
my hair trying to figure this out. here's the exception:
"Access is denied"
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..ctor(ITerminalServer
server, Int32 sessionId)
at Cassia.Impl.TerminalServer.GetSession(Int32 sessionId)
at DemoMachines.Index.Page_Load(Object sender, EventArgs e) in C:
\Users\Tony\Documents\Visual Studio 2010\Projects\DemoMachines
\DemoMachines\Default.aspx.cs:line 79
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Dan Ports

unread,
Dec 27, 2011, 12:54:36 PM12/27/11
to cassia...@googlegroups.com
Tony,

See this thread. Have you set AllowRemoteRPC appropriately on the Windows 7 machines?

Dan


--
You received this message because you are subscribed to the Google Groups "Cassia Users" group.
To post to this group, send email to cassia...@googlegroups.com.
To unsubscribe from this group, send email to cassia-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cassia-users?hl=en.


Tony

unread,
Dec 27, 2011, 2:25:26 PM12/27/11
to Cassia Users
that did it! thanks again!!

On Dec 27, 9:54 am, Dan Ports <danpo...@gmail.com> wrote:
> Tony,
>
> See this thread<http://groups.google.com/group/cassia-users/browse_thread/thread/7d9b...>.
Reply all
Reply to author
Forward
0 new messages