YetAnotherRelogger.Helpers.Tools.Impersonator.Impersonate C# (CSharp) Метод

Impersonate() публичный Метод

Impersonates the specified user account.
public Impersonate ( string userName, string domainName, string password ) : void
userName string Name of the user.
domainName string Name of the domain.
password string The password.
Результат void
        public void Impersonate(string userName, string domainName, string password)
        {
            Impersonate(userName, domainName, password, LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT);
        }

Same methods

Impersonator::Impersonate ( string userName, string domainName, string password, LogonType logonType, LogonProvider logonProvider ) : void

Usage Example

Пример #1
0
        private void D3Prefs()
        {
            var imp = new Impersonator();
            if (Parent.UseWindowsUser)
                imp.Impersonate(Parent.WindowsUserName, "localhost", Parent.WindowsUserPassword);
            // Copy D3Prefs
            Logger.Instance.Write("Replacing D3Prefs for user: {0}", Environment.UserName);
            var currentprefs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                               @"\Diablo III\D3Prefs.txt";
            if (Directory.Exists(Path.GetDirectoryName(currentprefs)))
            {
                Logger.Instance.Write("Copy custom D3Prefs file to: {0}", currentprefs);
                try
                {
                    File.Copy(Parent.D3PrefsLocation, currentprefs, true);
                }
                catch (Exception ex)
                {
                    Logger.Instance.Write("Failed to copy D3Prefs file: {0}", ex);
                }
            }
            else
                Logger.Instance.Write("D3Prefs Failed: Path to \"{0}\" does not exist!", currentprefs);
            if (imp != null)
                imp.Dispose();

            // Also replace Default User D3Prefs
            var defaultprefs =
                Regex.Match(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                            string.Format(@"(.+)\\{0}.*", Environment.UserName)).Groups[1].Value;
            if (Directory.Exists(defaultprefs + "\\Default"))
                defaultprefs += "\\Default";
            else if (Directory.Exists(defaultprefs + "\\Default User"))
                defaultprefs += "\\Default User";
            else
                return;
            defaultprefs += @"\Diablo III\D3Prefs.txt";
            if (Directory.Exists(Path.GetDirectoryName(defaultprefs)))
            {
                Logger.Instance.Write("Copy custom D3Prefs file to: {0}", defaultprefs);
                try
                {
                    File.Copy(Parent.D3PrefsLocation, defaultprefs, true);
                }
                catch (Exception ex)
                {
                    Logger.Instance.Write("Failed to copy d3prefs file: {0}", ex);
                }
            }
            Thread.Sleep(1000);
        }
All Usage Examples Of YetAnotherRelogger.Helpers.Tools.Impersonator::Impersonate