[英]What is the different between system and Administrator account when call SHGetSpecialFolderLocation() function?
I write two program, one is windows service run in system account(named xxService) and the other one is common application run in Administrator account(named xx); 我编写了两个程序,一个是在系统帐户(名为xxService)中运行的Windows服务,另一个是在管理员帐户(名为xx)中运行的常见应用程序;
They use the same code to get CSIDL_COMMON_DOCUMENTS
directory. 他们使用相同的代码来获取
CSIDL_COMMON_DOCUMENTS
目录。 In most machine , they run well. 在大多数机器上,它们运行良好。
But some machine, the xxService can get the correct directory, the xx have failure in SHGetSpecialFolderLocation()
; 但是在某些机器上,xxService可以获取正确的目录,xx在
SHGetSpecialFolderLocation()
失败;
edit: the program only run on Windows XP(sp3). 编辑:该程序仅在Windows XP(sp3)上运行。
edit2: Use SHGetFolderPathA()
function to solve this problem. edit2:使用
SHGetFolderPathA()
函数解决此问题。
My english is poor, everybody excuse me! 我的英语很差,大家不好意思!
log: 日志:
[2964] [db](tid=1108)(pid=2964): SHGetSpecialFolderLocation() fail.hr=0x80070057, ierr=122
the detail error info: 详细错误信息:
//
// MessageId: E_INVALIDARG
//
// MessageText:
//
// One or more arguments are invalid
//
#define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057L)
ERROR_INSUFFICIENT_BUFFER
122 (0x7A)
The data area passed to a system call is too small.
code: 码:
//C:\Users\Public\Documents
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
HRESULT hr = S_FALSE;
hr = SHGetMalloc(&pShellMalloc);
if(SUCCEEDED(hr))
{
hr = SHGetSpecialFolderLocation(NULL,CSIDL_COMMON_DOCUMENTS,&pidl);
if(SUCCEEDED(hr))
{
if(!SHGetPathFromIDListW(pidl, strDbFilePath))
{
int ierr=GetLastError();
DebugMsgW((L"SHGetPathFromIDListW() fail., ierr=%d"), ierr);
}
DebugMsgW(L"DBpath=%s",strDbFilePath);
pShellMalloc->Free(pidl);
}
else
{
int ierr=GetLastError();
DebugMsgW((L"SHGetSpecialFolderLocation() fail.hr=0x%x, ierr=%d"), hr, ierr);
}
pShellMalloc->Release();
}
else
{
int ierr=GetLastError();
DebugMsgW((L"SHGetMalloc() fail.hr=0x%x, ierr=%d"), hr, ierr);
}
SHGetSpecialFolderLocation()
(and any other function that returns an HRESULT) does not use GetLastError()
to report error codes, since the HRESULT
is the error code. SHGetSpecialFolderLocation()
(以及任何其他返回HRESULT的函数)不使用GetLastError()
报告错误代码,因为HRESULT
是错误代码。 Even SHGetPathFromIDList()
is not documented as using GetLastError()
, either. 甚至
SHGetPathFromIDList()
也没有记录为使用GetLastError()
。 So the return value of GetLastError()
is irrelevant in your example and needs to be removed to avoid confusion. 因此,
GetLastError()
的返回值在您的示例中是无关紧要的,需要将其删除以避免混淆。
As for the E_INVALIDARG
error, you are using a legacy function. 至于
E_INVALIDARG
错误,您正在使用旧版函数。 CSIDL_COMMON_DOCUMENTS
is known to fail in SHGetSpecialFolderLocation()
on some systems. 在某些系统上,
CSIDL_COMMON_DOCUMENTS
在SHGetSpecialFolderLocation()
失败 。 You need to use a newer function, such as SHGetFolderPath()
, or SHGetKnownFolderPath()
on Vista+. 您需要在Vista +上使用更新的函数,例如
SHGetFolderPath()
或SHGetKnownFolderPath()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.