• 0

VB6 - Creating Serial Number Code


Question

Hi guys, I'm back with a new question in continuation of my project ;)

  Quote
I'm creating a small project in Visual Basic 6 for a class I'm taking (Yes we have to create the project in VB6, teacher orders :) )

And so I'm creating a small VB6 Setup program to install a future program I might create...

I'm creating a form for a Serial Number, and it's basically done.

post-1303-0-52983300-1298679057.png

On user Serial number error:

post-1303-0-46329300-1298679084.png

So I have all fields set to setfocus when 5 characters are entered it jumps to the next text box, when 25 characters are inserted it unlocks the next button and runs an if to check the serial.

If the 25 characters don't match the serial, it gives the error msg..

Private Sub CMDNEXT_Click()

If TXTSERIAL1 = 11111 And TXTSERIAL2 = 11111 And TXTSERIAL3 = 11111 And TXTSERIAL4 = 11111 And TXTSERIAL5 = 11111 Then

    MsgBox "Test"
    Unload Me
    FRM04.Show

Else

     IMGWARNING.Visible = True
     LBLERROR.Visible = True
     CMDNEXT.Enabled = False

End If

End Sub

Now as you can see the Serial validation I made is fairly basic (I'm a VB6 noob :blush: ) and If I had to sell (remember this is just a personal project for a course) the program to 5 people, I have to enter 5 serials in the If cycle...

So I was wondering without creating too much complex code, is there a way of creating a random serial code creator ( In vb6, just another exe that creates basic 25 characters serial) , and use it in my project, like each field if it the combination of numbers makes 15 in a text box is valid or something ( did I make sense? :laugh: ) ?

Thanks guys :)

Link to comment
https://www.neowin.net/forum/topic/978416-vb6-creating-serial-number-code/
Share on other sites

11 answers to this question

Recommended Posts

  • 0
  On 26/02/2011 at 00:24, username(); said:

Wait - you are using VB6? Why??

I'm creating a small project in Visual Basic 6 for a class I'm taking (Yes we have to create the project in VB6, teacher orders :) )

And so I'm creating a small VB6 Setup program to install a future program I might create...

  On 26/02/2011 at 00:29, Subject Delta said:

If you really want to make your serial code potentially secure, wouldn't it be safer to base it on a serial algorithm, rather than a single set serial code?

I really don't have much free time to create any complex serial number generator, I have to deliver the project in some days. Remember this just a small project for a course :)

  • 0
  On 26/02/2011 at 00:32, Digitalfox said:

I'm creating a small project in Visual Basic 6 for a class I'm taking (Yes we have to create the project in VB6, teacher orders :) )

And so I'm creating a small VB6 Setup program to install a future program I might create...

I really don't have much free time to create any complex serial number generator, I have to deliver the project in some days. Remember this just a small project for a course :)

You need to come up with something to generate the serial numbers. I would do this if I was doing a class project: add up all the numbers/letters entered by the user, do some mathematical work. The serial is valid if the result is a predefined number. You can easily generate you 25-number serial keys, as long as the result is the number you want.

I hope this is clear as its 2am here and I am kinda tired :)

PS: don't use vb6 to write your setup program, learn something like WIX (Windows Installer Toolkit) or NSIS (Nullsoft's Installer). They can come in handy when distributing your software.

  • 0

Why don't you just use "key". You take that key and use a random number generator based off the work or value in the key. Then using the value generated, you can then use that value that was generated as part of your serial number, and you would include the random number that was chosen to do a mathmatical operation to generate you the value. I don't know how to explain this in sentences so here it is simply:

(with PHP variables lol)

$key = "ILikeCake"

$random_number = random_number_function();

