Go Premium for a chance to win a PS4. Enter to Win


Using VB to edit specific memory locations values

Posted on 2002-07-04
Medium Priority
Last Modified: 2010-05-02
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"?

Question by:craigewens
  • 4
  • 2
  • 2
  • +6

Expert Comment

ID: 7130802
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

Author Comment

ID: 7130808
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!

Expert Comment

ID: 7130827
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 7130846
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...


Expert Comment

ID: 7130870

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 : )

Expert Comment

ID: 7130886
>>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

Expert Comment

ID: 7131442
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!


Expert Comment

ID: 7131549
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

LVL 28

Accepted Solution

AzraSound earned 200 total points
ID: 7132260
May provide insight:
"Scan Another Process for a Memory Value and Replace It"

Expert Comment

ID: 7135479
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.

LVL 28

Expert Comment

ID: 7136752
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.

LVL 28

Expert Comment

ID: 7137721
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.   :-)
LVL 49

Expert Comment

ID: 7990686
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

Expert Comment

ID: 8053238
per recommendation

Community Support Moderator @Experts Exchange

Ark points for you at:

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question