Using VB to edit specific memory locations values

I have found a few memory locations on my computer that i'd like to edit using VB, whats the syntax envolved in doing such a thing?

Lets say the memory location is "D5D419" and the memory value is "1234556789" how do i edit that memory value for that specific location using VB code to be "abcdefghij"?

Who is Participating?
AzraSoundConnect With a Mentor Commented:
May provide insight:
"Scan Another Process for a Memory Value and Replace It"
you cannot do that
however in dos mode you could do it with Quickbasic
if i remember right like so:
def seg = TheSegmentAdres
poke TheOffsetAdres,1234
craigewensAuthor Commented:
Well i have heard of the "poke" cmd before, here is MSDNs definition:
In dynamic data exchange (DDE), to send data from a destination application to a source application. A form's LinkMode property must be set to Source to allow a destination application to send data to controls on the form.

This is where i fall over....I'm sure it's possible (espicially if it's possible in dos) but i'm unsure of the syntax again... Help!
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

the DDE poke is not the same as the Quickbasic poke
the Quickbasic poke 'pokes' a value in a memory location
DDE's poke sends a value to a DDE recipient
and no you can not do it in windows, simply because the memory windows allocates to your program is not physical memory
well maybe it can be done with C and a program that runs in the kernel, but thats way out of my league, and of VB's
craigewensAuthor Commented:
Hummm... so what stops me from getting my variable (the value i wish to place into a certain mem loaction) and passing it through a dos cmd to the relavent mem location to achieve the same thing?.. i know it's not as sexy but would such a thing get the job done till a more suitable solution comes along or someone else comes up with a different idea?

No offence, but its 2am here and i'm certainly not thinking straight :)

Do you know for sure it's impossible to do it through VB 100%?

I certainly dont... (which is obvious)

Either way i'm off to bed... lets see how many comments we get tomorrow morning...


IF AND ONLY IF both proggys are created by you...

Why don't you save whatever variables you want into a file, then let the 2 proggys communicate through that : )

That's it!

glass cookie : )

PS. Ignore me if this is out-of-point : )
>>so what stops me...
well for one thing it has to be true dos mode
and in dos you can only reach 640K of memory
and dos uses a segmented memory model (16 bits you know)
and you have to know very well what you are doing,if not and you are lucky the system will crash,if you are unlucky the system will not crash and some data will be corrupted
but if you really have to do it, there is a program that comes with dos that will allow you to do it: debug.exe
and Qbasic comes with dos to
and then there is the powerbasic console compiler wich still has 'peek' and 'poke'(if i remember well)
so just go ahead, crashing only hurts for a moment
>>Do you know for sure it's impossible to do it through VB 100%?
well lets say i am 99.999999% sure
have a good night
well, I think there might be way to do this, but I am not sure whether it will work or not.

Firstly, add this decleration.

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

and when you want to edit a location, use this line of code:

CopyMemory ByVal MemLoc, ByVal StrPtr(NewVal), LenB(NewVal)

MemLoc is the memory location, which is in your case: "D5D419" . But, you should convert this value to long. I think this could be done by doing the following:
  MemLoc = CLng(&HD5D419)
Notice that I added &H before the hexa address.

And finally NewVal is the string that holds the new value, which is "abcdefghij".

Notice also that the length (in bytes) of the source string must be equal to or less than the destination.  

To be honest, I didn't test. However, try it!

well the problem with copymemory is that it needs valid pointers
and i doubt that a physical memory adress is a valid pointer
it ofcource is well suited to copy from one variable to another
but for that saying a=b is the preferred way
>>Notice also that the length (in bytes) of the source string must be equal to or less than the destination
well thats not needed you know, copymemory will gladly overwrite anything thats in memory
>>To be honest, I didn't test. However, try it!
yes why not try it, crashing only hurst a moment

AzraSound has got it right.
You CAN use RtlMoveMemory to read and write to a memory location, but only a location in your own app's memory.
The Peek and Poke functions do exist in VB, but have the same problem. DOS programs have the same restrictions.

Hi, craigewens.
I'm highly recomended you to read Jeffry Richer's book "Programming applications for win32" for understanding how windows work with RAM.
BTW, AzraSound, did you check sample on XP? Someone told me it doesn't work.

Hey Ark,
Don't know...I don't have an XP machine to test it out on.  It wouldn't surprise me with Microsoft's wonderful history of backwards compatibility.   :-)
Hi craigewens,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: AzraSound and Ark

craigewens, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer
per recommendation

Community Support Moderator @Experts Exchange

Ark points for you at:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.