Results 1 to 23 of 23

Thread: [RESOLVED] Vista - app.path to Application Data

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Resolved [RESOLVED] Vista - app.path to Application Data

    My app doesn't want to work in vista probably because I try to write to the app.path. I've tried to find alternative. This Is the closest I could find to a solution but it doesn't describe exactly how to do it. Can anyone describe what to do to replace app.path so that I can write to Documents and Settings\All Users\Application Data\My App?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Vista - app.path to Application Data

    You can use the API SHGetSpecialFolderLocation passing the CSIDL_COMMON_APPDATA id.
    http://allapi.mentalis.org/apilist/S...Location.shtml
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: Vista - app.path to Application Data

    Thanks RobDog888.
    I just added that declaration in a module but I got a compile error saying User-defined type not defined.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Vista - app.path to Application Data

    You need to add the dependant type declares too. Look at the example at the bottom of that page.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: Vista - app.path to Application Data

    Sorry again.

    I'm getting Variables not defined on NOERROR and Path$

  6. #6
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Vista - app.path to Application Data

    I just switched to vista and:
    Applies to Vista
    I was trying to use CSIDL_COMMON_APPDATA , but found that
    My app creates price lists etc to text files and when writing to the files as admin
    and standard users only the admin could actually change the prices if not in this folder. Standard users could view the data, but not change it and the same applies to these 2 files. switching to common documents fixed the problem
    AI will post code to get paths
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Vista - app.path to Application Data

    Code:
    Private Const CSIDL_ADMINTOOLS           As Long = &H30   '{user}\Start Menu _                                                        '\Programs\Administrative Tools
    Private Const CSIDL_COMMON_ADMINTOOLS    As Long = &H2F   '(all users)\Start Menu\Programs\Administrative Tools
    Private Const CSIDL_APPDATA              As Long = &H1A   '{user}\Application Data
    Private Const CSIDL_COMMON_APPDATA       As Long = &H23   '(all users)\Application Data
    Private Const CSIDL_COMMON_DOCUMENTS     As Long = &H2E   '(all users)\Documents
    Private Const CSIDL_COOKIES              As Long = &H21
    Private Const CSIDL_HISTORY              As Long = &H22
    Private Const CSIDL_INTERNET_CACHE       As Long = &H20   'Internet Cache folder
    Private Const CSIDL_LOCAL_APPDATA        As Long = &H1C   '{user}\Local Settings\Application Data (non roaming)
    Private Const CSIDL_MYPICTURES           As Long = &H27   'C:\Program Files\My Pictures
    Private Const CSIDL_PERSONAL             As Long = &H5    'My Documents
    Private Const CSIDL_PROGRAM_FILES        As Long = &H26   'Program Files folder
    Private Const CSIDL_PROGRAM_FILES_COMMON As Long = &H2B   'Program Files\Common
    Private Const CSIDL_SYSTEM               As Long = &H25   'system folder
    Private Const CSIDL_WINDOWS              As Long = &H24   'Windows directory or SYSROOT()
    Private Const CSIDL_FLAG_CREATE = &H8000&                 'combine with CSIDL_ value to force
    Private Const MAX_PATH = 260
    
    Private Const CSIDL_FLAG_MASK = &HFF00                    'mask for all possible flag values
    Private Const SHGFP_TYPE_CURRENT = &H0                    'current value for user, verify it exists
    Private Const SHGFP_TYPE_DEFAULT = &H1
    Private Const S_OK = 0
    Private Const S_FALSE = 1
    Private Const E_INVALIDARG = &H80070057                   ' Invalid CSIDL Value
    
    Private Declare Function SHGetFolderPath Lib "shfolder" _
            Alias "SHGetFolderPathA" (ByVal hWndOwner As Long, _
            ByVal nFolder As Long, ByVal hToken As Long, _
            ByVal dwFlags As Long, ByVal pszPath As String) As Long
    
    
    
    Public Function AppFolderPath() As String
        Dim strBuffer  As String
        Dim strPath    As String
        Dim lngReturn  As Long
        Dim lngCSIDL   As Long   
        Dim gPathToAppFolder As String
        
       
        gPathToAppFolder = GetPathToAppFolder     
         lngCSIDL = CSIDL_COMMON_DOCUMENTS 'CSIDL_COMMON_APPDATA
         strPath = String(MAX_PATH, 0) "
      
         ' Get the folder's path. If the
                ' "Create" flag is used, the folder will be created
                ' if it does not exist.
                '
                'lngReturn = SHGetFolderPath(0, lngCSIDL, 0, SHGFP_TYPE_CURRENT, strPath)
                lngReturn = SHGetFolderPath(0, lngCSIDL Or CSIDL_FLAG_CREATE, 0, SHGFP_TYPE_CURRENT, strPath)
        
        gMyPath = Left$(strPath, InStr(1, strPath, Chr(0)) - 1)    
       
        using gMyPath because existing users have data in Program Files on xp, only use vista path if AppFolder does not exist in App.Path
        CheckDirectory gMyPath & "\YourApp"  'created if not present
        CheckDirectory gMyPath & "\YourApp\AppFolder"  'created if not present
         AppFolderPath = gMyPath & "\YourApp\AppFolder"
        
            
        End Function
    
    
    
    Put your exe in this folder under you company name
    
    Public Function PathToProgramFiles() As String
    Dim strBuffer  As String
    Dim strPath    As String
    Dim lngReturn  As Long
    Dim lngCSIDL   As Long
    
    lngCSIDL = CSIDL_PROGRAM_FILES 
    
     
     strPath = String(MAX_PATH, 0) 
     
     ' Get the folder's path. If the
            ' "Create" flag is used, the folder will be created
            ' if it does not exist.
            '
            lngReturn = SHGetFolderPath(0, lngCSIDL, 0, SHGFP_TYPE_CURRENT, strPath)
            'lngReturn = SHGetFolderPath(0, lngCSIDL Or CSIDL_FLAG_CREATE, 0, SHGFP_TYPE_CURRENT, strPath)
    
    PathToProgramFiles = Left$(strPath, InStr(1, strPath, Chr(0)) - 1)
    
    End Function
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  8. #8
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Vista - app.path to Application Data

    The code posted points to:

    Points to Myapp in CSIDL_COMMON_DOCUMENTS

    Points to these folders

    Xp

    C:\Documents and Settings\All Users.WINDOWS\Documents\MyApp\mydata.dat


    Vista
    D:\Users\Public\Documents\MyApp\mydata.dat
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: Vista - app.path to Application Data

    There seems to be a function missing or something.
    GetPathToAppFolder is unreferenced.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: Vista - app.path to Application Data

    I've edited that out. Not necessary?
    Can you post your CheckDirectory routine?

  11. #11
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Vista - app.path to Application Data

    'if directory doesn't exist it's created
    Code:
    Public Function CheckDirectory(ByVal sDirectoryPath As String, Optional ByVal bCreateIfNotFound As Boolean = True) As Boolean
    On Error GoTo e
       If LenB(Trim$(sDirectoryPath)) > 0 Then
             CheckDirectory = (LenB(Trim$(Dir$(sDirectoryPath, vbDirectory))) > 0)
          If (Not CheckDirectory) And bCreateIfNotFound Then
              'If Not DriveFull(Left(sDirectoryPath, 3)) Then
                MkDir sDirectoryPath
               'End If
            End If
             
        End If
        Exit Function
    e:
    SendToSupport "Error", mBasName, "Function CheckDirectory", Erl, err.Number, err.Description 'send online thru jmail
    ShowError err.Number, err.Description, "Function CheckDirectory", Erl 'write to file and display error
    
    
    
    End Function
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Vista - app.path to Application Data

    If your app is only for Vista then you shoul dreally be using hte new KnownFolderId's instead.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Vista - app.path to Application Data

    Quote Originally Posted by sgrya1 View Post
    There seems to be a function missing or something.
    GetPathToAppFolder is unreferenced.
    Comment out that line
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: Vista - app.path to Application Data

    Excellent!! Thankyou!!

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: [RESOLVED] Vista - app.path to Application Data

    I've just realised that I probably need to find and create the same path in the application deployment. Best if I post a similar question there or can anyone suggest something?

  16. #16
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] Vista - app.path to Application Data

    Quote Originally Posted by sgrya1 View Post
    I've just realised that I probably need to find and create the same path in the application deployment. Best if I post a similar question there or can anyone suggest something?
    Not sure what you are referring to. In my app I have had to account for users having existing data files in a folder under App.Path so i use global paths, if the folders exist I use app.path, if not i use CSIDL_COMMON_DOCUMENTS for data files. Is this what you mean ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: [RESOLVED] Vista - app.path to Application Data

    Yep. That's the answer I needed. Thanks again.

  18. #18
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] Vista - app.path to Application Data

    When installing to Vista be sure you setup requires Admin to register any ocx's, dll's. I use a manifest to make sure.
    Then provide a manifest for your exe. The manifest for my exe instructs vista to run as invoker so standard users can use it.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: [RESOLVED] Vista - app.path to Application Data

    I do have one ocx that I need to register. No idea what a manifest is.
    I use InnoSetup. Can it be done in that?

    I just installed my program on a Vista OS today. The app just stalled on startup. The person had admin rights. Will need to consider the case where someone doesn't.

  20. #20
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] Vista - app.path to Application Data

    Quote Originally Posted by sgrya1 View Post
    Yep. That's the answer I needed. Thanks again.
    One other Vista gotcha. If you log onto vista a run an exe you would think you are using it as admin, unless you right-click and choose open as admin you are considered a standard user. I have a routine that requires admin to run(program updater) from within my program. Use Private Declare Function IsUserAnAdmin Lib "shell32" () As Long to check and prompt user
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: [RESOLVED] Vista - app.path to Application Data

    Noted. Thanks.

    Never really used Vista before so I don't fully understand it. You have a program updater within your program?
    I have a setup.exe that overwrites the existing program. When I ran that today it asked for admin rights and a password.

    Might be my next hurdle. I'll have a go at it tomorrow and see what the problems are.

  22. #22
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] Vista - app.path to Application Data

    Quote Originally Posted by sgrya1 View Post
    I do have one ocx that I need to register. No idea what a manifest is.
    I use InnoSetup. Can it be done in that?

    I just installed my program on a Vista OS today. The app just stalled on startup. The person had admin rights. Will need to consider the case where someone doesn't.
    Don't know about InnoSetup, luckily my installer just provided a check box to provided the manifest(http://www.gdgsoft.com/pb/index.aspx)
    Here is the manifest for my exe:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <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>
    notice the asInvoker
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  23. #23
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] Vista - app.path to Application Data

    Quote Originally Posted by sgrya1 View Post
    Noted. Thanks.

    Never really used Vista before so I don't fully understand it. You have a program updater within your program?
    I have a setup.exe that overwrites the existing program. When I ran that today it asked for admin rights and a password.

    Might be my next hurdle. I'll have a go at it tomorrow and see what the problems are.
    I use this for program updates:
    http://www.planet-source-code.com/vb...xtCodeId=69060
    Also if you install as admin your desktop and startmenu shortcuts will not be seen by standard users , unless you provide the correct paths in public folders
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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