From: Mike S on
I use an ini file in the app.path for a program that runs on XP. What is
considered the best practice for deciding where to save the ini file on
Vista or W7?

I read this thread which recommended this approach:

http://www.codenewsgroups.net/group/microsoft.public.vb.general.discussion/topic16789.aspx

Option Explicit
Private Declare Function SHGetSpecialFolderLocation _
Lib "Shell32.dll" (ByVal hwndOwner As Long, _
ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList _
Lib "Shell32.dll" Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, ByVal pszPath As String) As Long
Private Type SH_ITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SH_ITEMID
End Type
Private AppDataFolder As String
Private Const CSIDL_APPDATA = &H1A
Private Const MAX_PATH As Integer = 260

Private Function findFolder(CSIDL As Long) As String
Dim path As String, ID As ITEMIDLIST
findFolder = ""
If SHGetSpecialFolderLocation(Me.hWnd, CSIDL, ID) = 0 Then
path = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal ID.mkid.cb, ByVal path) Then
findFolder = Left$(path, InStr(path, Chr(0)) - 1) & "\"
End If
End If
End Function

Private Sub Form_Load()
AppDataFolder = findFolder(CSIDL_APPDATA)
Caption = AppDataFolder
End Sub

Is it considered good practice to detect the OS, leave the ini in the
app.path for XP, and use that approach for Vista or W7? And if I do use
that approach is it true that I won't run into any permissions problems?

I'd like to write this into the program now so it doesn't matter what OS
it's run on.

Thanks,
Mike
From: Kevin Provance on
Leave it in the app datapath for Win 2000 and up. They should have been
there all along.

--
Customer Hatred Knows No Bounds at MSFT
Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc

Bawwk! Paulie want a dingleball, bawwk!
"Mike S" <mscir(a)yahoo.com> wrote in message
news:i3g06q$3cb$1(a)news.eternal-september.org...
:I use an ini file in the app.path for a program that runs on XP. What is
: considered the best practice for deciding where to save the ini file on
: Vista or W7?
:
: I read this thread which recommended this approach:
:
:
http://www.codenewsgroups.net/group/microsoft.public.vb.general.discussion/topic16789.aspx
:
: Option Explicit
: Private Declare Function SHGetSpecialFolderLocation _
: Lib "Shell32.dll" (ByVal hwndOwner As Long, _
: ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
: Private Declare Function SHGetPathFromIDList _
: Lib "Shell32.dll" Alias "SHGetPathFromIDListA" _
: (ByVal pidl As Long, ByVal pszPath As String) As Long
: Private Type SH_ITEMID
: cb As Long
: abID As Byte
: End Type
: Private Type ITEMIDLIST
: mkid As SH_ITEMID
: End Type
: Private AppDataFolder As String
: Private Const CSIDL_APPDATA = &H1A
: Private Const MAX_PATH As Integer = 260
:
: Private Function findFolder(CSIDL As Long) As String
: Dim path As String, ID As ITEMIDLIST
: findFolder = ""
: If SHGetSpecialFolderLocation(Me.hWnd, CSIDL, ID) = 0 Then
: path = Space$(MAX_PATH)
: If SHGetPathFromIDList(ByVal ID.mkid.cb, ByVal path) Then
: findFolder = Left$(path, InStr(path, Chr(0)) - 1) & "\"
: End If
: End If
: End Function
:
: Private Sub Form_Load()
: AppDataFolder = findFolder(CSIDL_APPDATA)
: Caption = AppDataFolder
: End Sub
:
: Is it considered good practice to detect the OS, leave the ini in the
: app.path for XP, and use that approach for Vista or W7? And if I do use
: that approach is it true that I won't run into any permissions problems?
:
: I'd like to write this into the program now so it doesn't matter what OS
: it's run on.
:
: Thanks,
: Mike

From: Mike S on
On 8/5/2010 9:03 PM, Kevin Provance wrote:
> Leave it in the app datapath for Win 2000 and up. They should have been
> there all along.

Sounds good, very easy fix.

Thanks,
Mike

From: Mayayana on
| > Leave it in the app datapath for Win 2000 and up. They should have been
| > there all along.
|
| Sounds good, very easy fix.
|
You realize that's a per-user method and what
you were doing is a per-machine method? You
can also just use the VB SaveSetting/GetSetting
functions if it's per-user. Those are designed to
mimic INI files. But if you need it per-machine
you need to take a different approach and change
permissions somewhere.


From: MikeD on


"Mayayana" <mayayana(a)invalid.nospam> wrote in message
news:i3grp7$gv$1(a)news.eternal-september.org...
> |
> You realize that's a per-user method and what
> you were doing is a per-machine method? You
> can also just use the VB SaveSetting/GetSetting
> functions if it's per-user. Those are designed to
> mimic INI files.

What mimicry are you referring to? For VB4 16 bit, they read/wrote to
actual .ini files. For 32 bit VB, they read/write the Registry;
specifically, to subkeys under "HKEY_CURRENT_USER\Software\VB and VBA
Program Settings".

> But if you need it per-machine
> you need to take a different approach and change
> permissions somewhere.

I cannot agree with that at all. A program has no business changing
permissions just to satisfy its own shortcomings (i.e. bad programming).

--
Mike


 |  Next  |  Last
Pages: 1 2 3
Prev: RegClean Revisited
Next: Make a Backup