Windows 7 (UAC) doesn’t allow the program to write down inside data file owned by another program. How to do

compatibilityuacvb6windows 7windows-vista

I've to maintain a VB6 piece of software which, basically, exports data from a second program and import them into data files about a third program. So, this import/export tool worked very well since some years under Windows 95 to XP, but, now, I have to update it to support Vista and Seven… And it fails when time comes to write down into third program's files. At this time, I've just done my tests under Windows 7, but I suppose it will be the same under Vista.

Here is the problem in detail :

When my program try to reach the third program's data for writing, I get this error : "Run-time error '75': Path/File access error". So, it sounds like a UAC blocking because my program try to obtains access for writing about a data file he doesn't own. Then, if I run my program with admin rights OR with XP compatibility, it works : no error and third program's data file is well modified.

At this time I'm wondering how to work around this error (fatal for my program since it's blocked about its main job : to export/import data) programatically : during install (I'm using Inno Setup) or during runtime.

What's the right way ? Force a "XP compatibility" programmatically OR elevate my program to be launched with admin rights ? How to achieve this and when (during install or at runtime) ? Does a manifest could change something in this field (never used any manifest at this time) ?

Also, whatever be the way (XP compatibility or admin rights), the UAC warns user about system change at every launching : very annoying 🙁

So, what to do to have my program runs as smoothly under Windows 7 and Vista as it does under XP, knowing it has no other choice than write down in third-party data file (since it's its main purpose) ?

Awaiting your lighted replies…

PS : also (it could be important), my program doesn't know the data files's path by itself, but it's the user who select-it using common dialog.


OK, I'm back with some news. I've embedded a manifest which just does level="requireAdministrator" using the Manifest Creator for VB6 (the one indicated by Matt in his reply).

If I install (under Windows 7) my program being logged as administrator, it installs without any question, then program is launched without any question and does its job (read and write any files which are not owned by my program) very weel without any question. So, perfect in this case !

Nevertheless, if I'm logged as simple user, it installs well after asking permission with admin password, then program is launched without any question, BUT (and this is the remaining problem) I fall again in the "Path/File access error" (error '75') when time comes to read or write external file (not owned by my program).

So, and this is my additional question : how to solve this error being logged as simple user ? Does it means elevation didn't worked (while it seems to work in others case for any steps : install, launching, read/write) in this specific case only ? It's a little bit confuse in my mind here…

EDIT : Well, I think I've understood a thing, but need your confirmation (or not). I'll call my program B. B will read/imports data owned by program A, then write/export to data owned by program C.

My confusion was that I reinstalled B being logged as simple user, but not programs A and C which still was installed being logged as admin. So, when time comes for B to read data about A, in spite of the elevation, it fails because these A's data are owned by administrator (even if these A's data are not in user specific path, but, says "C:\email_data").

If I reinstall all the three programs being logged as simple user, it works (no warning nor error).

So, I reformulate my question : since elevation works (which should allow program to gain admin rights), why does program B (installed by user) cannot read data about program A (installed by admin) ? Should I add something during Inno Setup process to do my program be installed as admin only (knowing I've not any influence about way A and C programs are installed) ?

Best Answer

You can use either an external manifest file (myapp.exe.manifest) or use a tool to include a manfiest in your exe and a Resource.

There is a ton of content available, just google it. From here I grabbed a sample manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

You need to change the level to "requireAdministrator", which will prompt the user for permission when they launch the application (depending on their UAC settings).

Related Topic