(convert $key to a number value somehow here. Its been years since I've coded anything at all, let alone write a "hello world" application, so bear with me);

$serial= $key * $random_number; (Muliply your key by the random number generated)

$serial = $serial +$random_number (Add the random number that was generated to the beginning, middle, or end of your previous serial number generated the step above, or even mix it into your serial number somehow)

Now at the end, when you verify a serial number, the only constant variable to check for is, when you reverse your math equation used to create the serial number, you make sure it equals the original key "ILikeCake". If somebody tries to change a value of the serial number, eg enter a wrong one, when you perform the decrypt operation you could write, it would not find the original word of "ILikeCake".

So reverse:

Now you need to get the random number from the serial number entered. Wherever you decide will be the random number spot, locate it and read the number into a variable.

Divide serial by random number (the remaining portion of the serial number, NOT THE RANDOM NUMBER PART OF IT!!)

Now you will compare the value of the serial devided by the random number portion, and see if it equals ILikeCake.

I'm sorry to explain this bad, I could make a PHP version in about an hour, however it would be of no use to you. I'm not good at explaining, just doing.

  • 0

This kind of thing is typically done with 3 components: a random component, an optional flagged (feature) component, and a checksum component. The random part is, as the name implies, just some random bytes. The flagged feature component is a set of flags (enums) that map to a particular set of features in your application (for example, the hex value 0x01 might map to ENTERPRISE_EDITION, and 0x02 might map to PERSONAL_EDITION), and are then optionally transformed with the random bytes (by XOR them, for example, though this isn't necessary). The flagged feature component, of course, is entirely optional. The checksum component simply validates the rest of the serial number. For example, if my serial number is 1234-10, the "1234" might be the serial portion, and the "10" is the checksum (in this case, the sum of the individual serial components). So the serial "2345-14" would be another valid serial number. "3456-11" would be invalid. That's how the Post Office validates delivery-point bar codes; the last digit is the sum of the rest of the bar codes digits modulo 10. The random component makes it so that the same feature set creates different checksums.

DON'T LISTEN TO ANYBODY WHO TELLS YOU THAT SIMPLE CHECKSUMMING ISN'T SECURE. Of course it's not, nor is it meant to be! You CANNOT secure a serial number. Microsoft, Adobe, Autodesk, and everybody else cannot do it, so neither can you.

If you want to force somebody to have to patch your application in order to generate serial numbers, you have to digitally sign each serial with a private encryption key, embed the public encryption key in the application, and validate the digital signature of the serial number on each startup. This is what companies like Jetbrains, Atlassian, PGP, etc, do with their serial numbers. In order to crack them, you have to either A) deduce the private key (which is possible with JetBrains since they only use 512-bit RSA keys), B) replace the embedded public key with your own so that you can use your rogue private key to digitally sign serial numbers, or C) patch the program to skip the digital signature validation step. Here is an example of how the Qt configure script checks license keys for various features (it's written in C, but the idea is the same). You can see from line 133 that if the 4th part of the serial number contains "F4M" and the first character of the serial is "F", then you have the COMMERCIAL type and the UNIVERSAL edition.

I hope this provides enough info for you to complete your task. Your first 5 characters could be random, the middle 15 characters could be whatever you want them to be (even more random ones if you want), and the last 5 characters could be a checksum of the other 20. Keep things simple and remember that you cannot prevent somebody from deducing your serial generation algorithm; it's not possible.

  • 0

Thanks guys :)

Here's what I been abbe to do, a small key-gen for creating serials to use on my little project...

post-1303-0-21154000-1298729340.png

But I'm obviously screwing this up, cause Serial any Serial5 should never have less that 5 characters or more than 5 characters...

But sometimes the program just locks after working for 7 or 8 Serials been generated.... :\

