简体   繁体   English

调用SHGetSpecialFolderLocation()函数时,系统帐户和管理员帐户有什么区别?

[英]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.

相关问题 从管理员帐户模拟SYSTEM(或等效) - Impersonate SYSTEM (or equivalent) from Administrator Account 如何在打开的管理员程序中调用system()并赋予它相同的权限? - How to call system() in an opened administrator program and gives it the same privileges? 读取系统调用与 istream::read function 有何不同? - How is a read system call different from the istream::read function? 转换function的显式调用和隐式调用有什么区别? - What's the difference between an explicit call and an implicit call of the conversion function? 当我在DLL中调用函数时会发生什么 - What happens when I call a function in a DLL 将 function 作为参数传递给另一个 function 的不同方式之间有什么区别? - What is the difference between different ways of passing a function as an argument to another function? 静态成员函数和全局函数有什么不同? - What is different between static member function and global function? 函数返回时,Linux c ++ system()调用崩溃 - Linux c++ system() call crash when function returns 在函数调用中struct Node *和Node *有什么区别? - What is the difference between struct Node* and Node* in function call? 在函数调用中创建的对象与传入的对象之间有什么区别 - What's the difference between an object created in function call and object passed in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM