1

Unfortunately my VB knowledge is very minimum, but i need a script to do the following: I have a file Licenses.txt, which contains one license per line:
License 1
License 2
License 3

I have an other file response.ini, which has a value ProductKey in this format : ProductKey=XXXXX-XXXXXX-XXXXXX-XXXX

I want to do the following:
Read from Licenses.txt the first license. If it is free (a license is free if after the license don't stay Used), then it should replace the XXXXX-XXXXXX-XXXXXX-XXXX value in response.ini and put Used after the first License, so in License.txt it should stay License 1 - Used. If i run it again, then it should use the second license and put Used after it etc. If i don't have any free License then i should get an ErrorMessage.

Hopefully you can understand what i want to do. Can someone help me?

Thanks!

1 Answer 1

1

Here is the script which will do exactly what you want.

Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")

'Read the licence.txt file
Dim f : Set f = oFSO.OpenTextFile("Licence.txt", 1)
Dim sData : sData = f.ReadAll
f.close

'Find next available licence
licenceKey = ""
Dim sLine : for each sLine in split(sData, vbNewLine)
    if (lcase(right(sLine,7)) <> " - used") then
        licenceKey = sLine
        exit for
    end if
Next

if (licenceKey = "") then
    'Show error if no licences are available
    msgbox "No available licences! ", vbOkOnly + vbexclamation, "Licence"
else
    'Write a Response.ini file
    Set f = oFSO.OpenTextFile("Response.ini", 2, true)
    f.Write licenceKey
    f.close

    'Mark the licence as used
    sData = replace(sData, licenceKey, licenceKey & " - Used")

    'ReWrite the licence.txt file
    Set f = oFSO.OpenTextFile("Licence.txt", 2)
    f.Write sData
    f.close
end if
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.