CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    59

    Write file from VB6 at Vista OS

    My program will write to file where the program is located. It's working fine with VB6 & Windows XP but with Vista the file can't write into the same location with the program. There is no error but I still can't find the file that it should write.

    Is there any special coding to write to file with Vista?

    Please help.

    Thanks

  2. #2
    Join Date
    May 2004
    Location
    Osijek
    Posts
    61

    Re: Write file from VB6 at Vista OS

    Quote Originally Posted by the_magicien View Post
    My program will write to file where the program is located. It's working fine with VB6 & Windows XP but with Vista the file can't write into the same location with the program. There is no error but I still can't find the file that it should write.

    Is there any special coding to write to file with Vista?
    I assume that you are doing this in Program Files. That directory is write protected for user.

    You could:
    1) Run your program as administrator (either manually or by using manifest).
    2) Manually set write rights for that directory.
    3) Write a file where it should be written - e.g. Application Data.

  3. #3
    Join Date
    Dec 2008
    Posts
    19

    Re: Write file from VB6 at Vista OS

    Create a folder for your program in the User or Common Application Data folder. Vista does not allow writing to the Program Files. Files in that folder should be read only. Do all your read/writing in the Application Data folder you create.

  4. #4
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    59

    Re: Write file from VB6 at Vista OS

    tq jmedved.how I can use manifest?Can you give sample.

    Thanks

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Write file from VB6 at Vista OS

    You still won't be able to write to the PROGRAM FILES folder under Vista or later OS. For Vista, use the %ProgramData% folder to create a program file for your app. (You could do the same for XP if you wanted the same program to run)

    Environmental Variables (Vista)
    http://vistaonwindows.com/environment_variables.html
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    59

    Re: Write file from VB6 at Vista OS

    tq dglienna.Im not sure how to use this enviroment variables.it there any sample
    coding that i can use as example?

    Thanks

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Write file from VB6 at Vista OS

    Another option is to disable that pesky UAC

  8. #8
    Join Date
    May 2004
    Location
    Osijek
    Posts
    61

    Re: Write file from VB6 at Vista OS

    Quote Originally Posted by the_magicien View Post
    how I can use manifest?Can you give sample.
    Add file named yourfilename.exe.manifest with following content:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
        <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
            <security>
                <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
                </requestedPrivileges>
            </security>
        </trustInfo>
    </asmv1:assembly>
    Important part is requestedExecutionLevel (requireAdministrator). This will make your program ask for admin rights on startup and after that, you will get everything you have on XP (full admin credentials).

    P.S. Proper way would be just to write where you are supposed to (Application Data).

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Write file from VB6 at Vista OS

    That won't write to the program files folder...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured