 |
|
 |
Hi Does this code work with windows 2008 server. I am getting command failed error . Can you please help.
Thanks, Smitha.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have tried the same process both in forms and WPF applications unfortunately am failed to impersonate user in WPF application.
Did i missed anything while impersonating a user in WPF application?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This was written in 2003 using the 1.0 Framework version. It's no longer necessary to use P/Invoke for impersonation. Take a look at System.Threading.Thread.CurrentPrincipal.
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
 |
Hi, It's a nice work. Congratulations!
But,
I would like to run a small windows service application. It will make some tasks and than the service may run another process but with other local credentials. The main service will run under SYSTEM account.
Can you help me?
Thanks!
Willian S. Rodrigues willian_cpp_br@hotmail.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I would like to have this funcionality in an ActiveX running in Windows CE .net
Do you know if this is possible?
Thanks,
Antonio.
Antonio
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The compact framework has no support for the WindowsImpersonationContext class that I see, so the short answer would be no. However, I'm sure there are plenty of ways to achieve this using a P/Invoke approach.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I've tried to use your code, or at least some of it in my project, and I've encountered the following problem:
The code runs, impersonates finely on local computer, but when I try to impersonate a user on an other computer (e.g. "Comp" , "User", "") I get error code 1326, the domain IS "Comp", username IS "User" and there is no password on it. So I don't know the solution for my problem. I've tried your sample application, which encountered the same. Could you provide me some information about this?
OK, I know that if there is no passwd on the share I needn't use this code, but the use of it should not end in the result written above, or is it?
After trying I noticed, that this program impersonates on local computer, because when I've tried to impersonate an admin user on an other computer, which has the same name and passwd as the admin of the local computer, it impersonated on the local computer. Is it possible or I'm missunderstanding something?
thanks in advance: collapo
-- modified at 7:13 Tuesday 21st August, 2007
Thx in advance: Collapo
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi
It is possible. You use mirrored accounts. In this way you can have access to local resources on the OTHER machine. But the question is how to achieve this (ex. access to files on other machines with NTFS rights sets on local account) without creating mirrored accounts on both?
Mirek
|
| Sign In·View Thread·PermaLink | 3.00/5 (5 votes) |
|
|
|
 |
|
 |
Hi,
I'm using Win 2000 Server and the sample application return:
LogonUser() failed with error code: 1314
and then:
DuplicateToken() failed with error code: 6
This error encurred only in a machine, in other machine works fine. I search the code on web and I think that I have to set some permission. But I don't know what.
Please help me, thanks Matteo
|
| Sign In·View Thread·PermaLink | 1.67/5 (2 votes) |
|
|
|
 |
|
 |
I'm sorry, setting the permission "Act as part of the operating system" works fine. Sorry again
|
| Sign In·View Thread·PermaLink | 1.75/5 (4 votes) |
|
|
|
 |
|
|
 |
|
 |
* Log in as Administrator * Execute gpedit.msc * Go to "Local Computer Policy\Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment" and add the account being impersonated to “Act as part of the operating system”.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
i used this solution to impersonate a domain user, but can't do with a local account.
the problem is: - i have a workgroup, has two machine (mac1 & mac2) - i create a local account on (mac1) [username=ysa,password=123] - i create a shared folder on (mac1) called "Images", and assign the local user [ysa] to it. - i want to access this shared folder from (mac2)
Yossef Elnaggar
|
| Sign In·View Thread·PermaLink | 1.20/5 (5 votes) |
|
|
|
 |
|
|
 |
|
 |