I feel such a noob on this.... :(

Dim varSerial1 As Integer
Dim varSerial2 As Double
Dim varSerial3 As Double
Dim varSerial4 As Double
Dim varSerial5 As Double

Private Sub CMDGENERATE_Click()

TXT1.Text = ""
TXT2.Text = ""
TXT3.Text = ""
TXT4.Text = ""
TXT5.Text = ""

varSerial1 = 0
varSerial2 = 0
varSerial3 = 0
varSerial4 = 0
varSerial5 = 0

Randomize

Do While varSerial5 < 10000 And varSerial5 > 99998

  'Serial 1
  Do While varSerial1 < 10000
    varSerial1 = Int(Rnd * 63000) / 2
  Loop

  'Serial 2
  Do While varSerial2 < 10000
    varSerial2 = Int(Rnd * 99998) 
  Loop

  'Serial 3
  Do While varSerial3 < 10000
    varSerial3 = Int(Rnd * 99998) 
  Loop

  'Serial 4
  Do While varSerial4 < 10000
    varSerial4 = Int(Rnd * 99998) 
  Loop

  'Serial 5
  varSerial5 = varSerial3 + varSerial2 + varSerial1 - varSerial4

Loop

TXT1.Text = varSerial1
TXT2.Text = varSerial2
TXT3.Text = varSerial3
TXT4.Text = varSerial4
TXT5.Text = varSerial5

End Sub

  • 0

If the goal is just to create a setup program, I would leave out all the key verification code. Simply have stubs that always return true for the various functions if you want to have it in there at all. That code would generally be application-specific anyway and not part of the generic setup program itself anyway.

If you can manage, I would also make a very basic script file that tells the installer what to do instead of hard-coding it. Basically a file that contains the content of the various setup screens and what the program does in response to actions (ie copy a list of files or whatever.)

I do understand that this might be more complicated than you have time for, but I would rather spend my time on this than key generation/validation stuff, and I'd wager that whoever has to grade the project would think the same. It doesn't have to be advanced, just the bare minimum you can get away with to make the setup program somewhat "generic." It doesn't make much sense to be missing basic parts like that but have advanced features like key validation.

If you really do need the key stuff, you have to remember that you can't just arbitrarily decide to have a key made up of 5x5 characters. They have to actually mean something, not just be random numbers. You can't copy the format of a Microsoft (or whoever) key without understanding why it has that format. Start from scratch with something basic.

  • 0

Well after a bunch of hours the Serial part (The Serial Generator I created and the code on the Setup to accept the Serials ) It's working, even better than I expect it ;)

Thanks everyone for your help :)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • AMD 25.6.1 driver out with RX 9060 XT support and a lot more FSR 4 games by Pulasthi Ariyasinghe A brand-new hardware launch is happening today for AMD, and to make sure its new GPUs are running properly, a new graphics driver has also landed right alongside it. The AMD Software: Adrenalin Edition 25.6.1 driver lands with support for the RX 9060 XT and the AMD Radeon AI PRO R9700, while also finally updating the number of games that support its AMD FidelityFX Super Resolution 4 upscaling technology. The consumer space-targeted RX 9060 XT graphics card comes in 8GB and 16GB flavors starting at $300 and $350 price points, respectively. Check out our launch coverage for this RDNA 4 GPU for more details here. At the same time, the AMD Radeon AI PRO R9700 comes in for handling professional workloads with a whopping 32GB of VRAM. While support for this card has already arrived with the latest driver, AMD is expecting to ship the product sometime in July 2025. The driver has also added official support for Onimusha 2: Samurai's Destiny Remaster as well, the Capcom-developed action game from last month. As for fixes, AMD has said that it has resolved reversed Quality and Performance selections in the Radeon Boost UI, as well as Le Mans Ultimate performance issues on RX 9070 series GPUs. There are quite a few known issues AMD is still working on: Stutter and lower than expected performance may be observed when using alt-tab and streaming to Discord with multiple monitors. Intermittent application crash or driver timeout may be observed while playing Marvel Spiderman 2 with Ray Tracing enabled on Radeon™ RX 9060 XT. Intermittent application crash may be observed when first launching The Last of Us Part 1 on Radeon™ RX 9060 XT graphics products. Stutter may be observed while playing games with some VR headsets at 80Hz or 90Hz refresh rate on some AMD Radeon™ Graphics Products such as the Radeon™ RX 7000 series. Users experiencing this issue are recommended to change the refresh rate as a temporary workaround. Intermittent system or application crash may be observed while playing Cyberpunk 2077 on some AMD Radeon™ Graphics Products such as the Radeon™ RX 7000 series. Intermittent application crash or driver timeout may be observed while playing Monster Hunter Wilds with Radeon™ Anti-Lag and Instant Replay enabled. Artifacts or corruption may appear while playing Battlefield™ V on Radeon™ RX 7000 series graphics products. Stutter may be observed while playing Call of Duty®: Warzone™ Season 03 ‘Verdansk’ map on some AMD Graphics Products. Stutter and lower than expected performance may be observed while playing 4K resolution YouTube videos in Chromium. Users experiencing this issue are recommended to play videos in full screen as a temporary workaround. Texture flickering or corruption may appear while playing The Elder Scrolls IV: Oblivion Remastered with AMD FidelityFX™ Super Resolution enabled on Radeon™ RX 9070 XT. Users experiencing this issue are recommended to disable AMD FidelityFX™ Super Resolution as a temporary workaround. As for FSR 4, these games are now supported by the popular upscaling tech for gaining more frames: Deadzone: Rogue Rem Survival F1 25 Runescape: Dragonwilds Frostpunk 2 Star Wars Outlaws Legacy: Steel & Sorcery Steel Seed Lords of the Fallen Stellar Blade Planetaries Virtua Fighter 5 R.E.V.O QANGA Wild Assault The complete list of games with FSR 4 support, as well as upcoming implementations, can be found on AMD's support page here. The WHQL-certified AMD Software: Adrenalin Edition 25.6.1 driver can now be downloaded from the AMD Software app as well as the changelog page on its official website here.
    • Download Unruly: Fighting Back when Politics, AI, and Law Upend [...] (worth $18) for free by Steven Parker Claim your complimentary eBook worth $18 for free, before the offer ends on June 17. In Unruly: Fighting Back when Politics, AI, and Law Upend the Rules of Business, co-founder of software company Hence Technologies and former Global Deputy CEO of Eurasia Group, Sean West, delivers a startlingly insightful new take on how politics, technology and law are converging to upend the rules of business, generating dangerous risks and incredible opportunities. West convincingly argues that we must understand all three factors to get leverage over the future – a future filled with eroding rule of law, deepfakes that upend elections and court decisions, government pressure for businesses to be patriotic, robot lobbyists, a flood of automated legal claims pointed directly at your company and much more. Unruly offers detailed, practical advice for how to understand the world ahead, how to be resilient in the face of innumerable and complex challenges, and how to surround your business with the people and technology you need to excel in this environment. Inside the book: A framework for understanding all of the pressures on modern corporations from the convergence of geopolitics, technology and law. Strategies for turning your company's legal department into a source of enduring competitive advantage How to navigate government pressure for nationalism when you have a global footprint Approaches to winning in a world where courts are politicized and the law is increasingly automated, built on interviews with top experts Ways to deal with the backlash to ESG at a company level Perfect for executives, managers, entrepreneurs, founders, and other business leaders, Unruly is also a must-read for general counsels and the advisors who serve them. How to get it Please ensure you read the terms and conditions to claim this offer. Complete and verifiable information is required in order to receive this free offer. If you have previously made use of these free offers, you will not need to re-register. While supplies last! Download Unruly: Fighting Back when Politics, AI, and Law Upend [...] (worth $18) for free Offered by Wiley, view other free resources The below offers are also available for free in exchange for your (work) email: VideoProc Converter AI v7.5 for FREE (worth $78.90) – Expires 6/18 Winxvideo AI V3.0 Lifetime License for PC ($69.95 Value) FREE – Expires 6/8 Aiarty Image Enhancer for PC/Mac ($85 Value) FREE – Expires 6/8 Solutions Architect's Handbook, Third Edition ($42.99 Value) FREE – Expires 6/10 AI and Innovation ($21 Value) FREE – Expires 6/11 Unruly: Fighting Back when Politics, AI, and Law Upend [...] ($18 Value) FREE - Expires 6/17 SQL Essentials For Dummies ($10 Value) FREE – Expires 6/17 Continuous Testing, Quality, Security, and Feedback ($27.99 Value) FREE – Expires 6/18 Macxvideo AI ($39.95 Value) Free for a Limited Time – Expires 6/22 The Ultimate Linux Newbie Guide – Featured Free content Python Notes for Professionals – Featured Free content Learn Linux in 5 Days – Featured Free content Quick Reference Guide for Cybersecurity – Featured Free content We post these because we earn commission on each lead so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin The above deal not doing it for you, but still want to help? Check out the links below. Check out our partner software in the Neowin Store Buy a T-shirt at Neowin's Threadsquad Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: An account at Neowin Deals is required to participate in any deals powered by our affiliate, StackCommerce. For a full description of StackCommerce's privacy guidelines, go here. Neowin benefits from shared revenue of each sale made through the branded deals site.
    • AMD RX 9060 XT launches above MSRP and is available to buy now by Sayan Sen At Computex 2025 this year, AMD announced its RX 9060 XT mid-range desktop GPUs. The new graphics card landed in both 8GB and 16GB flavors and targets 1080p as well as light 1440p gaming. The community and some of the media criticized the 8GB VRAM model, but AMD defended the move explaining how the smaller memory buffer is not a cause of worry for the majority. Both the 8 GB and the 16 GB RX 9060 XT are now available for purchase. A new driver is out too with Adrenalin version 25.6.1. However, as always, day one stocks would likely be highly limited, similar to other GPUs or any other product, like the Nintendo Switch 2, that also landed today. Third-party AIB (add in board) vendors like Gigabyte, for example, are selling the 8GB at $329 (SEP is $299) currently on Amazon US, so expect some markup. The technical specifications of the Radeon RX 9060 XT are given below: Specification Value GPU Architecture AMD RDNA™ 4 Core Compute Units 32 Video Memory 16 GB / 8GB GDDR6 Infinity Cache 32 MB Core Boost Clock Up to 3.13 GHz Memory speed/bandwidth 20 Gbps / 320 GB/s AI Performance 821 TOPS (INT4 with sparsity) Raytracing & AI Accelerators 32 3rd Generation Raytracing Accelerators; 64 2nd Generation AI Accelerators PCIe Interface PCIe® 5.0 x16 Display Outputs DisplayPort™ 2.1a, HDMI® 2.1b Total Board Power (TBP) 160W* If you notice, we have an asterisk for the TBP value in the table above. That is because AMD says that it can vary between 150 and 182 watts. Performance-wise, we know the $349 16 GB variant is close to the Nvidia RTX 5060 Ti in rasterization but falls behind in ray tracing. Meanwhile, the 8GB model, priced the same as the GeForce RTX 5060 at $299, should be better, as both 8 Gig and 16 Gig SKUs are identical spec-wise outside of memory capacity. As an Amazon Associate we earn from qualifying purchases.
    • It actually looks decent, although trailers could make the worst nonsense look watchable sometimes. I'm not a fan of the "extended" Aliens universe (Prometheus, Covenant), but I liked Romulus so will definitely give this a shot.
  • Recent Achievements

    • Week One Done
      jbatch earned a badge
      Week One Done
    • First Post
      Yianis earned a badge
      First Post
    • Rookie
      GTRoberts went up a rank
      Rookie
    • First Post
      James courage Tabla earned a badge
      First Post
    • Reacting Well
      James courage Tabla earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      406
    2. 2
      +FloatingFatMan
      181
    3. 3
      snowy owl
      175
    4. 4
      ATLien_0
      170
    5. 5
      Xenon
      135
  • Tell a friend

    Love Neowin? Tell a friend!