Search code examples
vb6windows-xpwindows-vista

VB6 using Write #1, (UnitCount


I have a legacy VB6 system which uses the expression

Write #1, (UnitCount

to write a text file. (UnitCount is the first a several short integers that are written.)

This works well under XP but does not produce the text file under Vista and Windows 8. No error is reported.

Does anyone know how to fix this?

Also - the VB6 application is installed in C:/Program Files/IronDuke

and the text file is intended to be written here as well (i.e. in the current directory).

I am aware of the closing bracket. I only included a section of the statement.


Solution

  • Your application is being treated as legacy (not Vista aware) and so files you write to protected locations are being virtualized (not "isolated") instead of causing a security violation exception. A filesystem VirtualStore exists in each user's profile path.

    It is perfectly possible for VB6 to embed an application manifest, though it will not generate one for you. You simply create the manifest file separately, then include it as a Custom resource with Type #24 and Id #1 and it will be compiled right in.

    One caveat is that the manifest file should be UTF-8 XML padded to an even multiple of 4 bytes. If padding is required you can add spaces at the end. You can save this from Notepad as ANSI since generally only the 7-bit ASCII character subset is used and this avoids the risk of a UTF-8 BOM, which you do not want Notepad to write.

    There are even simple ways to bypass WOW64 redirection when required, though there isn't a good reason to do so.

    But instead you might find it far easier to either modify your Start Menu shortcut or create a new one if the program is indeed writing this file to its current directory. Just set the shortcut's current directory ("Start in") to some legaly writeable location such as your Documents directory, some directory on the D: drive, the Public special folder, etc.