The first call to ImpersonateUser() takes about 10 or more seconds, I assume this is because of the Import statements (I read an article that explained exactly why it takes so long but honestly didn't fully understand it). On the second call though, it's instantaneous. Is there a way to speed this process up or maybe Import the dlls when I start my application so that when I make the first call it doesn't get bogged down.
Thanks,
Chris
-- modified at 12:23 Tuesday 4th April, 2006
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
10 seconds seems a bit excessive..? Honestly, I was still learning .NET when I wrote this article over 3 years ago, so I'd recommend using Uwe Keim's code instead of mine. His code is much more up-to-date and easier to use. I'd be curious to know if you are still incurring the latency issue, so let me know. Thanks!
|
| Sign In·View Thread·PermaLink | 4.70/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi,
Is it possible to contain impersonation to a given AppDomain rather than impersonation consuming the full process?
I have a service running under the local system account, but need to impersonate the current user for some functionality (e.g. accessing the current users network share). However I don't want the full service to change it's access rights. I can spawn a seperate process (which impersonates a specifed user) but this therefore consumes more memory.
My service needs to run as the Local System account (not a specified account particular to the domain).
Any ideas?
Thanks Chris
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi, Even i have the same query..
I also want to impersonate a user (i'hav his credentials) from inside a service running under local system account so that i can access "Mapped Drives" that are mapped in the context of the user whom i want to impersonate.
I gave several experiments to this.. like trying and get the UNC name from the mapped name using WNet APIs but no results..
FYI: I can easily access network shares (using UNC names) to which i had access to. But couldnot access mapped drives. Reason i'm aware of, that drives are mapped on a per user basis i.e. i cannot see a drive mapped in some another user's account.
But there must be some workaround.. like impersonating.. (but that too did not help.. )
If someone has a diffenent vision.. pls let us know..
Love, TJ
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
 |
Here you go...
public class NetworkHelper { // Used to Map UNC from a Windows Service
#region Constants //NetResource Scope private const int RESOURCE_CONNECTED = 0x00000001; private const int RESOURCE_GLOBALNET = 0x00000002; private const int RESOURCE_REMEMBERED = 0x00000003;
//NetResource Type private const int RESOURCETYPE_ANY = 0x00000000; private const int RESOURCETYPE_DISK = 0x00000001; private const int RESOURCETYPE_PRINT = 0x00000002;
//NetResource Usage private const int RESOURCEUSAGE_CONNECTABLE = 0x00000001; private const int RESOURCEUSAGE_CONTAINER = 0x00000002;
//NetResource Display Type private const int RESOURCEDISPLAYTYPE_GENERIC = 0x00000000; private const int RESOURCEDISPLAYTYPE_DOMAIN = 0x00000001; private const int RESOURCEDISPLAYTYPE_SERVER = 0x00000002; private const int RESOURCEDISPLAYTYPE_SHARE = 0x00000003; private const int RESOURCEDISPLAYTYPE_FILE = 0x00000004; private const int RESOURCEDISPLAYTYPE_GROUP = 0x00000005;
//Flags private const int CONNECT_UPDATE_PROFILE = 0x00000001; private const int CONNECT_UPDATE_RECENT = 0x00000002; private const int CONNECT_TEMPORARY = 0x00000004; private const int CONNECT_INTERACTIVE = 0x00000008; private const int CONNECT_PROMPT = 0x00000010; private const int CONNECT_NEED_DRIVE = 0x00000020;
#endregion
#region NetResource Structure [StructLayout(LayoutKind.Sequential)] private struct NetResource { public int Scope; public int Type; public int DisplayType; public int Usage; public string LocalName; public string RemoteName; public string Comment; public string Provider; } #endregion
#region Win32 Functions [DllImport("mpr.dll", EntryPoint = "WNetAddConnection2A", CharSet = CharSet.Ansi, SetLastError = true)] private static extern int WNetAddConnection2A(ref NetResource netresource, string password, string username, int flags);
[DllImport("mpr.dll", EntryPoint = "WNetCancelConnection2", CharSet = CharSet.Ansi, SetLastError = true)] private static extern int WNetCancelConnection2(string drivename, int flag, bool force);
#endregion
myLib lib = new myLib();
public bool WNetAddConnection(string LocalDrive, string NetworkFolderPath, string User, string Password, bool Force) { bool success = false;
try { NetResource netresource = new NetResource(); netresource.Scope = RESOURCE_GLOBALNET; netresource.Type = RESOURCETYPE_DISK; netresource.Usage = RESOURCEUSAGE_CONNECTABLE; netresource.DisplayType = RESOURCEDISPLAYTYPE_SHARE; netresource.LocalName = LocalDrive; netresource.RemoteName = NetworkFolderPath; netresource.Comment = ""; netresource.Provider = "";
int Flag = CONNECT_UPDATE_PROFILE;
if (Force) { success = WNetCancelConnection(LocalDrive, true); }
int result = WNetAddConnection2A(ref netresource, Password, User, Flag);
if (result > 0) { throw new System.ComponentModel.Win32Exception(result); } success = true;
} catch (Exception e) { lib.Echo("Error: " + e.Message, myLib.MsgType.FAIL); }
return success; }
public bool WNetCancelConnection(string LocalDrive, bool Force) { bool success = false; try { int result = WNetCancelConnection2(LocalDrive, CONNECT_UPDATE_PROFILE, Force); if (result > 0) { throw new System.ComponentModel.Win32Exception(result); } success = true;
} catch (Exception e) { lib.Echo("Error:" + e.Message, myLib.MsgType.FAIL); } return success;
}
}
|
| Sign In·View Thread·PermaLink | 2.00/5 (3 votes) |
|
|
|
 |
|
 |
Hi guys, i need ur help on the impersonation when accessing the network share drive. here's the scenario: I have 3 file servers in windows domain which are f1.domain.local, f2.domain.local, f3.domain.local for user with the PC not joining to the domain, every time they try to access the the file server they'll need to login into each server with the same credential. I found that rather annoying and would like to write a simple app that would do the job.
the above impersonation code works only on user account reside in the local machine, is there anyway i would be able to do impersonation while the user account reside in the domain. also trying to login into three file servers.
Regards, Godwin
|
| Sign In·View Thread·PermaLink | 1.50/5 (5 votes) |
|
|
|
 |