protected override void ProcessRecord() { base.ProcessRecord(); // initialize SYSTEMTIME int structMemLen = Marshal.SizeOf(typeof(SYSTEMTIME)); byte[] buffer = new byte[structMemLen]; SYSTEMTIME sysTime = new 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; int procId = InputObject.Current.ProcessId; int inputHandle = InputObject.Current.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); } if (hndProc != (IntPtr)0 || hndProc != IntPtr.Zero) { NativeMethods.CloseHandle(hndProc); } } }