Results 1 to 6 of 6

Thread: The ABSOLUTE safest way to rename one item or virtual item ak (IshellItem)

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    976

    The ABSOLUTE safest way to rename one item or virtual item ak (IshellItem)

    This IS THE MOST reliable and safest way to rename an item (physical or virtual) within the Shell's Namespace (From Desktop and down to whatever level of drives and everything in there between)'

    Put this code into a BAS-module or into the public section of a form.

    *You need a typelib that handles IShellFolder and IShellItem Interfaces (write one on your own if you can so you don't have to be bound.)

    Code:
    Public Declare Function SHCreateItemFromIDList Lib "shell32.dll" (ByVal pidlAbsolute As Long, riid As GUID, ByRef ppv As IShellItem) As Long
    
    *Public m_cShell32 As New cShell32
    Public pidl As Long
    
    Private Sub Command2_Click()
      
      pidl = m_cShell32.GetPIDLFromSpecialFolder(CSIDL_BITBUCKET)
      
      If m_cShell32.SetNameOfFromPidlItem(pidl, "'THE WAIST BUCKET'") <> 0 Then
        MsgBox "Your Recycle Bin has now successfully changed name to 'THE WAIST BUCKET'"
      Else
        MsgBox "Your Recycle Bin Failed to rename to 'THE WAIST BUCKET'"
      End If
      
    End Sub
    
    Public Function IID_IShellItem() As GUID
      Dim lpIID As GUID
      
      
      '43826D1E-E718-42EE-BC55-A1E261C37BFE
      lpIID.Data1 = &H43826D1E
      lpIID.Data2 = &HE718
      lpIID.Data3 = &H42EE
      
      lpIID.Data4(0) = &HBC
      lpIID.Data4(1) = &H55
      lpIID.Data4(2) = &HA1
      lpIID.Data4(3) = &HE2
      lpIID.Data4(4) = &H61
      lpIID.Data4(5) = &HC3
      lpIID.Data4(6) = &H7B
      lpIID.Data4(7) = &HFE
      
      IID_IShellItem = lpIID
    
    End Function
    
    Public Function SetNameOfFromPidlItem(ByVal pidlItem As Long, ByVal sNewName As String, Optional ByVal hWnd As Long = 0) As Long
      Dim hr As Long
      Dim pISI As IShellItem
      Dim pISF As IShellFolder
      Dim pIPAI As IParentAndItem
      Dim pidlNew As Long
      
      If pidlItem = 0 Then Exit Function
      
      hr = SHCreateItemFromIDList(pidlItem, IID_IShellItem, pISI)
      
      If hr <> S_OK Then Exit Function
      
      If pISI Is Nothing Then Exit Function
      
      Set pIPAI = pISI
      
      If pIPAI Is Nothing Then Exit Function
      
      pIPAI.GetParentAndItem 0, pISF, 0
      
      If pISF Is Nothing Then Exit Function
      
      hr = pISF.SetNameOf(hWnd, pidlItem, StrPtr(sNewName), SHGDN_INFOLDER, pidlNew)
      
      If hr = S_OK Then
        SetNameOfFromPidlItem = pidlNew
      Else
        MsgBox "IShellFolder.SetNameOf Failed! #" & Hex(hr)
      End If
    End Function
    *cShell32 is my own written class module for Shell32.

    AS YOU CAN SEE NO ERROR HANDLING ADDED TO THIS SAMPLE - JUST BREAKS IF SOME ERROR SHOULD OCCURE IN ONE OF THE LEVELS!!
    Attached Images Attached Images  
    Last edited by nebeln; Dec 26th, 2023 at 04:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width