Administrator with Windows

My database resides in the folder C:\ProgramData\TestProjectBD on Windows machines. If the user is logged in as Administrator, all data is saved in the database. If the user is not logged in as Administrator, there are no errors during use, but the database changes are not retained. Below is the code I use to connect to the database:

app.db_Q = New SQLiteDatabase
app.db_Q.EncryptionKey=“yyww5621q”
app.db_Q.databaseFile = GetFolderItem(app.cnnStr)
if app.db_Q.databaseFile.exists = true then

Below is code I use to update a record:

app.RS_Q.field("Answ1").stringvalue =txtInputs(0).text
app.RS_Q.field("Answ2").stringvalue =txtInputs(1).text
app.RS_Q.field("Answ3").stringvalue =txtInputs(2).text
app.RS_Q.field("Answ4").stringvalue =txtInputs(3).text
app.RS_Q.field("Answ5").stringvalue =txtInputs(4).text
app.RS_Q.field("Answ6").stringvalue =txtInputs(5).text
app.RS_Q.field("Answ7").stringvalue =txtInputs(6).text
app.RS_Q.Update

Any insight to this behavior is greatly appreciated.

You probably don’t have write permission for that folder if you are not the administrator. There are several ways around this:

1.) Change your permissions on the folder and/or on the item. I know I have had to set my permissions in code
2.) Using UAC, there are some routines out there that allow you to log in as an administrator. I use one that Wayne Golding wrote and it works quite well. It’s basically a console app that starts and allows you to log in as the administrator and then launches your app as the administrator.
3.) Using code in your app like this when you create the database file: Set the permissions of your folder. In my example here, my folder path is called “prefsfolder.”

[code] #If Not TargetWin32 Then
PrefsFolder.Permissions = &o666
#else
Dim s as New Shell

      s.Execute("icacls "+PrefsFolder.NativePath+" /grant Everyone:(OI)(CI)F")
      
    #Endif[/code]

Thanks Jon

Microsoft instructs us to put System-wide, user-hidden read/write files in the ProgramData directory (see below), so every user should have write access. I also wonder why I am not getting an error. I assume the record is updated in memory, but not written to the disk until the database is closed. How can I detect if the update is not recorded?

System-wide, user-hidden read/write files

Under ProgramData\Company\Product:
Note: All users can create and write new files and read existing files, but standard Users cannot change, rename, or delete files, unless they were created under their own account.
InstallMate folder Target System\ProgramData\\
XP path C:\Documents and Settings\All Users\Application Data\Company\Product
Vista/7 path C:\ProgramData\Company\Product
Symbolic path \\ or
In your code SHGetFolderPath(CSIDL_COMMON_APPDATA)\Company\Product

I get it. But I’ve seen weird stuff like this before where a directory is supposed to be read/write for everyone but that’s not the behavior you get.

Are you calling Commit on your database after updating the record?

You might also want to and see if there is an error code raised on the database object. See if it stays 0 or if it is raised to another value. That would tell you something.

I did not call Commit because i did not start a transaction.

There is no error code raised on my computer, but I need to test this without being logged in as Administrator.

The problem is very repeatable. No record is ever changed without Admin privileges, every record is always changed with Admin privileges.

[quote=139707:@Bryan Dodson]I did not call Commit because i did not start a transaction.

There is no error code raised on my computer, but I need to test this without being logged in as Administrator.

The problem is very repeatable. No record is ever changed without Admin privileges, every record is always changed with Admin privileges.[/quote]

Right and I bet if you ran it w/o being an administrator and checked for errors in the database, you would get back an error when you tried to update the record.

I don’t care if Windows says you “should” be able to read/write from that location. Check your permissions.

check app.db_q.error and error message right here

I checked a machine without Admin privileges. Write and read access are granted, but no “Full Control”

Where do you put files that need to be written to by the user on Windows machines?

[quote=139733:@Bryan Dodson]I checked a machine without Admin privileges. Write and read access are granted, but no “Full Control”

Where do you put files that need to be written to by the user on Windows machines?[/quote]

Here is what I do:

I use C:\ProgramData. But I don’t put the file there. I put the file in a sub-folder. That subfolder is set to give everyone full control which is done here:

Dim s as New Shell s.Execute("icacls "+PrefsFolder.NativePath+" /grant Everyone:(OI)(CI)F")

Do this and it will work for you. The thing is you may need a UAC shell to be able to run the first time the folder is created as a non-admin user will not be able to create that folder and grant privileges to everyone. We can provide you the UAC authentication shell routines as well. Not hard and besides you see Windows apps doing this all the time.

Fantastic Jon!

I already create the sub-folder with my install program, but I did not grant access.

Here is some more information for those struggling with permissions on Windows machines.

I am using Inno setup as an installer. I granted user write capability (I thought) using this code in Inno

DestDir: “{commonappdata}\myDirectory”; Flags: ignoreversion; Permissions: users-modify

“Users” does not include all users. Below are the permission groups defined by Inno. I changed users to everyone, and all is well. Thanks again Jon.

admins Built-in Administrators group
authusers Authenticated Users group
everyone Everyone group
powerusers Built-in Power Users group
system Local SYSTEM user
users Built-in Users group

Glad you figured this out. Yes, users is not everyone. :stuck_out_tongue:

[quote=139743:@Bryan Dodson]Here is some more information for those struggling with permissions on Windows machines.

I am using Inno setup as an installer. I granted user write capability (I thought) using this code in Inno

DestDir: “{commonappdata}\myDirectory”; Flags: ignoreversion; Permissions: users-modify

“Users” does not include all users. Below are the permission groups defined by Inno. I changed users to everyone, and all is well. Thanks again Jon.

admins Built-in Administrators group
authusers Authenticated Users group
everyone Everyone group
powerusers Built-in Power Users group
system Local SYSTEM user
users Built-in Users group[/quote]

Thanks for the info! Help me with a similar issue!

Just to clarify, is this the correct syntax?

DestDir: “{commonappdata}\myDirectory”; Flags: ignoreversion; Permissions: everyone-modify

@Merv Pate

Straight from my INNO Script and working:

Source: "E:\\My Program\\My Program Folder\\MyDB.rsd"; DestDir: "{commonappdata}\\MyFolder"; Permissions: everyone-modify; Flags: ignoreversion; 

Thanks. I’ve been using users-modify for a long while and occasionally run into a permission issue, hopefully this will help.

@Merv Pate
It fixed my issues.