Saving application Variable

Hello everyone. I have an interesting application request here.


Some places a product order in a shopping cart of a file.
At the end of the check out process they download a EXE file that is a "download manager" and then they proceed to download the file. They can move this EXE to any other computer, and it will know what file to download.

I have the application....but how do you store/hold the customer ID in the application when it is distributed. I have seen this at You buy a song, download the app at the checkout...and the app knows who you are and can download at other locations by just moving the app.

If I can just store the customer id in the app, that is all i would need.

Hope you can help!!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
You can store the customer ID somewhere in the Windows Registry or Windows directory
Use SaveSetting and GetSetting to store and retreive values from the VBA key in the registry:


 SaveSetting appname, section, key, setting

appname String expression containing the name of the application orproject to which the setting applies.
section    String expression containing the name of the section where the key setting is being saved.
key         String expression containing the name of the key setting being saved.
setting    Expression containing the value that key is being set to.

 GetSetting(appname, section, key[, default])

Same as above except default is used for when the key is not in the registry.

This Code example should explain it all. Add 2 command buttons, paste the following and run:

Private Sub Command1_Click()
msg = InputBox("Enter the cust id to store")
SaveSetting "TestApp", "TestSection", "CustID", msg
End Sub

Private Sub Command2_Click()
MsgBox GetSetting("TestApp", "TestSection", "CustID", "No Key Found")
Command1.Enabled = True
End Sub

Private Sub Form_Load()
Command1.Caption = "Save Value"
Command2.Caption = "Get Value"
Command1.Enabled = False
End Sub

       I thinks it a difficult task to save data on a exe, unless you re-compile your application for every company that will use it, which is improper. Probably there is a login screen that must be filled up by the user that will identify them. Another probable way is to create a exe file from winzip which contains thet exe file and a file which contains identifier for the user during run time of your application.

      For the Music software. Normally you are required to registered to run this application. All the data will be either be save on registry or file for your idetity.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

blenettAuthor Commented:
Hello Omnicast,

Definately agree it is far as the music sofware.....there is no login/registration on the app...and you can move the app registry is not involved.

I am thinking if they compile the app during the order process with customer id/order id
maybe with .NET command line compile??

Joachim CarreinSr. Software DeveloperCommented:
let the program talk to a database, and let the user remember some kind of serial number.
that way only 1 exe is needed
Hello blenett

For this sollution you need to write a program for editing your main exe before suppyling it to the user

The main idea is that the exe doesn't get affected if you add data to the end of the exe file so we'll write the customerID to the end of the main exe file using another program and we'll put a function in the main program to read this data

And of course the data will go anywhere the main exe goes

The function that reads the data from the end of the main exe should be pasted in the main program
This function asumes that the customerID is 6 bytes length and uses 4 bytes asure that this data is ours

Private Function GetCustomerID() As String
Dim myPath As String
Dim iData As String * 10

' Open the Me.Exe for binary access
myPath = App.Path
If Right(myPath, 1) <> "\" Then myPath = myPath & "\"
myPath = myPath & App.EXEName & ".exe"

' Read the Last 10 bytes
Open myPath For Binary As #1
    Get #1, FileLen(myPath) - 9, iData
Close #1

' Check if they are our information
If Left(iData, 4) = "~MD~" Then
    GetCustomerID = Mid(iData, 5, 6)
    GetCustomerID = ""
End If

End Function
' ==========================================

And if you want the function which writes to the exe please comment

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi  blenett,
     I have seen a way to write in the exe file. It was posted also here at the expert exchange. But the problem is more about software piracy. Check this post it might help you to understand more about writing data to exe file and reading it.

    I hope this might help you with your problem.

blenettAuthor Commented:
I will look into that example tonight.
blenettAuthor Commented:
Hey Guys I should be testing this this week.

The app to write to the you reccomend doing it in .ASP page or to write a tiny app and call it in .ASP page via shell.

also iHadi, let me know if you have the write portion of your read example.
Hi Blenett,

Here's the 'write portion' that you asked for and I hope it will help


Private Sub PutCustomerID()
Dim myPath As String
Dim iData As String * 10
Dim DataToWrite As String * 6

DataToWrite = "test12"
' Open the Exe for binary access
myPath = YourExePath
Open myPath For Binary As #1
' Read the Last 10 bytes
    Get #1, LOF(1) - 9, iData
    ' Check if they are our information
    If Left(iData, 4) = "~MD~" Then
        ' Write the data only
        Put #1, LOF(1) - 5, DataToWrite
        ' Write the data with our verifing string
        Put #1, LOF(1), "~MD~" & DataToWrite
    End If
Close #1

End Sub

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.