Click here to Skip to main content
15,915,164 members
Home / Discussions / C#
   

C#

 
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 
C#
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms;

namespace MyProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    string LOU = (queryObj["UserName"].ToString());// returns domain\username
                    Console.WriteLine(LOU);
                    Console.ReadLine();
                    WindowsIdentity wi = new WindowsIdentity(LOU);// ref http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity
                    WindowsImpersonationContext ctx = null;
                    ctx = wi.Impersonate();
                    WindowsPrincipal wp = new WindowsPrincipal(wi);

                    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(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)));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }
}


I know there are a lot of non-required references listed but I have just copied and pasted from the service into the Console App. while testing the code. Am I missing one?
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 
QuestionRe: Red Five Labs + C# Pin
jojoba201126-Feb-12 4:23
jojoba201126-Feb-12 4:23 
AnswerRe: Red Five Labs + C# Pin
Dan Mos26-Feb-12 9:00
Dan Mos26-Feb-12 9:00 
QuestionRe: Red Five Labs + C# Pin
jojoba201126-Feb-12 23:18
jojoba201126-Feb-12 23:18 
AnswerRe: Red Five Labs + C# Pin
Pete O'Hanlon27-Feb-12 0:08
mvePete O'Hanlon27-Feb-12 0:08 
Questioncant read joystick data Managed DX, SlimDX Pin
DerecL25-Feb-12 13:07
DerecL25-Feb-12 13:07 
QuestionHelp need regarding SendMessageTimeout for IE window Pin
vishal nerkar25-Feb-12 7:51
vishal nerkar25-Feb-12 7:51 
AnswerRe: Help need regarding SendMessageTimeout for IE window Pin
DaveyM6925-Feb-12 8:35
professionalDaveyM6925-Feb-12 8:35 
GeneralRe: Help need regarding SendMessageTimeout for IE window Pin
vishal nerkar25-Feb-12 20:37
vishal nerkar25-Feb-12 20:37 

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.