ini or reg- where can I find path to templates and desktop?

K

KR

If anyone has a code snippet that would be fine too, but I'm not opposed to
spending additional hours trying to wrestle this to death...I'm a slow
learner, but eventually brute force attempts get me something that works...

I had a template that worked fine on Win95 and Win98 (untested on Win2K).
When we were upgraded to XP, one of the things that broke was the
installation routine (tries to write to the template directory) and the
other thing that broke was my ability to create and append information to a
..txt file on the desktop, because in XP the desktop has a different path (I
was hardcoding the path before).

Given the numerous versions of both Win OS and Word that are all operating
now (I need to be backward compatible to Word97 on Win95, and upward to the
most current stuff) what is the most reliable method to identify where a
..dot should install itself (yes, I use a routine so if the activated dot is
_not_ in the template directory, it installs a copy of itself then closes)
and also to locate the path to the desktop of whatever machine it is on?

Many thanks,
Keith
 
M

Malcolm Smith

Keith

I use this code, which I located on the Internet some time ago, to access
the Special Folders. If the author sees this then please accept my thanks
for a truly wonderful bit of code.

As for the Template folder why not look in:
Options.DefaultFilePath(wdUserTemplatesPath) - for the Normal.dot
Options.DefaultFilePath(wdWorkgroupTemplatesPath) - for the templates

- Malc
www.dragondrop.com



Option Explicit


' The Desktop - virtual folder
Public Const CSIDL_DESKTOP = &H0
' Program Files
Public Const CSIDL_PROGRAMS = 2
' Control Panel - virtual folder
Public Const CSIDL_CONTROLS = 3
' Printers - virtual folder
Public Const CSIDL_PRINTERS = 4
' My Documents
Public Const CSIDL_DOCUMENTS = 5
' Favorites
Public Const CSIDL_FAVORITES = 6
' Startup Folder
Public Const CSIDL_STARTUP = 7
' Recent Documents
Public Const CSIDL_RECENT = 8
' Send To Folder
Public Const CSIDL_SENDTO = 9
' Recycle Bin - virtual folder
Public Const CSIDL_BITBUCKET = 10
' Start Menu
Public Const CSIDL_STARTMENU = 11
' Desktop folder
Public Const CSIDL_DESKTOPFOLDER = 16
' My Computer - virtual folder
Public Const CSIDL_DRIVES = 17
' Network Neighbourhood - virtual folder
Public Const CSIDL_NETWORK = 18
' NetHood Folder
Public Const CSIDL_NETHOOD = 19
' Fonts folder
Public Const CSIDL_FONTS = 20
' ShellNew folder
Public Const CSIDL_SHELLNEW = 21


Declare Function SHGetSpecialFolderLocation Lib "Shell32.dll" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, _
pidl As ITEMIDLIST) As Long

Declare Function SHGetPathFromIDList Lib "Shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Public Type SH_ITEMID
cb As Long
abID As Byte
End Type

Public Type ITEMIDLIST
mkid As SH_ITEMID
End Type

Public Const MAX_PATH As Integer = 260
'
'


Public Function GetSpecialFolder(CSIDL As Long) As String
Dim sPath As String
Dim IDL As ITEMIDLIST
'
' Retrieve info about system folders such as the
' "Desktop" folder. Info is stored in the IDL structure.
'
GetSpecialFolder = ""
If SHGetSpecialFolderLocation(0, CSIDL, IDL) = 0 Then
'
' Get the path from the ID list, and return the folder.
'
sPath = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then
GetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & "\"
End If
End If
End Function
 
J

Joost Verdaasdonk

Hi,

I see that malcom has covered the template quesion.

In my example you also see some code to get the desktop
Path have fun:

Sub T()
Dim fsShell
Set fsShell = CreateObject("WScript.Shell")
MsgBox fsShell.SpecialFolders("Desktop")

MsgBox Options.DefaultFilePath(wdUserTemplatesPath)
Set fsShell = Nothing
End Sub

Enjoy,
Joost Verdaasdonk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top