0

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) ?

casperOne
  • 73,706
  • 19
  • 184
  • 253
hilow
  • 11
  • 1
  • 3
  • Where are the files you're importing into? If different users need access to them then surely the permissions should be set appropriatly? – Deanna Jun 25 '12 at 13:38
  • Can you change the paths where your programs are installed? In Windows Vista/7, only elevated, real admins, can write to Program Files. If you put your application into a folder where user(s) has full write permissions. You might want to modify the permissions of the files so that only data files can be modified by limited (regular) users, and all executable files are protected, i.e. only admins can write to them and/or delete them. In such a way you can avoid UAC warnings. There's no way to suppress them (except to turn UAC off). – Alexey Ivanov Jun 25 '12 at 18:25

2 Answers2

0

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).

Deanna
  • 23,876
  • 7
  • 71
  • 156
tcarvin
  • 10,715
  • 3
  • 31
  • 52
0

The %Program Files% directory is protected under Windows 7 when UAC is enabled (You need elevated privileges to write directly to it)

This is the problem you are encountering.

In order for 'legacy' programs to work more seamlessly (i.e. without visible error) Windows 7 uses folder redirection. This allows your legacy application to read and write a copy of what is in the program files directory.

If you use a manifest, this tells windows that your application is UAC aware and so no folder redirection takes place but you will need to have elevated (administrator) privileges in order to read/write to program files.

There are tons of examples of how to use a manifest. My personal preference is Manifest Creator.

If you set the requestedExecutionLevel to "requireAdministrator" then it will read and write the actual folder but you will be prompted for UAC elevation when your app runs.

The solution really is to not read and write to the program files location but to use another location. Have a look at this stack overflow question for solutions on this.

Community
  • 1
  • 1
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • 1
    I think an app with *no* manifest gets redirected. By utilizing the manifest it indicates the application is UAC aware enough to not get folder redirection but instead get path/persission errors. – tcarvin Jun 25 '12 at 16:50
  • Yes, application with `requestedExecutionLevel` element in their manifest will never get Virtualization, and folder redirection is part of it, enabled. – Alexey Ivanov Jun 25 '12 at 18:19
  • OK, so I'll go toward manifest for sure. And, by hazard, before to read your post, I've downloaded Manisfest Creator from http://www.vbforums.com/showthread.php?t=606736 :o) Well, since my tool has no other choice than to be able to write down data in other program's files (see my first post), I don't want neither redirection nor suggestion to use other location (the file I have to modify are already here and their location doesn't depend of my choice)... Well, I'll made tests around elevation using manifest and will tell you the result here... – hilow Jun 25 '12 at 23:43