protected override void ProcessRecord() { base.ProcessRecord(); // initialize SYSTEMTIME // int structMemLen = Marshal.SizeOf(typeof(SYSTEMTIME)); int structMemLen = Marshal.SizeOf(typeof(NativeMethods.SYSTEMTIME)); // 20140312 // byte[] buffer = new byte[structMemLen]; var buffer = new byte[structMemLen]; // SYSTEMTIME sysTime = new SYSTEMTIME(Date); // 20140312 // NativeMethods.SYSTEMTIME sysTime = new NativeMethods.SYSTEMTIME(Date); var sysTime = new NativeMethods.SYSTEMTIME(Date); // get memory size of SYSTEMTIME IntPtr dataPtr = Marshal.AllocHGlobal(structMemLen); Marshal.StructureToPtr(sysTime, dataPtr, true); Marshal.Copy(dataPtr, buffer, 0, structMemLen); Marshal.FreeHGlobal(dataPtr); IntPtr hndProc = IntPtr.Zero; IntPtr lpAddress = IntPtr.Zero; // 20140312 // int procId = InputObject.Current.ProcessId; // int inputHandle = InputObject.Current.NativeWindowHandle; int procId = InputObject.GetCurrent().ProcessId; int inputHandle = InputObject.GetCurrent().NativeWindowHandle; try { // inject new SYSTEMTIME into process memory injectMemory(procId, buffer, out hndProc, out lpAddress); // set DateTime to object via pointer to injected SYSTEMTIME NativeMethods.SendMessage((IntPtr)inputHandle, DTM_SETSYSTEMTIME, (IntPtr)GDT_VALID, lpAddress); } finally { // release memory and close handle if (lpAddress != (IntPtr)0 || lpAddress != IntPtr.Zero) { // we don't really care about the result because if release fails there is nothing we can do about it // bool relState = NativeMethods.VirtualFreeEx(hndProc, lpAddress, 0, FreeType.Release); bool relState = NativeMethods.VirtualFreeEx(hndProc, lpAddress, 0, NativeMethods.FreeType.Release); } if (hndProc != (IntPtr)0 || hndProc != IntPtr.Zero) { NativeMethods.CloseHandle(hndProc); } } }
protected override void ProcessRecord() { base.ProcessRecord(); // 20140312 // if (InputObject.Current.ControlType == classic.ControlType.Window) if (InputObject.GetCurrent().ControlType == classic.ControlType.Window) { // 20131208 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // WindowPattern windowPattern = InputObject.GetCurrentPattern(classic.WindowPattern.Pattern) as WindowPattern; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IWindowPattern windowPattern = InputObject.GetCurrentPattern <IWindowPattern>(classic.WindowPattern.Pattern); try { switch (PatternName.ToLower()) { case "close": windowPattern.Close(); break; case "maximize": windowPattern.SetWindowVisualState(classic.WindowVisualState.Maximized); break; case "minimize": windowPattern.SetWindowVisualState(classic.WindowVisualState.Minimized); break; case "restore": windowPattern.SetWindowVisualState(classic.WindowVisualState.Normal); break; } } catch (InvalidOperationException) { ArgumentException ex = new ArgumentException("Target window doesn't support '" + PatternName + "' pattern."); ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null)); } } else { ArgumentException ex = new ArgumentException("Cannot call WindowPattern on object that is not a Window."); ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null)); } }