I have always had problems saving my product registration code in the correct location on Windows. I have a customer who says he has to register the program every time he launches which would indicate I am not saving to an accessable location. The customer is on Windows 11 (I only have access to Windows 10) he installs as an admin user for all accounts.
Is this the right location?
Is there a difference between W10 and W11 that I have to cater for, it looked to be the same location in the documentation.
I currently do the following which seemed to be working on Mac and Windows 10.
Dim tout as textoutputstream
Dim f as folderItem
f = SpecialFolder.Preferences.child("ProductRegoFileName")
if f <> Nil then
'tout = f.CreateTextFile
tout = TextOutputStream.Create(f)
if tout <> nil then
tout.writeline username
tout.writeline company
var ob as string = Bans
dim encryptserial as string =EncryptQuickrc4v6(serialnum,ob)
tout.WriteLine encryptserial
'tout.writeline serialnum
tout.writeline str(site)
//tout.writeline settings
tout.close
end if
end if
Does this mean he logs in as “AdminUserXYZ” and then expects this to work for “RegularUserABC”? If so that is why it isn’t working. The actual location this would be stored to is \Users\AdminUserXYZ\AppData\Roaming\ so only AdminUserXYZ will see that file. If this needs to be available for multiple user logins then the location you probably want is SpecialFolder.SharedPreferences.
The locations will be identical for Windows 10 and 11.
Var DatabaseFolder As FolderItem
DatabaseFolder = SpecialFolder.SharedPreferences.Child("TestRego")
If Not DatabaseFolder.Exists Then
DatabaseFolder.CreateFolder
End If
Then create your file after the folder has been created.
The code I gave you creates a new folder as C:\ProgramData\TestRego on my system. Perhaps it is a permissions issue on your system with the user you are running the code as? I always run logged in as a member of the Administrator group.
Not too sure on what is stopping it but I am in as an admin user and running on a Mac. It has worked fine for some time just writing to the Preference folder but the point you raised at the top of the discussion got me keen to get a solution for all users on the system not just the currently logged in one. I would have thought just changing to SpecialFolder.SharedPreferences would have been enough.
When you have such an exception, the first thing you may do to get a clue is to click on the exception (in the variables viewer) and look at its error code (and error message, if any). If you stop at “I get an exception”, you basically just know something went wrong, but it’s hard to guess what.
Not only that, @Martin_Fitzgibbons , when you get this sort of error you should look through the properties of the folderitem f manually using the debugger and check that they all make sense - e.g., is f readable? is it writeable? Your code should probably check each of these.
Hi Martin,
Ok, error 13 means several things, but in this context, the only relevant one would be “permissions denied”.
BTW: my comment was also meant to tell it’s a good habit to take in general: when getting an exception, check the error code, message and exception type right away.