Click here to Skip to main content
15,903,203 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help Symbian Coding + C# Pin
Dave Kreskowiak27-Feb-12 2:11
mveDave Kreskowiak27-Feb-12 2:11 
QuestionRe: Help Symbian Coding + C# Pin
jojoba201127-Feb-12 3:52
jojoba201127-Feb-12 3:52 
AnswerRe: Help Symbian Coding + C# Pin
Pete O'Hanlon27-Feb-12 3:55
mvePete O'Hanlon27-Feb-12 3:55 
Questionget and update control values from another thread Pin
Danzy8326-Feb-12 12:41
Danzy8326-Feb-12 12:41 
AnswerRe: get and update control values from another thread Pin
agha_ali2226-Feb-12 17:48
agha_ali2226-Feb-12 17:48 
AnswerRe: get and update control values from another thread Pin
Dave Kreskowiak26-Feb-12 18:06
mveDave Kreskowiak26-Feb-12 18:06 
AnswerRe: get and update control values from another thread Pin
Shameel26-Feb-12 23:33
professionalShameel26-Feb-12 23:33 
QuestionHelp with impersonation please Pin
CCodeNewbie26-Feb-12 5:42
CCodeNewbie26-Feb-12 5:42 
Hi,

I am trying to get some logged-on user details from a service running as LocalSystem.

After spending the weekend trying to find the best way of doing this, having found that the P/Invoke method is lengthy and arduous and that the get-owner-token-from-process method isn't suitable in this instance I am trying the following method but it won't compile giving non-useful errors.

The code:
C#
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
    foreach (ManagementObject queryObj in searcher.Get())
        {
           string LOU = (queryObj["UserName"].ToString());// returns domain\username - I found this to be the quickest solution
           WindowsIdentity wi = new WindowsIdentity(LOU);// ref http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity
// fails here with security exception - should I be passing a token instead?
           WindowsImpersonationContext ctx = null;
           ctx = wi.Impersonate();
           WindowsPrincipal wp = new WindowsPrincipal(wi);

           string LOU1 = wi.Name;
           string AuthType = wi.AuthenticationType;
           string Authd = wi.IsAuthenticated.ToString();
           string isGuest = wi.IsGuest.ToString();
           string SidNo = wi.Owner.ToString();
           string SidPlain = wi.Owner.Translate(typeof(System.Security.Principal.NTAccount)).ToString();
           string Token = wi.Token.ToString();

           Console.WriteLine(LOU1);
           Console.WriteLine(AuthType);
           Console.WriteLine(Authd);
           Console.WriteLine(isGuest);
           Console.WriteLine(SidNo);
           Console.WriteLine(SidPlain);
           Console.WriteLine(Token);

           foreach (System.Security.Principal.IdentityReference group in wi.Groups)
           {
               Console.WriteLine(group.Translate(typeof(System.Security.Principal.NTAccount)));
           }


Can anyone shed some light on this please?
QuestionRe: Help with impersonation please Pin
Richard MacCutchan26-Feb-12 6:05
mveRichard MacCutchan26-Feb-12 6:05 
AnswerRe: Help with impersonation please Pin
CCodeNewbie26-Feb-12 6:46
CCodeNewbie26-Feb-12 6:46 
GeneralRe: Help with impersonation please Pin
Richard MacCutchan26-Feb-12 6:54
mveRichard MacCutchan26-Feb-12 6:54 
GeneralRe: Help with impersonation please Pin
CCodeNewbie26-Feb-12 7:41
CCodeNewbie26-Feb-12 7:41 
AnswerRe: Help with impersonation please Pin
Luc Pattyn26-Feb-12 7:39
sitebuilderLuc Pattyn26-Feb-12 7:39 
GeneralRe: Help with impersonation please Pin
CCodeNewbie26-Feb-12 10:10
CCodeNewbie26-Feb-12 10:10 
AnswerRe: Help with impersonation please Pin
Luc Pattyn26-Feb-12 6:14
sitebuilderLuc Pattyn26-Feb-12 6:14 
GeneralRe: Help with impersonation please Pin
CCodeNewbie26-Feb-12 6:53
CCodeNewbie26-Feb-12 6:53 
QuestionConverting audio file into a binary display Pin
kfir.alf26-Feb-12 3:20
kfir.alf26-Feb-12 3:20 
AnswerRe: Converting audio file into a binary display Pin
OriginalGriff26-Feb-12 4:12
mveOriginalGriff26-Feb-12 4:12 
GeneralRe: Converting audio file into a binary display Pin
kfir.alf26-Feb-12 4:56
kfir.alf26-Feb-12 4:56 
GeneralRe: Converting audio file into a binary display Pin
Eddy Vluggen26-Feb-12 11:11
professionalEddy Vluggen26-Feb-12 11:11 
GeneralRe: Converting audio file into a binary display Pin
V.26-Feb-12 21:14
professionalV.26-Feb-12 21:14 
QuestionRed Five Labs + C# Pin
jojoba201125-Feb-12 22:46
jojoba201125-Feb-12 22:46 
AnswerRe: Red Five Labs + C# Pin
Dan Mos26-Feb-12 3:48
Dan Mos26-Feb-12 3:48 
QuestionRe: Red Five Labs + C# Pin
jojoba201126-Feb-12 4:01
jojoba201126-Feb-12 4:01 
AnswerRe: Red Five Labs + C# Pin
OriginalGriff26-Feb-12 4:15
mveOriginalGriff26-Feb-12 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.