public static EnvironmentBlockHandle Create(TokenHandle token, IDictionary<string, string> extraEnvironmentVariables)
 {
     using (var environment = Create(token, false))
     {
         var current = environment.GetEnvironmentVariables();
         foreach (var extraEnvironmentVariable in extraEnvironmentVariables)
         {
             current[extraEnvironmentVariable.Key] = extraEnvironmentVariable.Value;
         }
         return Create(current);
     }
 }
예제 #2
0
 public static void Main(string[] args)
 {
     using (var windowsIdentity = WindowsIdentity.GetCurrent())
     {
         using (var token = new TokenHandle(windowsIdentity))
         {
             var groups = token.GetGroupsTokenInformation(TokenInformationClass.TokenLogonSid);
             SecurityIdentifier securityIdentifier = groups.Single().SecurityIdentifier;
             Console.WriteLine("Is Account: {0}", securityIdentifier.IsAccountSid());
             Console.WriteLine("SID: {0}", securityIdentifier);
             Console.WriteLine("ProfilePath: {0}", token.GetUserProfileDirectory().FullName);
         }
     }
 }
예제 #3
0
 public static ProcessInformation CreateAsUser(TokenHandle tokenHandle, string applicationName, string commandLine, bool inheritHandles, ProcessCreationFlags creationFlags, EnvironmentBlockHandle environmentHandle, string currentDirectory, ProcessStartInfo startInfo, ProcessSecurity processSecurity = null, ThreadSecurity threadSecurity = null)
 {
     using (var processSecurityAttributes = processSecurity == null ? new SecurityAttributes() : new SecurityAttributes(processSecurity))
     {
         using (var threadSecurityAttributes = threadSecurity == null ? new SecurityAttributes() : new SecurityAttributes(threadSecurity))
         {
             ProcessInformationOut processInformation;
             if (!NativeMethods.CreateProcessAsUser(tokenHandle, applicationName, commandLine, processSecurityAttributes, threadSecurityAttributes, inheritHandles, creationFlags, environmentHandle ?? new EnvironmentBlockHandle(), currentDirectory, startInfo, out processInformation) || processInformation.ProcessHandle == IntPtr.Zero || processInformation.ThreadHandle == IntPtr.Zero)
             {
                 ErrorHelper.ThrowCustomWin32Exception();
             }
             return new ProcessInformation(processInformation.ProcessHandle, processInformation.ProcessId, processInformation.ThreadHandle, processInformation.ThreadId);
         }
     }
 }
예제 #4
0
 public static extern bool DuplicateTokenEx(TokenHandle handle, TokenAccessRights desiredAccess, SecurityAttributes securityAttributes, SecurityImpersonationLevel impersonationLevel, TokenType tokenType, out TokenHandle newToken);
 public IEnvironmentBlock Create(TokenHandle token, bool inherit)
 {
     var handle = EnvironmentBlockHandle.Create(token, inherit);
     return new EnvironmentBlock(handle);
 }
예제 #6
0
 public static extern bool CreateProcessWithTokenW(TokenHandle tokenHandle, ProcessLogonFlags logonFlags, string applicationName, string commandLine, ProcessCreationFlags creationFlags, EnvironmentBlockHandle environment, string currentDirectory, ProcessStartInfo startupInfo, out ProcessInformationOut processInformation);
예제 #7
0
 public static ProcessInformation CreateWithToken(TokenHandle tokenHandle, ProcessLogonFlags logonFlags, string applicationName, string commandLine, ProcessCreationFlags creationFlags, EnvironmentBlockHandle environment, string currentDirectory, ProcessStartInfo startupInfo)
 {
     ProcessInformationOut processInformation;
     if (!NativeMethods.CreateProcessWithTokenW(tokenHandle, logonFlags, applicationName, commandLine, creationFlags, environment, currentDirectory, startupInfo, out processInformation) || processInformation.ProcessHandle == IntPtr.Zero || processInformation.ThreadHandle == IntPtr.Zero)
     {
         ErrorHelper.ThrowCustomWin32Exception();
     }
     return new ProcessInformation(processInformation.ProcessHandle, processInformation.ProcessId, processInformation.ThreadHandle, processInformation.ThreadId);
 }
