user1970090
user1970090

Reputation: 235

exceuting some statments only once (vb.net)

I have a question , Can I execute statements only once at first application execution ? can it be done without registery keys or installer?

Upvotes: 1

Views: 1600

Answers (2)

xfx
xfx

Reputation: 1358

Since you do not explain why you don't want to/can use any "common" method for storing state parameters for your application, I will assume that it's for anti-piracy purposes.


I guess it all depends to the depths you want to go.

So, here's something I've done on several commercial applications I've developed (mainly, but not limited, to prevent piracy):

  • Encrypt the original executable using your own proprietary algorithm (perhaps, not necessary in your situation)
  • Create a launcher application which can decrypt and execute your application
  • Implement, into the launcher, a mechanism to modify some areas of the original application, that do not affect its execution (hint: meta-data/resources/etc...)
  • Save the modified code

Consequent executions of the program can then easily detect "parameters/values/settings" by "detecting" such changes.

Again, this is a quite complex and rather obscure way to store start-up arguments (or states) for an application, but again, depending on what you are looking for, this is a quite secure and effective method.


Here's a sample demonstrating the "basics" of this method: HiddenParams

Upvotes: 1

Jeremy Thompson
Jeremy Thompson

Reputation: 65554

Simply store a value in the App.Config

<appSettings>
<add key="HasExecuted" value ="0"/>

In code:

If Convert.ToBoolean(ConfigurationManager.AppSettings("HasExecuted")) = False Then
'Do something only once
End If

Here is a guide to saving/updating the AppConfig: Update app.config system.net setting at runtime

Upvotes: 2

Related Questions