xp下怎么取得我的文档的路径

iori8421 2006-01-21 03:44:41
xp下怎么取得我的文档的路径
...全文
486 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhjjhjhj 2006-01-22
  • 打赏
  • 举报
回复
不用API
Private Sub Command2_Click()
Const ssfDESKTOP = 0 '桌面
Const ssfPERSONAL = 5 '我的文档
'.......还有很多
Set shl = CreateObject("shell.application")
MsgBox shl.NameSpace(ssfDESKTOP).Self.Path
MsgBox shl.NameSpace(ssfPERSONAL).Self.Path
End Sub
zyl910 2006-01-22
  • 打赏
  • 举报
回复
//如果你能肯定用户没有修改我的文档的路径的话

我就建议别人修改“我的文档”的路径,这样重装系统时不需要备份“我的文档”
rainstormmaster 2006-01-22
  • 打赏
  • 举报
回复
如果你能肯定用户没有修改我的文档的路径的话,用northwolves(狼行天下) 的方法应该是比较简洁的
rainstormmaster 2006-01-22
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim mshell As Object
Dim mfolder As Object
Set mshell = CreateObject("shell.Application")
Set mfolder = mshell.NameSpace(5)
MsgBox mfolder.Self.Path
Set mfolder = Nothing
Set mshell = Nothing
End Sub

zyl910 2006-01-22
  • 打赏
  • 举报
回复
如果是想获得其他用户的特殊文件夹路径,用SHGetFolderPath


MSDN:

SHGetFolderPath Function

--------------------------------------------------------------------------------

Takes the CSIDL of a folder and returns the pathname.

Syntax

HRESULT SHGetFolderPath( HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
LPTSTR pszPath
);
Parameters

hwndOwner
[in] Handle to an owner window. This parameter is typically set to NULL. If it is not NULL, and a dial-up connection needs to be made to access the folder, a user interface (UI) prompt will appear in this window.
nFolder
[in] A CSIDL value that identifies the folder whose path is to be retrieved. Only real folders are valid. If a virtual folder is specified, this function will fail. You can force creation of a folder with SHGetFolderPath by combining the folder's CSIDL with CSIDL_FLAG_CREATE.
hToken
[in]
An access token that can be used to represent a particular user. For systems earlier than Microsoft® Windows® 2000, it should be set to NULL. For later systems, hToken is usually set to NULL. However, you may need to assign a value to hToken for those folders that can have multiple users but are treated as belonging to a single user. The most commonly used folder of this type is My Documents.

The caller is responsible for correct impersonation when hToken is non-NULL. It must have appropriate security privileges for the particular user, including TOKEN_QUERY and TOKEN_IMPERSONATE, and the user's registry hive must be currently mounted. See Access Control for further discussion of access control issues.

Assigning the hToken parameter a value of -1 indicates the Default User. This allows clients of SHGetFolderPath to find folder locations (such as the Desktop folder) for the Default User. The Default User user profile is duplicated when any new user account is created, and includes special folders such as My Documents and Desktop. Any items added to the Default User folder also appear in any new user account.

dwFlags
[in] Flags to specify which path is to be returned. It is used for cases where the folder associated with a CSIDL may be moved or renamed by the user.
SHGFP_TYPE_CURRENT
Return the folder's current path.
SHGFP_TYPE_DEFAULT
Return the folder's default path.
pszPath
[out] Pointer to a null-terminated string of length MAX_PATH which will receive the path. If an error occurs or S_FALSE is returned, this string will be empty.
Return Value

Returns standard HRESULT codes, including the following:

S_FALSE SHGetFolderPathA only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function.
E_FAIL SHGetFolderPathW only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function.
E_INVALIDARG The CSIDL in nFolder is not valid.


Remarks

This function is a superset of SHGetSpecialFolderPath, included with earlier versions of the Shell. On systems preceeding those including Shell32.dll version 5.0 (Windows Millennium Edition (Windows Me) and Windows 2000), SHGetFolderPath was obtained through SHFolder.dll, distributed with Microsoft Internet Explorer 4.0 and later versions. SHFolder.dll always calls the current platform's version of this function. If that fails, it will try to simulate the appropriate behavior. SHFolder.dll continues to be included for backward compatibility, though the function is now implemented in Shell32.dll.

Only some CSIDLs are supported, including:

CSIDL_ADMINTOOLS
CSIDL_COMMON_ADMINTOOLS
CSIDL_APPDATA
CSIDL_COMMON_APPDATA
CSIDL_COMMON_DOCUMENTS
CSIDL_COOKIES
CSIDL_FLAG_CREATE
CSIDL_HISTORY
CSIDL_INTERNET_CACHE
CSIDL_LOCAL_APPDATA
CSIDL_MYPICTURES
CSIDL_PERSONAL
CSIDL_PROGRAM_FILES
CSIDL_PROGRAM_FILES_COMMON
CSIDL_SYSTEM
CSIDL_WINDOWS

Example

The following code fragment uses SHGetFolderPath to find or create a folder and then creates a file in it.

TCHAR szPath[MAX_PATH];

if(SUCCEEDED(SHGetFolderPath(NULL,
CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
NULL,
0,
szPath)))
{
PathAppend(szPath, TEXT("New Doc.txt"));
HANDLE hFile = CreateFile(szPath, ...);
}
Function Information

Minimum DLL Version shell32.dll version 5.0 or later
Custom Implementation No
Header shlobj.h
Import library None
Minimum operating systems Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0, Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0, Windows NT 4.0 with Service Pack 4 (SP4)
northwolves 2006-01-22
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
MsgBox Environ("USERPROFILE") & "\My Documents"
End Sub
wzzwwz 2006-01-21
  • 打赏
  • 举报
回复
http://vbnet.mvps.org/index.html?code/browse/csidl.htm
看看这个例子,枚举很多系统文件夹

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