예제 #8
0
 public static extern bool LogonUser(string username, string domain, string password, UserLogonType logonType, UserLogonProvider logonProvider, out TokenHandle handle);
예제 #9
0
 public static extern bool LogonUser(string username, string domain, string password, UserLogonType logonType, UserLogonProvider logonProvider, out TokenHandle handle);
예제 #10
0
 public Token(TokenHandle handle)
 {
     _handle = handle;
 }
예제 #11
0
 public IProcessInformation CreateWithToken(TokenHandle token, ProcessLogonFlags logonFlags, string applicationName, string commandLine, ProcessCreationFlags creationFlags, EnvironmentBlockHandle environment, string currentDirectory, ProcessStartInfo startupInfo)
 {
     return ProcessHandle.CreateWithToken(token, logonFlags, applicationName, commandLine, creationFlags, environment, currentDirectory, startupInfo);
 }
예제 #12
0
 public IProcessInformation CreateAsUser(TokenHandle token, string applicationName, string commandLine, bool inheritHandles, ProcessCreationFlags creationFlags, EnvironmentBlockHandle environment, string currentDirectory, ProcessStartInfo startInfo, ProcessSecurity processSecurity = null, ThreadSecurity threadSecurity = null)
 {
     return ProcessHandle.CreateAsUser(token, applicationName, commandLine, inheritHandles, creationFlags, environment, currentDirectory, startInfo, processSecurity, threadSecurity);
 }
예제 #13
0
 public Token(TokenHandle handle)
 {
     _handle = handle;
 }
예제 #14
0
        public IToken Logon(string username, string domain, SecureString password, UserLogonType logonType = UserLogonType.Interactive, UserLogonProvider logonProvider = UserLogonProvider.Default)
        {
            var handle = TokenHandle.Logon(username, domain, password, logonType, logonProvider);

            return(new Token(handle));
        }
예제 #15
0
 public static EnvironmentBlockHandle Create(TokenHandle token, bool inherit)
 {
     EnvironmentBlockHandle environmentBlockHandle;
     if (!NativeMethods.CreateEnvironmentBlock(out environmentBlockHandle, token, inherit))
     {
         ErrorHelper.ThrowCustomWin32Exception();
     }
     return environmentBlockHandle;
 }
예제 #16
0
 public static extern bool GetUserProfileDirectory(TokenHandle token, StringBuilder profileDir, ref int size);
예제 #17
0
 public static extern bool LoadUserProfile(TokenHandle token, ref ProfileInfo profileInfo);
예제 #18
0
 public static extern bool DuplicateTokenEx(TokenHandle handle, TokenAccessRights desiredAccess, SecurityAttributes securityAttributes, SecurityImpersonationLevel impersonationLevel, TokenType tokenType, out TokenHandle newToken);
예제 #19
0
 public static extern bool UnloadUserProfile(TokenHandle token, IntPtr profileInfo);
예제 #20
0
 public static extern bool LoadUserProfile(TokenHandle token, ref ProfileInfo profileInfo);
예제 #21
0
 public static extern bool CreateProcessAsUser(TokenHandle tokenHandle, string applicationName, string commandLine, SecurityAttributes processAttributes, SecurityAttributes threadAttributes, bool inheritHandles, ProcessCreationFlags creationFlags, EnvironmentBlockHandle environment, string currentDirectory, ProcessStartInfo startInfo, out ProcessInformationOut processInformation);
예제 #22
0
 public static extern bool UnloadUserProfile(TokenHandle token, IntPtr profileInfo);
예제 #23
0
 public static extern bool OpenProcessToken(ProcessHandle processHandle, TokenAccessRights desiredAccess, out TokenHandle tokenHandle);
예제 #24
0
 public static extern bool GetUserProfileDirectory(TokenHandle token, StringBuilder profileDir, ref int size);
 public IEnvironmentBlock Create(TokenHandle token, IDictionary<string, string> extraEnvironmentVariables)
 {
     var handle = EnvironmentBlockHandle.Create(token, extraEnvironmentVariables);
     return new EnvironmentBlock(handle);
 }
예제 #26
0
 public static extern bool CreateEnvironmentBlock(out EnvironmentBlockHandle environment, TokenHandle token, bool inherit);