VB复制文件程序

2022-05-20 20:58:14   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《VB复制文件程序》,欢迎阅读!
复制,文件,程序


1.

Private Sub Command1_Click()

Dim result As Long, fileop As SHFILEOPSTRUCT With fileop

.hwnd = Me.hwnd .wFunc = FO_COPY

.pFrom = "C:\PROGRAM FILES\MICROSOFT VISUAL

BASIC\VB.HLP" & vbNullChar & "C:\PROGRAM FILES\MICROSOFT VISUAL BASIC\README.HLP" & vbNullChar & vbNullChar .pFrom = "C:\*.*" & vbNullChar & vbNullChar

.pTo = "C:\testfolder" & vbNullChar & vbNullChar

.fFlags = FOF_SIMPLEPROGRESS Or FOF_FILESONLY End With

result = SHFileOperation(fileop) If result <> 0 Then

' Operation failed

MsgBox Err.LastDllError Else

If fileop.fAnyOperationsAborted <> 0 Then MsgBox "Operation Failed" End If End If End Sub

模块:

Public Const FO_MOVE As Long = &H1 Public Const FO_COPY As Long = &H2 Public Const FO_DELETE As Long = &H3 Public Const FO_RENAME As Long = &H4

Public Const FOF_MULTIDESTFILES As Long = &H1 Public Const FOF_CONFIRMMOUSE As Long = &H2 Public Const FOF_SILENT As Long = &H4

Public Const FOF_RENAMEONCOLLISION As Long = &H8 Public Const FOF_NOCONFIRMATION As Long = &H10

Public Const FOF_WANTMAPPINGHANDLE As Long = &H20 Public Const FOF_CREATEPROGRESSDLG As Long = &H0 Public Const FOF_ALLOWUNDO As Long = &H40 Public Const FOF_FILESONLY As Long = &H80

Public Const FOF_SIMPLEPROGRESS As Long = &H100 Public Const FOF_NOCONFIRMMKDIR As Long = &H200

Type SHFILEOPSTRUCT






hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Long

fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String End Type

Declare Function SHFileOperation Lib "Shell32.dll" "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

2.

放一个按钮command1 复制以下代码即可



Alias

Private Declare Function GetWindowsDirectory Lib "kernel32 " Alias "GetWindowsDirectoryA " (ByVal lpbuffer As String, ByVal nSize As Long) As

Long

Private Declare Function GetSystemDirectory Lib "kernel32 " Alias "GetSystemDirectoryA " (ByVal lpbuffer As String, ByVal nSize As Long) As Lo

ng

Dim SYSDIR, WINDIR As String



Private Sub Command1_Click()

FileCopy App.Path + "\ " + "abc.exe ", SYSDIR

End Sub








Private Sub Form_Load() Dim dir As String * 255 Dim a, b As Integer a = GetSystemDirectory(dir, 255)

dir = Left(dir, a) a = Len(dir) b = 1

Do While b <= a

If Mid(dir, b, 1) = " " Then Exit Do

b = b + 1

Loop

SYSDIR = Mid(dir, 1, b - 1) '当前操作系统的Windows系统目录System路径

End Sub

3.

新建文本文件,粘贴 reg add

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v lin /t REG_SZ /d C:\我爱你.exe /f 然后命名为 开机启动.bat 放在vb相同路径

你的vb中要包含如下代码

Shell (App.Path & "\开机启动.bat")

然后vb生成的exe要命名为 我爱你.exe 然后运行即可。




本文来源:https://www.wddqxz.cn/60c2798e6529647d272852c8.html

相关推荐