说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB如何使用vb取得一个文件的控制权

HTML文档下载 WORD文档下载 PDF文档下载
VB如何使用vb取得一个文件的控制权

解答(1):

VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName As String * 128
End Type
Private Const OF_SHARE_DENY_READ = &H30
Dim Hfile As Long

Dim my As OFSTRUCT


Private Sub Form_Load()
'禁止其他程序读写(包括执行)文件内容
Hfile = OpenFile("d:\foxmail.exe", my, OF_SHARE_DENY_READ)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim rlt As Long
'关闭文件句柄,撤消上面的禁止功能,可别忘了这一步哦:)
rlt = CloseHandle(Hfile)

End Sub

解答(2):
open "test.dat" for binary lock read write as #1
~~~~~~~~~~~~~~~
..................
close #1
上面加~~的部分的意义:
share 其他进程可以共享读写此文件
lock read 其他进程只能读
lock write 其他进程只能写
lock read write 其他进程完全拒绝访问

备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