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); } }
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); } } }
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); } } }
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); }
public static extern bool CreateProcessWithTokenW(TokenHandle tokenHandle, ProcessLogonFlags logonFlags, string applicationName, string commandLine, ProcessCreationFlags creationFlags, EnvironmentBlockHandle environment, string currentDirectory, ProcessStartInfo startupInfo, out ProcessInformationOut processInformation);
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); }
public static extern bool LogonUser(string username, string domain, string password, UserLogonType logonType, UserLogonProvider logonProvider, out TokenHandle handle);
public Token(TokenHandle handle) { _handle = handle; }
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); }
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); }
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)); }
public static EnvironmentBlockHandle Create(TokenHandle token, bool inherit) { EnvironmentBlockHandle environmentBlockHandle; if (!NativeMethods.CreateEnvironmentBlock(out environmentBlockHandle, token, inherit)) { ErrorHelper.ThrowCustomWin32Exception(); } return environmentBlockHandle; }
public static extern bool GetUserProfileDirectory(TokenHandle token, StringBuilder profileDir, ref int size);
public static extern bool LoadUserProfile(TokenHandle token, ref ProfileInfo profileInfo);
public static extern bool UnloadUserProfile(TokenHandle token, IntPtr profileInfo);
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);
public static extern bool OpenProcessToken(ProcessHandle processHandle, TokenAccessRights desiredAccess, out TokenHandle tokenHandle);
public IEnvironmentBlock Create(TokenHandle token, IDictionary<string, string> extraEnvironmentVariables) { var handle = EnvironmentBlockHandle.Create(token, extraEnvironmentVariables); return new EnvironmentBlock(handle); }
public static extern bool CreateEnvironmentBlock(out EnvironmentBlockHandle environment, TokenHandle token, bool inherit);