Getting E_ACCESSDENIED when calling IPersistFile:Save
-
Hi all I'm calling IPersistFile:Save on my local machine logged in with administrator rights and I'm getting a security error any ideas would be very welcome. I'm using VS2005 on XP SP2 Here's the code, it's basically pulled out of the VS documentation:
HRESULT CShellLink::CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs)
{
HRESULT hres;
IShellLink* psl;
::CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{IPersistFile\* ppf; // Set the path to the shortcut target and add the description. psl->SetPath(lpszPathObj); psl->SetDescription(lpszDesc); psl->SetArguments(lpszArgs); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID\_IPersistFile, (LPVOID\*)&ppf); if (SUCCEEDED(hres)) { WCHAR wsz\[MAX\_PATH\]; // Ensure that the string is Unicode. if ( ! MultiByteToWideChar(CP\_ACP, 0, lpszPathLink, -1, wsz, MAX\_PATH)) { DisplayLastError(); } else { // Save the link by calling IPersistFile::Save. hres = ppf->Save(wsz, TRUE); if ( ! SUCCEEDED(hres)) { DisplayLastError(); } } ppf->Release(); } psl->Release(); } return hres;
}
Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.
-
Hi all I'm calling IPersistFile:Save on my local machine logged in with administrator rights and I'm getting a security error any ideas would be very welcome. I'm using VS2005 on XP SP2 Here's the code, it's basically pulled out of the VS documentation:
HRESULT CShellLink::CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs)
{
HRESULT hres;
IShellLink* psl;
::CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{IPersistFile\* ppf; // Set the path to the shortcut target and add the description. psl->SetPath(lpszPathObj); psl->SetDescription(lpszDesc); psl->SetArguments(lpszArgs); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID\_IPersistFile, (LPVOID\*)&ppf); if (SUCCEEDED(hres)) { WCHAR wsz\[MAX\_PATH\]; // Ensure that the string is Unicode. if ( ! MultiByteToWideChar(CP\_ACP, 0, lpszPathLink, -1, wsz, MAX\_PATH)) { DisplayLastError(); } else { // Save the link by calling IPersistFile::Save. hres = ppf->Save(wsz, TRUE); if ( ! SUCCEEDED(hres)) { DisplayLastError(); } } ppf->Release(); } psl->Release(); } return hres;
}
Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.
TClarke wrote:
I'm calling IPersistFile:Save on my local machine logged in with administrator rights and I'm getting a security error any ideas would be very welcome. I'm using VS2005 on XP SP2
Since it is a security error, I think it is important to know where you are saving to. Even as an administrator, there are parts of the system you aren't allowed to modify. Nathan
-
TClarke wrote:
I'm calling IPersistFile:Save on my local machine logged in with administrator rights and I'm getting a security error any ideas would be very welcome. I'm using VS2005 on XP SP2
Since it is a security error, I think it is important to know where you are saving to. Even as an administrator, there are parts of the system you aren't allowed to modify. Nathan
I'm getting the same error on W7 using VS 2008 and the same sample code. I am writing to a temp folder with security set to all access for "Everyone" from a shell running with Administrator priviledge. It still doesn't work. Probably, as usual, MS sample code is incomplete, or not even wrong. -Geoff