Bagikan melalui


Metode IShellDispatch3.AddToRecent

Menambahkan file ke daftar yang terakhir digunakan (MRU).

Sintaks

IShellDispatch3.AddToRecent(
  varFile,
  [ bstrCategory ]
)

IShellDispatch3.AddToRecent( _
  ByVal varFile As Variant, _
  [ ByVal bstrCategory As BSTR ] _
)

Parameter

varFile [in]

Jenis: Varian

String yang berisi jalur file untuk ditambahkan ke daftar dokumen yang baru digunakan.

Windows Vista: Atur parameter ini ke null untuk menghapus folder dokumen terbaru.

bstrCategory [in, opsional]

Jenis: BSTR

String yang berisi nama kategori untuk menempatkan file.

Nilai kembali

JScript

Metode ini tidak mengembalikan nilai.

VB

Metode ini tidak mengembalikan nilai.

Contoh

Contoh berikut menunjukkan penggunaan AddToRecent untuk JScript, VBScript, dan Visual Basic.

Jscript:

<script language="JScript">
    function fnIShellDispatch3AddToRecentJ()
    {
        var objShell = new ActiveXObject("shell.application");
        var ssfWINDOWS = 36;
        var objFolder;
        
        objFolder = objShell.NameSpace(ssfWINDOWS);
        if (objFolder != null)
        {
            var objFolderItem;
            
            objFolderItem = objFolder.ParseName("system.ini");
            if (objFolderItem != null)
            {
                objShell.AddToRecent(objFolderItem.Path);
            }
        }
    }
</script>

Vbscript:

<script language="VBScript">
     function fnIShellDispatch3AddToRecentVB()
        dim objShell
        
        set objShell = CreateObject("shell.application")
        if (not objShell is nothing) then
            dim objFolder
            dim ssfWINDOWS
            
            ssfWINDOWS = 36
            set objFolder = objShell.NameSpace(ssfWINDOWS)
            if (not objFolder is nothing) then
                dim objFolderItem
                        
                set objFolderItem = objFolder.ParseName("system.ini")
                if (not objFolderItem is nothing) then
                    objShell.AddToRecent (objFolderItem.Path)
                end if
                set objFolderItem = nothing
            end if
            set objFolder = nothing
        end if
        set objShell = nothing
    end function
 </script>

Visual Basic:

Private Sub fnIShellDispatch3AddToRecent()
    Dim objShell  As Shell
    Dim objFolder As Folder
    Dim ssfWINDOWS As Long

    ssfWINDOWS = 36
    Set objShell = New Shell
    Set objFolder = objShell.NameSpace(ssfWINDOWS)
    If (Not objFolder Is Nothing) Then
        Dim objFolderItem As FolderItem

        Set objFolderItem = objFolder.ParseName("system.ini")
        If (Not objFolderItem Is Nothing) Then
            objShell.AddToRecent (objFolderItem.Path)
        End If
        Set objFolderItem = Nothing
    End If
    Set objFolder = Nothing
    Set objShell = Nothing
End Sub

Persyaratan

Persyaratan Nilai
Klien minimum yang didukung
Windows XP [hanya aplikasi desktop]
Server minimum yang didukung
Windows Server 2003 [hanya aplikasi desktop]
Header
Shldisp.h
IDL
Shldisp.idl
DLL
Shell32.dll (versi 6.0 atau yang lebih baru)