c# - Update dateTimePicker in another process by DTM_SETSYSTEMTIME -
i trying update datetimecontroller in application using dtm_setsystemtime.
bool retval = false; ushort gdt_valid = 0; systemtime td = new systemtime(); td.wyear = 1990; td.wmonth = 4; td.wday = 2; td.wdayofweek = 0; td.whour = 0; td.wmilliseconds = 0; td.wminute = 0; td.wsecond = 0; int erc = sendmessage(handle, dtm_setsystemtime, gdt_valid, ref td);
unfortunately attempt failed, picker not updated, every time return value zero. important thing application having datatimepicker gives error message illegal memory access exception after execute sendmessage command.
can me fix ?
yes, cannot work. 4th argument sendmessage pointer systemtime. pointer value valid in process, not 1 owns control. crashing target app pointer value quite possible. need to
- call openprocess() on target process obtain handle
- call virtualallocex() allocate memory in target process
- call writeprocessmemory() copy systemtime value process target process
- call sendmessage, using pointer value got virtualallocex
- call virtualfreeex() release memory
- call closehandle() release process handle.
lots of things can go wrong here, starting uac stopping executing these highly privileged api functions. function names google well, should have little trouble finding sample code.
Comments
Post a Comment