ASPNET/COM Security E_ACCESS_DENIED error

Discussion in 'ASP .Net Security' started by Natalia DeBow, May 6, 2004.

  1. Hi there,

    I am trying to create shortcuts to a desktop and to a Start->Programs menu
    from a C# client talking to a server (using .NET Remoting) that in turn
    talks to a COM object. I am running both the client and the server code on
    the same machine with the client having Administrators privileges. The
    server is running under IIS with ASPNET account having Users privileges
    only. We do use impersonate = true in our web.config file. I am trying to
    create a shortcut for an account that is created on the same machine as the
    client and the server. I have also logged in at least once into this
    account, so the profile for this account does indeed exist and the password
    is set to never expire. This account has Users privileges only.

    Here is the function that should create shortcuts, but it chokes when I am
    trying to save the .lnk file to a specified folder.

    More specifically the line:
    hres = ppf->Save(wsz, TRUE);
    returns E_ACCESSDENIED and the next line:
    hres = ppf->Release();
    returns S_FAIL.

    The strange thing is when we are trying to created multiple shortcuts for an
    app (say, app.exe), the first attempt always fails but consecutive tries
    succeed.

    Here is the function that creates shortcuts.
    BOOL CreateShortcut(LPCSTR lpszFolderName,

    LPCSTR lpszProgName,

    LPCSTR lpszEXE,

    LPCSTR lpszCommand,

    LPCSTR lpszWorkingDirectory,

    LPCSTR lpszDescription)

    {


    HRESULT hres;

    IShellLink* psl;

    char FullPath[MAX_PATH];



    CoInitialize(0);

    hres = CoCreateInstance(CLSID_ShellLink, 0,

    CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);


    if (SUCCEEDED(hres))

    {

    IPersistFile* ppf;

    hres = psl->SetPath(lpszEXE);


    if (SUCCEEDED(hres))

    {

    hres = psl->SetArguments(lpszCommand);


    if (SUCCEEDED(hres))

    {

    hres = psl->SetWorkingDirectory(lpszWorkingDirectory);

    if (SUCCEEDED(hres))

    {

    hres = psl->SetDescription(lpszDescription);


    if (SUCCEEDED(hres))

    {

    hres = psl->QueryInterface(IID_IPersistFile, (void**) &ppf);


    if (SUCCEEDED(hres))

    {

    WORD wsz[MAX_PATH];

    sprintf(FullPath,"%s\\%s.lnk", lpszFolderName, lpszProgName);

    int nMbwc = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, FullPath, -1, wsz,
    MAX_PATH);

    hres = ppf->Save(wsz, TRUE);

    hres = ppf->Release();

    }

    }

    }

    }

    }

    hres = psl->Release();

    }

    CoUninitialize();

    if FAILED(hres)

    SetLastError(hres);

    CONFIRM_PROCEED(SUCCEEDED(hres))

    BOOL Success = BuildUnInstDB(FullPath);

    CONFIRM_PROCEED(Success)

    return TRUE;

    }



    Any help would be greatly appreciated.



    Natalia
     
    Natalia DeBow, May 6, 2004
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.