C# Remoting/COM Security E_ACCESSDENIED error

Discussion in 'ASP .Net' 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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnny Cash
    Replies:
    1
    Views:
    331
    John Saunders
    Jul 15, 2004
  2. moi
    Replies:
    2
    Views:
    2,786
    tatemononai
    May 19, 2006
  3. Replies:
    0
    Views:
    673
  4. kenshiro2000
    Replies:
    1
    Views:
    5,227
    kenshiro2000
    Jul 5, 2006
  5. Bart Simpson
    Replies:
    1
    Views:
    399
    Werner Schiendl
    Oct 27, 2003
Loading...

Share This Page