Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Getting E_ACCESSDENIED when calling IPersistFile:Save

Getting E_ACCESSDENIED when calling IPersistFile:Save

Scheduled Pinned Locked Moved COM
databasevisual-studiosecurityhelpannouncement
3 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TClarke
    wrote on last edited by
    #1

    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.

    N 1 Reply Last reply
    0
    • T TClarke

      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.

      N Offline
      N Offline
      Nathan Holt at EMOM
      wrote on last edited by
      #2

      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

      U 1 Reply Last reply
      0
      • N Nathan Holt at EMOM

        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

        U Offline
        U Offline
        User 7819005
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups