问VB高手一个问题

我想要制作一个按钮,但我不想用shell但是我又我想要这个按钮能帮我在硬盘里找QQ.exe而是找到后,就做一个地址记录,而不是每次运行都寻找当哪天我QQ文件转到另一个文件... 我想要制作一个按钮,但我不想用shell
但是我又我想要这个按钮能帮我在硬盘里找QQ.exe
而是找到后,就做一个地址记录,而不是每次运行都寻找
当哪天我QQ文件转到另一个文件夹,原来的地址找不到qq.exe了
此时,再寻找QQ.exe,有没有什么办法做到,或者请高手帮我写一个例。。,谢谢
展开
 我来答
meiren777
2007-11-29 · 超过81用户采纳过TA的回答
知道小有建树答主
回答量:448
采纳率:0%
帮助的人:307万
展开全部
完全可以,我给你做做看

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long

Const MAX_PATH = 260
Const MAXDWORD = &HFFFF
Const INVALID_HANDLE_VALUE = -1
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const names = "qq.exe"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Function StripNulls(OriginalStr As String) As String
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function

Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
Dim FileName As String ' Walking filename variable...
Dim DirName As String ' SubDirectory Name
Dim dirNames() As String ' Buffer for directory name entries
Dim nDir As Integer ' Number of directories in this path
Dim i As Integer ' For-loop counter...
Dim hSearch As Long ' Search Handle
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
If Right(path, 1) <> "\" Then path = path & "\"
' Search for subdirectories.
nDir = 0
ReDim dirNames(nDir)
Cont = True
hSearch = FindFirstFile(path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
DoEvents
DirName = StripNulls(WFD.cFileName)
' Ignore the current and encompassing directories.
If (DirName <> ".") And (DirName <> "..") Then
' Check for directory with bitwise comparison.
If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
dirNames(nDir) = DirName
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
End If
End If
Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
Loop
Cont = FindClose(hSearch)
End If
' Walk through this directory and sum file sizes.
hSearch = FindFirstFile(path & SearchStr, WFD)
Cont = True
If hSearch <> INVALID_HANDLE_VALUE Then
While Cont
FileName = StripNulls(WFD.cFileName)
If (FileName <> ".") And (FileName <> "..") Then
FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
FileCount = FileCount + 1
If Text1.Text = "" Then
Text1.Text = path & FileName
Else
Text1.Text = Text1.Text & vbCrLf & path & FileName
End If
End If
Cont = FindNextFile(hSearch, WFD) ' Get next file
Wend
Cont = FindClose(hSearch)
End If
' If there are sub-directories...
If nDir > 0 Then
' Recursively walk into them...
For i = 0 To nDir - 1
FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
Next i
End If
End Function
Sub serchpath(SearchPath As String)
Dim FindStr As String
Dim FileSize As Long
Dim NumFiles As Integer, NumDirs As Integer
Screen.MousePointer = vbHourglass '改变鼠标
'List1.Clear
SearchPath = SearchPath
FindStr = names
Print "正在 " & SearchPath & " 中查找"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
Print "in " & SearchPath & "found " & NumFiles & " qq.exe"
' Text4.Text = "Size of files found under " & SearchPath & " = " & Format(FileSize, "#,###,###,##0") & " Bytes"
Screen.MousePointer = vbDefault '还原鼠标
End Sub
Private Sub serch()
Dim hard
Dim StrDrive As String '盘符串(A:\ C:\ D:\...)
Dim DriveID As String '盘符(如:A:\)
StrDrive = String(30, Chr$(0)) '初始化盘符串
Call GetLogicalDriveStrings(100, StrDrive) '返回盘符串
Dim i As Integer
'返回光盘盘符到数组
For i = 1 To 100 Step 4 '注意这里是4
DriveID = Mid(StrDrive, i, 3) '枚举盘符
If DriveID = Chr$(0) & Chr(0) & Chr(0) Then Exit For '没有盘符,即时退出循环
If GetDriveType(DriveID) = 3 Then '3表示本地硬盘
serchpath DriveID '只在硬盘上查找
End If
Next i
Open App.path & "\qqpath.txt" For Output As #1
Print #1, Text1.Text
Close
End Sub

Private Sub Command1_Click()
Dim qqpath As String
On Error GoTo serchqq
Open App.path & "\qqpath.txt" For Input As #1
Line Input #1, qqpath
Close

Open qqpath For Input As #1 '检查是否存在
Close
Print "then qq path hasn`t change"
Exit Sub
serchqq:
Print "then qq path had changed,serching qq path now……"
Call serch
End Sub

ok !! 我的心血,给我分吧^
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式