Results 1 to 6 of 6

Thread: Using oleexp.tlb by fafalone

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Using oleexp.tlb by fafalone

    I'm using this is to remove internet zone id from files, after adding the Reference.
    Code:
    Public Sub RemoveFileSecurityZone(sFile As String)
        Dim pZI As PersistentZoneIdentifier
        Set pZI = New PersistentZoneIdentifier
        
        pZI.Remove
        Dim pIPF As IPersistFile
        Set pIPF = pZI
        pIPF.Save sFile, 1
        
        Set pIPF = Nothing
        Set pZI = Nothing
    End Sub
    
    Public Function GetFileSecurityZone(sFile As String) As URLZONE
        'returns the Zone Identifier of a file, using IZoneIdentifier
        'This could also be done by ready the Zone.Identifier alternate
        'data stream directly; readfile C:\file.txt:Zone.Identifier
        On Error GoTo err_ADS
        Dim lz As Long
        Dim pZI As PersistentZoneIdentifier
        Set pZI = New PersistentZoneIdentifier
        
        Dim pIPF As IPersistFile
        Set pIPF = pZI
        
        pIPF.Load sFile, STGM_READ
        pZI.GetId lz
        GetFileSecurityZone = lz
        
        Set pIPF = Nothing
        Set pZI = Nothing
        On Error GoTo 0
        Exit Function
        
    err_ADS:
    End Function
    Code:
                If GetFileSecurityZone(CStr(files(i))) = 3 Then  'files(i) is full path plus filename
                    i = MsgBox("File Contains Internet Zone Identifier. Remove It ?", vbYesNo + vbQuestion, files(i))
                    If i = vbYes Then RemoveFileSecurityZone (CStr(files(i)))
                End If

    It was working but now I get
    Run-time error '-2147467259 (80004005)':
    Automation error
    Unspecified error

    Any idea how I can resolve ?
    Thanks

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,713

    Re: Using oleexp.tlb by fafalone

    Was it a Windows update that broke it? Could be you need to run as admin now.

    But what specific line is causing the issue?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Using oleexp.tlb by fafalone

    Thanks for reply fafalone.
    It's not an upgrade as I'm using offline XP.
    It occurs in Sub RemoveFileSecurityZone on line pIPF.Save sFile, 1

    sfile is "O:\CF\tests\R-4049652-1512871393-5043.jpeg.jpg"
    O: is a mapped Networked drive.

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,713

    Re: Using oleexp.tlb by fafalone

    It seems that error can be related to access issues, and I'd tend to agree since you said this exact code used to work? Was it working on the same drive, or locally? Because I was just playing with it and get a 'not found' error for anything on a mapped drive (different error than yours) but haven't tried XP yet. And a local drive if there's no zone set. It's weird.

    Could try the manual way, confirming whether it's the interface or drive.

    Code:
    Public Declare Function DeleteFile Lib "kernel32.dll" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
    Public Declare Function GetLastError Lib "kernel32" () As Long
    
    Public Sub RemoveFileSecurityZoneManual(sFile As String)
    On Error GoTo e0
    Dim hr As Long
    Dim lerr As Long
    hr = DeleteFile(sFile & ":Zone.Identifier")
    lerr = GetLastError()
    If hr = 0& Then
        Debug.Print "Delete failed, 0x" & Hex$(lerr)
    End If
    Exit Sub
    
    e0:
        Debug.Print "RemoveFileSecurityZone->Error: " & Err.Description & ", 0x" & Hex$(Err.Number)
    End Sub
    Note that the operation fails if the file is read only (this one, and very likely the interface call). Check if that may be the issue.

    Code:
    Public Declare Function GetFileAttributesW Lib "kernel32.dll" (ByVal lpFileName As Long) As Long
    Public Declare Function SetFileAttributesW Lib "kernel32.dll" (ByVal lpFileName As Long, ByVal dwFileAttributes As Long) As Long
    
    Public Enum FILE_ATTRIBUTES
        INVALID_FILE_ATTRIBUTES = -1
        FILE_ATTRIBUTE_READONLY = &H1
        FILE_ATTRIBUTE_HIDDEN = &H2
        FILE_ATTRIBUTE_SYSTEM = &H4
        FILE_ATTRIBUTE_ARCHIVE = &H20
        FILE_ATTRIBUTE_NORMAL = &H80
        FILE_ATTRIBUTE_TEMPORARY = &H100
        FILE_ATTRIBUTE_OFFLINE = &H1000
        FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &H2000
        'Values below this point can only be read, not set
        FILE_ATTRIBUTE_COMPRESSED = &H800
        FILE_ATTRIBUTE_DIRECTORY = &H10
        FILE_ATTRIBUTE_ENCRYPTED = &H4000
        FILE_ATTRIBUTE_REPARSE_POINT = &H400
        FILE_ATTRIBUTE_SPARSE_FILE = &H200
    End Enum
    
    Public Sub ClearReadOnly(sFile As String)
    'Removes the read-only attribute
    Dim lAtr As FILE_ATTRIBUTES
    lAtr = GetFileAttributesW(StrPtr(sFile))
    lAtr = lAtr And Not FILE_ATTRIBUTE_READONLY
    Call SetFileAttributesW(StrPtr(sFile), lAtr)
    End Sub
    Last edited by fafalone; Feb 3rd, 2021 at 12:17 AM.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Using oleexp.tlb by fafalone

    I first moved the files to local drive, this didn't change anything (but I left them there)
    About 16 files were involved, some I had removed the identifier by r-click-properties (In Win 10 although running vb6 in XP)
    For those still with it, each one debug.printed
    Delete failed, 0x0
    I then added ClearReadOnly routine ahead of RemoveFileSecurityZoneManual but the same errors occurred.

    I don't have the earlier files (that did work) anymore, with the zone identifier still.

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,713

    Re: Using oleexp.tlb by fafalone

    If the DeleteFile API is failing too it definitely seems like a permissions issue, it's supposed to specify the error for GetLastError but that might be broken, I couldn't get error codes for failures either.

    Perhaps see if other programs have the same issue... check out NirSoft's AlternateStreamsView, that will show all the zone identifiers and provide a menu option to delete them.

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