Search Tools Links Login

Find the Application Data Folder in Windows XP


This article uses the SHGetFolderPath API to find the Application Data Folder In "C:Documents and SettingsUserNameApplication Data" so you can save program data files and allow limited users in windows xp to use you program easier.

Original Author: RRKSS

Code

Since the SHGetFolderPath API is not in the api viewer here are the declarations you need.


Declare Function SHGetFolderPath Lib "shell32.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwFlags As Long, ByVal lpszPath As String) As Long

Public Const CSIDL_APPDATA = &H1A

Public Const SHGFP_TYPE_CURRENT = 0

Public Const SHGFP_TYPE_DEFAULT = 1

Public DataFolder as String


Add a module to your project and copy and paste those declarations into the module. Now create a function called GetDataFolder and paste this code into it.


Public Function GetDataFolder()

On Error Goto GenericFolder

Dim ReturnVal as long

Dim PathName as long

pathname = Space(260)

retval = SHGetFolderPath(Form1.hWnd, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, pathname)
pathname = Left(pathname, InStr(pathname, vbNullChar) - 1)

DataFolder = PathName

exit function

GenericFolder:

'Since Windows XP2000 is not installed we don't have this api so just use the App.path

if err.number = 453 then

  datafolder = app.path

end if

end function


With that code you should be able to make your programs more XP compatible and still be able to run it on windows 9x. Please leave your comments and vote.

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 106 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.