|
Hi, having some trouble incoking LogonUser, here's the code fragment.
int token;
bool loggedOn = LogonUser(
"CustomAppUser", //Username
"AA02", //Computer name
"customappuser", //Passwd (Remember, this is case-sensitive.)
3, //Logon type = LOGON32_LOGON_NETWORK_CLEARTEXT.
0, //Logon provider = LOGON32_PROVIDER_DEFAULT.
out token //token for the specified user.
);
int ret = GetLastError();
if(ret!=0)
{
Console.WriteLine("Impersonation error. Error code: " + ret.ToString());
return;
}
Error from GetLastError is "203". After a bit of searching, I suspect that LogonUser call LoadUserProfile internally. Reference:
http://support.microsoft.com/default.aspx?scid=KB;en-us;305136&
But I'm not sure how to pinvoke LoadUserProfile... parameter such as "Handle" and "LPPROFILEINFO"... How can I call LoadUserProfile from C#?
Reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/policy/policy/loaduserprofile.asp
Thanks!
norm
|
|
|
|
|
I invoked LoadUserProfile before call LogonUser - it failed to solve the problem. GetLastError still returns error 203 after LogonUser.
Here's how I did it:
//MSDN Sample: http://msdn.microsoft.com/vstudio/using/understand/interop/default.aspx?pull=/library/en-us/dnnetsec/html/SecNetHT13.asp
const int SecurityImpersonation = 2;
IntPtr dupeTokenHandle = DupeToken(
WindowsIdentity.GetCurrent().Token,
SecurityImpersonation); //CAUTION: Current user is different from the user I wish to impersonate.
if(IntPtr.Zero == dupeTokenHandle)
{
Console.WriteLine("Unable to duplicate token.");
}
PROFILEINFO profile = new PROFILEINFO();
profile.dwSize = 32;
profile.lpUserName = "AA02\\CustomAppUser";
bool retval = LoadUserProfile(dupeTokenHandle, ref profile);
if(retval==false)
{
Console.WriteLine("LoadUserProfile failed. Error code: " + Marshal.GetLastWin32Error());
return;
}
bool loggedOn = LogonUser(
"CustomAppUser", //Username
"AA02", //Computer name
"customappuser", //Passwd (Remember, this is case-sensitive.)
3, //Logon type = LOGON32_LOGON_NETWORK_CLEARTEXT.
0, //Logon provider = LOGON32_PROVIDER_DEFAULT.
out token //token for the specified user.
);
int ret = GetLastError();
if(ret!=0)
{
Console.WriteLine("Impersonation error. Error code: " + ret.ToString());
return;
}
It seems to me that you don't need to call LoadUserProfile prior to calling LogonUser - am I right? But what else can be the problem?
THanks!
norm
|
|
|
|
|
I got it working now, it was a really stupid mistake. LogonUser returned true!
It was stupid that I invoked GetLastError after LogonUser returned "true" - indicating no error at all.
Thanks anyway.
norm
|
|
|
|
|
I have been tasked with producing an application that will decode SNMP packets. The short story is that this application must capture SNMP trap events sent from various locations and store the results in a database.
Is anybody aware of any tutorials, code samples that step through the decode process?
post.mode.signature = true;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
I'm looking for someone to help me make sense of the results I'm observing
when using the ThreadPool class in a COM-Interop scenario. Here's the set
up:
1) A classic ASP page instantiates and calls MethodA on COM+ Class (C1).
2) MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class
(N1). (Note: N1 has been registered using RegASM and is present in the
GAC).
3) MethodB of .NET class (N1) uses the ThreadPool.QueueUserWorkItem method
to queue up a call to MethodC on .NET Class (N2).
4) MethodC of .NET Class (N2), (called on a ThreadPool thread),
instantiates and calls MethodD on COM+ class (C2).
5) MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class
(C3).
Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2)
to retrieve the results of the "background" processing. These results are
passed back to COM+ Class (C1) and ultimately displayed on the ASP page.
Note: All COM+ classes are registered within the same COM+ application;
and this application is configured as a "Library" application.
I believe this sequence of calls results in the following transitions:
1)An IIS worker thread, (running C1), transitions to .NET managed thread,
(running N1). I'm not at all clear as to what process owns the .NET
thread.
2) As a result of item#1 a .NET ThreadPool thread, (running N2),
transitions to a COM+ thread, (running C2).
3) I'm assuming the same COM+ Thread from item#2 is used to run C3.
4) The COM+ Thread running C2 and C3 completes and transitions back to
the .NET ThreadPool thread running N2.
5) Based on a flag exposed as a static member of N2, the "original" .NET
Thread begins accessing static members of N2. (These static members are
used to aggregate results across multiple ThreadPool threads.)
6) Finally, the "original" .NET thread transitions back to the IIS worker
thread running C1.
After modifying Machine.Config such that the "ProcessModel" tag used
the "system" account instead of the "machine" account, I was able to get
this working in Debug mode. The modification was required to enable
transition #2 (listed above). Prior to making this modification an
exception was thrown indicating an inability to call COM+ class C2. (Sorry,
I don't recall the exact exception.)
When I say Debug mode, I'm referring to running the code within the
VS.NET and VS6 IDEs and stepping between break points.
With everything working in Debug mode, I then attempted to execute the code
without debugging. Based on well placed App.LogEvent and
EventLog.WriteEntry calls, it appears that the following is occurring:
1) All calls prior to the calling of COM+ Class C3 appear to be working.
2) The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant
returned from this call is empty. During successful execution the
resulting variant contains an array with a "UBound" of 5. The real
puzzling thing about this situation is that an error with COM+ class C3
should result in a variant containing an array with a "UBound" of 3.
There should always be an array returned from COM+ C3!
So the questions are as follows:
1) Is it possible that the return values, (which are passed ByRef), aren't
being marshalled properly between COM+ Class C2 and COM+ Class C3?
2) Is it possible that the call from COM+ Class C2 to COM+ Class C3 is
failing silently? (Placing App.LogEvent calls within COM+ Class C3
requires the involvement of another team.)
3) Is there some security or thread related issue here that I'm just not
seeing? And does this underlying issue explain why things work during
Debug and fail when not running under an IDE managed thread?
Thanks for taking the time to read all of that.
|
|
|
|
|
After further review, it appears that my problem was due to an apparent inability to call an in-process STA COM+ class from a MTA "ThreadPool" Thread.
Moving COM+ Class (C2) to an out-of-process "Server" application allowed me to "work-around" my error.
Does anyone know whether it is possible to call in-process COM+ classes from a "ThreadPool" thread?
Thanks!
|
|
|
|
|
Hi, very simple question:
WindowsPrincipal principal = (WindowsPrincipal) Thread.CurrentPrincipal;
bool bIsInRole = principal.IsInRole(WindowsBuiltInRole.Administrator);
What if the role is a user defined role? (ie. not built in)
Thanks.
norm
|
|
|
|
|
How about:
bool isDishWasher = principal.IsInRole("DishWasher");
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Thanks. I got it working now =)
norm
|
|
|
|
|
This may sound stupid ...
Could someone explain the difference between OleDB and ADO? I mean I can use both to access a database so what is the point of having both available ?
Am I right in this?
Cheers
John
|
|
|
|
|
Yes, you are right, you can use both.
ADO is a layer over OLEDB. ADO is easier to use, is fast and it's "universal", meaning that code using ADO (and well written queries) can usually be database independent. ADO achieves this through a lowest common denominator implementation and feature querying. So, most high-level code uses ADO.
OTOH, OLEDB can be used both as a database commnunication driver for ADO and as a substitute for ADO. If you want to use some specific DB features (e.g., some BLOB specific features on Oracle), OLEDB is the way to go. It is slightly faster than ADO (my own biased benchmarks showed less than 5% difference, but YMMV).
But this is a weird question on a C# forum
Help me dominate the world - click this link and my army will grow
|
|
|
|
|
Hi!
I need to use configuration file with subSections.
<Section>
<SubSection>
<Parameter>
<Parameter>
<Parameter>
</SubSection>
</Section>
I use Configuration Application Management Block (CMAB)
that does not support SectionGroup or something like that.
May be someone knows how can I manage this.
Thank you!
|
|
|
|
|
I should make application that RIP , Play and convert audio and video files in .NET but I can not find any library(components) about it.I found ActiveX controls ,but I prefer to use .NET components.If anybody know some link or answer about that.....
|
|
|
|
|
How can I add double qoute(") in my string?
Mazy
No sig. available now.
|
|
|
|
|
Escape the double quote:
s = "this \" is a double quote";
or
s = @"this "" is a double quote";
|
|
|
|
|
Thanks Corinna.
Mazy
No sig. available now.
|
|
|
|
|
\" perhaps?
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
Yes.
Mazy
No sig. available now.
|
|
|
|
|
|
I saw a lot of datagrid messages but still remain a few questions for me:
1. there is a simple way to know if the grid was edited or not (= any cell changed, deleted, added or not)
2. I want a grid that is not readonly but allows just update or update and delete but no insert, ...
3. want to scroll down: when the grid is show the last lines be visible
4. a kind of alternate color: change rows background upon a cell value (have more records for a day and I want to have rows for same day in same color, changing background for the next day)
Thanks
|
|
|
|
|
Anyone have any experience with used the FileSystemWatcher in conjunction with FTP?
Trying to processing incoming files at are being dropped into a given directory via FTP, but don't want to start processing until the FTP process has *completed* writing the file to disk.
Any ideas? The NotifyFilters don't seem to allow for the "close" on the file.
TIA.
~Mike Stanbrook
|
|
|
|
|
Ok, I've gotten around the problem by attempting to open exclusively, and sleep until successful.
However, for large files, I still get 3+ "Changed" events thrown.. anyone have a good scheme for blocking/ignoring the extraneous events ?
TIA.
~Mike Stanbrook
|
|
|
|
|
Hello all. I'm trying to do some tag swapping and having no success. My tags come in the following format: <#data>.
The data can be letters, numbers or spaces. My colleague here at work wrote the following:
<#([^>])>
This seems to match everything fine but I'm using a CodeProject tool called <a href="http://www.codeproject.com/dotnet/Expresso.asp ">Expresso</a>[<a target=_blank title='New Window' href="http://www.codeproject.com/dotnet/Expresso.asp ">^</a>]and the match occurs only for the first character. Is there a way to make it recursively grab all the characters in between tags?
I tried this with groups and was very frustrated:
<#(?<data>([^>]+)>
It still only seems to grab the first character.
Thanks in advance...
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
|