About deleting file on Vista 64bit

Y

yxq

Hello,
The File.Delete(VS2005) function can not delete file on Vista-64bit, why?

And, what changes of API between 32-bit and 64-bit?

Thank you
 
Y

yxq

Yes, i have the permission(Right-Click the exe file, choose the Run as
Administrator), even i closed the UAC function.
 
Y

yxq

Sorry, the io.file.delete works well, but the API below for x86 will not
work on x64, how to change the API to x64?

//////////////////////////////////////////////////////////////////////////////////////
Public Class FileOperate
Private Structure SHFILEOPSTRUCT
Dim hWnd As Integer
Dim wFunc As Integer
Dim pFrom As String
Dim pTo As String
Dim fFlags As Short
Dim fAborted As Boolean
Dim hNameMaps As Integer
Dim sProgress As String
End Structure
Private Const FO_DELETE As Short = &H3S
Private Const FOF_ALLOWUNDO As Int16 = &H40S
Private Const FOF_NOCONFIRMATION As Int16 = &H10S
Private Const FO_MOVE As Int16 = &H1S
Private Const FO_COPY As Int16 = &H2S
Private Const FOF_NOERRORUI As Int16 = &H400S
Private Const FOF_SILENT As Int16 = &H4S

Private Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Private Shared SHFileOp As SHFILEOPSTRUCT


Public Shared Function ShellDirectDelete(ByRef sFile As String, Optional
ByVal ShowProgress As Boolean = True) As Int16

sFile = sFile & Chr(0)

With SHFileOp
.fAborted = True
.wFunc = FO_DELETE
.pFrom = sFile

If ShowProgress = True Then
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI +
FOF_SILENT
End If

End With
Return SHFileOperation(SHFileOp)
End Function


Public Shared Function ShellDelToRecycled(ByRef sFile As String,
Optional ByVal ShowProgress As Boolean = True) As Int16

sFile = sFile & Chr(0)

With SHFileOp
.fAborted = True
.wFunc = FO_DELETE
.pFrom = sFile

If ShowProgress = True Then
.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_NOERRORUI
+ FOF_SILENT
End If

End With
Return SHFileOperation(SHFileOp)
End Function

Public Shared Function ShellMove(ByVal SourcePath As String, ByVal
DsintedPath As String, Optional ByVal ShowProgress As Boolean = True, _
Optional ByVal MoveEntireDir As Boolean = True) As Int16

If IO.Directory.Exists(DsintedPath) = False Then
IO.Directory.CreateDirectory(DsintedPath)
Application.DoEvents()

If SourcePath.EndsWith("\") Then
SourcePath.Remove(SourcePath.Length - 1, 1)
If DsintedPath.EndsWith("\") Then
DsintedPath.Remove(DsintedPath.Length - 1, 1)

With SHFileOp
.fAborted = True
.wFunc = FO_MOVE

If MoveEntireDir = True Then
.pFrom = SourcePath & Chr(0)
Else
.pFrom = SourcePath & "\*.*"
End If

.pTo = DsintedPath

If ShowProgress = True Then
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI +
FOF_SILENT
End If

End With
Return SHFileOperation(SHFileOp)
End Function

Public Shared Function ShellCopy(ByVal SourcePath As String, ByVal
DsintedPath As String, Optional ByVal ShowProgress As Boolean = True, _
Optional ByVal CopyEntireDir As Boolean = True) As Int16

If IO.Directory.Exists(DsintedPath) = False Then
IO.Directory.CreateDirectory(DsintedPath)
Application.DoEvents()

If SourcePath.EndsWith("\") Then
SourcePath.Remove(SourcePath.Length - 1, 1)
If DsintedPath.EndsWith("\") Then
DsintedPath.Remove(DsintedPath.Length - 1, 1)

With SHFileOp
.fAborted = True
.wFunc = FO_COPY

If CopyEntireDir = True Then
.pFrom = SourcePath & Chr(0)
Else
.pFrom = SourcePath & "\*.*"
End If

.pTo = DsintedPath

If ShowProgress = True Then
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI +
FOF_SILENT
End If

End With
Return SHFileOperation(SHFileOp)
End Function

End Class
 
K

Ken Tucker [MVP]

Hi,

Try using an intptr for the hwnd in the structure. A handle is
not the same size in a 64bit os as a 32bit one.


Private Structure SHFILEOPSTRUCT
Dim hWnd As intptr

Ken
 
Y

yxq

Could you please view the API below, them will not work on 64bit.
I have change the
Dim hwnd As Integer
to
Dim hwnd As Intptr, but it will not work yet.
Thank you

/////////////////////////////////////////////////////////////////
Private Declare Function ShellExecuteEx Lib "shell32.dll" (ByRef lpExecInfo
As SHELLEXECUTEINFO) As Integer
Private Const SW_NORMAL As Integer = 1
Private Const SW_SHOW As Integer = 5
Private Const SEE_MASK_NOCLOSEPROCESS As Integer = &H40S

Private Structure SHELLEXECUTEINFO
Dim cbSize As Integer
Dim fMask As Integer
Dim hwnd As Integer
Dim lpVerb As String
Dim lpFile As String
Dim lpParameters As String
Dim lpDirectory As String
Dim nShow As Integer
Dim hInstApp As Integer
' fields
Dim lpIDList As Integer
Dim lpClass As String
Dim hkeyClass As Integer
Dim dwHotKey As Integer
Dim hIcon As Integer
Dim hProcess As Integer
End Structure


Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top