Example #1
0
VOID SetupCreateLink(
    _In_ PWSTR LinkFilePath, 
    _In_ PWSTR FilePath,
    _In_ PWSTR FileParentDir
    )
{
    IShellLink* shellLinkPtr = NULL;
    IPersistFile* persistFilePtr = NULL;

    if (FAILED(CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, &shellLinkPtr)))
        goto CleanupExit;

    if (FAILED(IShellLinkW_QueryInterface(shellLinkPtr, &IID_IPersistFile, &persistFilePtr)))
        goto CleanupExit;

    // Load existing shell item if it exists...
    //IPersistFile_Load(persistFilePtr, LinkFilePath, STGM_READ)
    //IShellLinkW_SetDescription(shellLinkPtr, FileComment);
    IShellLinkW_SetWorkingDirectory(shellLinkPtr, FileParentDir);
    IShellLinkW_SetIconLocation(shellLinkPtr, FilePath, 0);

    // Set the shortcut target path...
    if (FAILED(IShellLinkW_SetPath(shellLinkPtr, FilePath)))
        goto CleanupExit;

    // Save the shortcut to the file system...
    IPersistFile_Save(persistFilePtr, LinkFilePath, TRUE);

CleanupExit:
    if (persistFilePtr)
        IPersistFile_Release(persistFilePtr);
    if (shellLinkPtr)
        IShellLinkW_Release(shellLinkPtr);
}
Example #2
0
BOOLEAN CreateLink(
    _In_ PWSTR DestFilePath,
    _In_ PWSTR FilePath,
    _In_ PWSTR FileParentDir,
    _In_ PWSTR FileComment
    )
{
    IShellLink* shellLinkPtr = NULL;
    IPersistFile* persistFilePtr = NULL;
    BOOLEAN isSuccess = FALSE;

    __try
    {
        if (FAILED(CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, &shellLinkPtr)))
            __leave;
        if (FAILED(IShellLinkW_QueryInterface(shellLinkPtr, &IID_IPersistFile, &persistFilePtr)))
            __leave;

        // Load existing shell item if it exists...
        //if (SUCCEEDED(IPersistFile_Load(persistFilePtr, DestFilePath, STGM_READ)))
        //{
        //    IShellLinkW_Resolve(shellLinkPtr, NULL, 0);
        //}

        IShellLinkW_SetDescription(shellLinkPtr, FileComment);
        IShellLinkW_SetWorkingDirectory(shellLinkPtr, FileParentDir);
        IShellLinkW_SetIconLocation(shellLinkPtr, FilePath, 0);

        // Set the shortcut target path...
        if (FAILED(IShellLinkW_SetPath(shellLinkPtr, FilePath)))
             __leave;

        // Save the shortcut to the file system...
        if (FAILED(IPersistFile_Save(persistFilePtr, DestFilePath, TRUE)))
            __leave;

        isSuccess = TRUE;
    }
    __finally
    {
        if (persistFilePtr)
        {
            IPersistFile_Release(persistFilePtr);
        }

        if (shellLinkPtr)
        {
            IShellLinkW_Release(shellLinkPtr);
        }
    }

    return isSuccess;
}
Example #3
0
static HRESULT WINAPI WshShortcut_put_TargetPath(IWshShortcut *iface, BSTR Path)
{
    WshShortcut *This = impl_from_IWshShortcut(iface);
    TRACE("(%p)->(%s)\n", This, debugstr_w(Path));
    return IShellLinkW_SetPath(This->link, Path);
}