Beispiel #1
0
        public static IEnumerable <AdminAccess> Test_AdminAccess(Args_Test_AdminAccess args = null)
        {
            if (args == null)
            {
                args = new Args_Test_AdminAccess();
            }

            IntPtr LogonToken = IntPtr.Zero;

            if (args.Credential != null)
            {
                LogonToken = InvokeUserImpersonation.Invoke_UserImpersonation(new Args_Invoke_UserImpersonation {
                    Credential = args.Credential
                });
            }

            var IsAdmins = new List <AdminAccess>();

            foreach (var Computer in args.ComputerName)
            {
                // 0xF003F - SC_MANAGER_ALL_ACCESS
                // http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981(v=vs.85).aspx
                var Handle    = NativeMethods.OpenSCManagerW($@"\\{Computer}", "ServicesActive", 0xF003F);
                var LastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error();

                var IsAdmin = new AdminAccess
                {
                    ComputerName = Computer
                };

                // if we get a non-zero handle back, everything was successful
                if (Handle != IntPtr.Zero)
                {
                    NativeMethods.CloseServiceHandle(Handle);
                    IsAdmin.IsAdmin = true;
                }
                else
                {
                    Logger.Write_Verbose($@"[Test-AdminAccess] Error: {new System.ComponentModel.Win32Exception((int)LastError).Message}");
                    IsAdmin.IsAdmin = false;
                }
                IsAdmins.Add(IsAdmin);
            }

            if (LogonToken != IntPtr.Zero)
            {
                InvokeRevertToSelf.Invoke_RevertToSelf(LogonToken);
            }

            return(IsAdmins);
        }
Beispiel #2
0
 public static IEnumerable <AdminAccess> Invoke_CheckLocalAdminAccess(Args_Test_AdminAccess args = null)
 {
     return(InvokeCheckLocalAdminAccess.Invoke_CheckLocalAdminAccess(args));
 }
Beispiel #3
0
 public static IEnumerable <AdminAccess> Test_AdminAccess(Args_Test_AdminAccess args = null)
 {
     return(TestAdminAccess.Test_AdminAccess(args));
 }