473,809 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remote call to COM impersonating another user

I need to call a COM object from a remote machine using C#. I also need to
pass on a different userID and password to the call. Has anyone done this?
I've used Java to do this using JIntegra, but the application I'm using
requires .NET.

Any advice?
Jan 7 '08
11 3857
I call LogonUser just the way you specified and I'm still getting the 1326:

int ret = CoInitializeSec urity(IntPtr.Ze ro,-1,IntPtr.Zero,I ntPtr.Zero,
RpcAuthnLevel.C onnect,RpcImpLe vel.Impersonate , IntPtr.Zero,
(int)EoAuthnCap .DynamicCloakin g, IntPtr.Zero);

ret is zero ...
bool returnValue = LogonUser("UID" , "Domain", "password",
LOGON32_LOGON_I NTERACTIVE, LOGON32_PROVIDE R_DEFAULT, ref tokenHandle);

returns false with a code of 1326

I can connect to the machine in question using these values and mstsc.exe.
The domain I use to log into my machine is different from the domain I use
above. Is this an issue? Is there some kind of administrative flag keeping
me from doing this? Am I calling CoInitializeSec urity with the wrong values?
I'm using the definitions you sent in an earlier post.

"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:OB******** ******@TK2MSFTN GP02.phx.gbl...
"JCav" <jc********@cin ci.rr.comwrote in message
news:47******** **************@ roadrunner.com. ..
>These are the calls I'm using. LogonUser is failing with a 1326 - invalid
userID or password, even though these work when I log onto the machine.
So I never get far enough to make the call to the COM object.
int retxxx = CoInitializeSec urity(IntPtr.Ze ro, -1, IntPtr.Zero,
IntPtr.Zero, RpcAuthnLevel.C onnect, RpcImpLevel.Imp ersonate, IntPtr.Zero,
(int)EoAuthnCa p.DynamicCloaki ng, IntPtr.Zero);

const int LOGON32_PROVIDE R_DEFAULT = 0;

const int LOGON32_LOGON_I NTERACTIVE = 2;

const int LOGON32_LOGON_N ETWORK = 3;

IntPtr tokenHandle = new IntPtr(0);

bool returnValue = LogonUser(xxx", "yyy", "zzz",LOGON32_L OGON_NETWORK,
LOGON32_PROVID ER_DEFAULT, ref tokenHandle);

And you function declaration looks like:

[DllImport("adva pi32", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(Unman agedType.Bool)]
static extern bool LogonUser(
string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider ,
ref IntPtr hToken);

bool result = LogonUser(name, domain, passwd,
LOGON32_LOGON_I NTERACTIVE ,
LOGON32_PROVIDE R_DEFAULT,
ref tokenHandle);
if (result == false) // If failed
{
}
else // success
{

Note that you should use LOGON32_LOGON_I NTERACTIVE or LOGON32_LOGON_B ATCH
(value 4) as logon type, other types will not return a token that can be
used to impersonate unless you are running in the context of an
administrator (or an account with "SeImpersonateP rivileges" enabled) .
Willy.

Jan 10 '08 #11
"JCav" <jc********@cin ci.rr.comwrote in message
news:47******** **************@ roadrunner.com. ..
>I call LogonUser just the way you specified and I'm still getting the 1326:

int ret = CoInitializeSec urity(IntPtr.Ze ro,-1,IntPtr.Zero,I ntPtr.Zero,
RpcAuthnLevel.C onnect,RpcImpLe vel.Impersonate , IntPtr.Zero,
(int)EoAuthnCap .DynamicCloakin g, IntPtr.Zero);

ret is zero ...
bool returnValue = LogonUser("UID" , "Domain", "password",
LOGON32_LOGON_I NTERACTIVE, LOGON32_PROVIDE R_DEFAULT, ref tokenHandle);

returns false with a code of 1326

I can connect to the machine in question using these values and mstsc.exe.
The domain I use to log into my machine is different from the domain I use
above. Is this an issue? Is there some kind of administrative flag keeping
me from doing this? Am I calling CoInitializeSec urity with the wrong
values? I'm using the definitions you sent in an earlier post.
You can't use LogonUser to get a token from a non trusted domain, if the
callers domain is trusted by the called domain there shouldn't be a problem.
When there is no domain trust, the caller cannot locate the domain and the
call will fail.
CoInitializeSec urity has nothing to do with this. What happens when you call
LogonUser specifying the credentials of a local account?, or the
credentials of an account on a remote system, hereby specifying the machine
name instead of the domain name(same or other domain).

Willy.

Jan 11 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2758
by: Daniel | last post by:
Is it possible to retain local file system read, write, delete access while impersonating for access to a remote drive in a different domain? I need to be able to move files from a local computer to a remote computer. do i have to copy them from the local computer to the remote computer then delete them fromt the local computer after undo-ing the impersonation? Or is there a way to retain access to both the local computer and the remote...
3
2243
by: todd_groten | last post by:
Alright, I've been searching around for some time and have not been able to find anything concrete on fixing an issue I am having. Here's the situation: 1) I have a non-anonymous webservice running on a w2k3ee sp1 server 2) I am behind a corporate firewall, but was able to get our network services group to punch a hole at port 80 through. 3) I'm running the webservice using an impersonation to the service account and have the pool...
4
14470
by: Heliotic | last post by:
Hi everyone, Currently I am working on an application that will perform a remote scan of a specified server using the following code: Type t = Type.GetTypeFromProgID( "Microsoft.Update.Session", "proact" ); UpdateSession UpdSess = (UpdateSession) Activator.CreateInstance(t); This code works quite well, as long as the user you are currently authenticated to also has administrative access on the target device. This
2
2905
by: Jon L. Lovesky | last post by:
Hello all, I am attempting to access a remote folder from an asp.net application (all within the same domain). The application is configured for windows authentication in IIS and the asp.net worker process runs as the local ASP.NET account. When the application is about to access the remote folder I switch the security context to the remote user programmatically, then switch it back afterwards. When I run the application on my local...
1
6669
by: TerrenceJ | last post by:
Hi there I've configure our SBS 2003 server to allow remote access and Outlook over internet. The mail works fine, but when I try remote access, I am asked for username and password, which I complete and then I get this error. ____________________________________ Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\remote\3f1585d2\3070828a" is denied. Description: An unhandled exception occurred...
3
9471
by: Billy Bob | last post by:
Hello In C# how can i start a remote process such as someapp.exe on a remote PC? I know the remote PC's name, but how do I start the app on that PC? Thanks ..
2
23047
by: =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= | last post by:
Hi, I've been trying to use Directory.GetFiles() and also DirectoryInfo.GetFiles() to list files on a remote server using "\\server_name\dir_name" like paths. It works fine on a test windows app, but I get an access error message when the code is running on a asp.net app. First I thought it was just a matter of credentials, so I started to use windows authentication and impersonate the current user, but I still got the same message.
2
4789
by: Vadim Malishev | last post by:
Hello, Can anybody help to solve the following problem? My Windows Service trying to access remote machine to get WindowsDirectory Property over Win32_OperatingSystem WMI class. Both servers are in the same Active Directory domain, so I create special active directory user and impersonate to it before invoke WMI. My code looks like:
3
1613
by: Looch | last post by:
All, I have a remotable object hosted in IIS and one of the methods connects to an Access db on a different machine. I can't seem to connect to the access db. I thought there may have been a permissions issue so I copied the Access db to the physical directory that the virtual dir is pointed to and still it tells me that the file path is not valid.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.