private static void ActivateProcessMainWindow(IntPtr handle)
 {
     if (handle != IntPtr.Zero)
     {
         APILibrary.ShowWindow(handle, (int)APILibrary.ShowWindowCommands.ShowNA);
         APILibrary.SetForegroundWindow(handle);
     }
 }
Пример #2
0
        public static Image SnipWindow(IntPtr hwnd)
        {
            APILibrary.RECT rc;
            APILibrary.GetWindowRect(hwnd, out rc);

            Bitmap   bmp    = new Bitmap(rc.Right - rc.Left, rc.Bottom - rc.Top, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            Graphics gbmp   = Graphics.FromImage(bmp);
            IntPtr   hdcbmp = gbmp.GetHdc();

            APILibrary.PrintWindow(hwnd, hdcbmp, 0);
            gbmp.ReleaseHdc(hdcbmp);
            gbmp.Dispose();
            return(bmp);
        }
Пример #3
0
        public static Image Snip(IntPtr hwnd)
        {
            APILibrary.fnSetWindowForeground(hwnd);
            Thread.Sleep(100);
            Rectangle rc  = Screen.PrimaryScreen.WorkingArea;
            Bitmap    bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            Graphics  g   = Graphics.FromImage(bmp);

            g.CopyFromScreen(0, 0, 0, 0, rc.Size);
            using (LibScreenScraperHelper snipper = new LibScreenScraperHelper(bmp))
                if (snipper.ShowDialog() == DialogResult.OK)
                {
                    return(snipper.Image);
                }
            return(bmp);
        }
Пример #4
0
        public static void Impersonate(string domainName, string userName, string userPassword, Action actionToExecute)
        {
            SafeTokenHandle safeTokenHandle;

            try
            {
                // Call LogonUser to obtain a handle to an access token.
                bool returnValue = APILibrary.LogonUser(userName, domainName, userPassword,
                                                        APILibrary.LOGON32_LOGON_NEW_CREDENTIALS, APILibrary.LOGON32_PROVIDER_DEFAULT,
                                                        out safeTokenHandle);

                if (returnValue == false)
                {
                    int ret = Marshal.GetLastWin32Error();
                    throw new System.ComponentModel.Win32Exception(ret);
                }

                using (safeTokenHandle)
                {
                    // Use the token handle returned by LogonUser.
                    using (WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle()))
                    {
                        using (WindowsImpersonationContext impersonatedUser = newId.Impersonate())
                        {
                            actionToExecute();
                            if (impersonatedUser != null)
                            {
                                impersonatedUser.Undo();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //ex.HandleException();
                //On purpose: we want to notify a caller about the issue /Pavel Kovalev 9/16/2016 2:15:23 PM)/
                //throw;
            }
        }
Пример #5
0
 protected override bool ReleaseHandle()
 {
     return(APILibrary.CloseHandle(handle));
 }