ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 1 2

7 ѹҤ ..2549
66 Users On-Line.
Visitors - Page views
 8 9 7 3 8 5 5
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ҹ Remove Drive (Flash/Thumb/Handy Drive) Ҥ 1

Category »  VB 6/VB.Net
: Webmaster 15/12/2551 17:03:00
(ҹ : 22770) 

ҸԸաҶ֧ŵҧػó红Ẻ Ẻʹ (Remove Drive) Floppy Disk ¹ФѺ ؤ ¹ ػóǹ礧§ӹҹҢҹ ... 55555+ Ҩҹҹҷҧ Script Object ... ԧ ... Ƿҧѹ Ըա÷йҧʢҡ͡ǹҷ餹ͧ ѧ鹺ͧ ͧèж·ʹͧͧ֡ͧǷǡѺèѴ ÿҧͧ (ҹ) MS Visual Basic 6.0 ѧӾ֡ ѹѹҧ繻ѭҢҹФѺ ... ôͧ͡ (100%) ͧ͹ ¹ФѺ ...

    ͧͧ Script Object Сͺ仴
  1. FileSystem Object
  2. TextStream Object
ѹСǶ֧ͧͧ FileSystem Object ЪöѴáѺÿ ź Drive Դҧ С͹ҹ FileSystem Object 鹨еͧաҧ Object ҡ͹
    Ѻ M$ Visual Basic 6
  • Private FileSystem As New Scripting.FileSystemObject
    Ѻ ASP Script
  • Dim FileSystem
  • Set FileSystem = Server.CreateObject("Scripting.FileSystemObject")
FileSystem Object 繻ͧ Object Ẻ Script (ѧࡵҡҤ "Script.FileSystemObject") µâͧ Object ժ FileSystem FileSystem һСȢҹ öѴǡѺ ÿ ʹ (Method) (Ըա÷öѴáѺ Object ) ʹ㨴ѧ仹

CopyFile, MoveFile
ҡ˹ѧա˹

CopyFolder, MoveFolder
ҡ˹ѧա˹

CreateFolder
ҧ

DeleteFile, DeleteFolder
㹡ź

DriveExists, FolderExists, FileExists
㹡õǨͺÿ

GetDrives, GetFolder, GetFile
㹡¡ҹǡѺÿ

ͧٵҧ õǨͺÿ ԧ
' True ÿ C ԧ
FileSystem.DriveExists("C:")

' True temp ÿ C ԧ
FileSystem.FolderExists("C:\temp")

' ǡѺ 2 觴ҹ True
' MyData.txt temp ÿ C ԧ
FileSystem.FileExists("C:\temp\MyData.txt")

͵ҧ㹡ź
FileSystem.DeleteFolder "C:\temp"
FileSystem.DeleteFile "C:\temp\MyData.txt"

 

  1. Project --> References ...
  1. Project --> Components ...
  1. Design Time
  2. Ѻ Properties ͧ List View Control
    Style = 1 - CheckBox
  1. ͹ӧҹ ͧͺҧ inf resycled ҡ仫͹ (صѹСѹ ... )
    Start --> Run --> cmd ... ҹҹͧѭ (Windows) ¡ФѺͧ
  2. copy con autorun.inf (ҡ鹾áŧ ش红顴 Ctrl + Z)
  3. md resycled ... ҧ (Make Directory)
  4. attrib +s +h + r autorun.inf ... 仫͹
  5. attrib +s +h + r resycled ... 仫͹
  1. Run Time ... ѹȨ㨤Ѻͧ ... ١͹ѹʴŢ ·ͧ仵駤 ˹ ( Tools --> Folder Options ... ռŤѺ ... ͧ)
ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6
ǹŴ ViewRemoveDrive.exe ͹ҹ (еͧǹŴ VB6 Run-Time ҹҧ仴¹ФѺ)
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack
 ǹŴ Microsoft Data Access Object (MDAC) Jet 4.0 Update
 ǹŴ Microsoft Visual Basic Service Pack 6
鹡кǹ÷ӧҹ

' СȤҵ÷
Option Explicit

' ǹ繡¡ҹ ScrRun.DLL
Private FSO As New Scripting.FileSystemObject

Dim mDrive As Drive    ' ÿ
Dim mFolder As Folder    ' 
Dim mFile As File    ' 

' ͧͧسѵԢͧ Drive ͧ
DriveType ҵŢ֧ͧ͡ Drive
'  0 ¶֧ ҷöк
'  1 ¶֧ Removable Drive
'  2 ¶֧ Fix Drive
'  3 ¶֧ Network Drive
'  4 ¶֧ CD Rom Drive
'  5 ¶֧ RAM Drive


' ҹ Remove Drive ( Flash/Thumb/Handy Drive)
Private Sub ViewFiles()
    On Error Resume Next
    ' ٻӹǹ Drive 
    For Each mDrive In FSO.Drives
        ' Ǩͺ Drive еͧẺ Remove Drive ҹ ... ǡ Hard Drive ͧ
        If mDrive.IsReady = True And mDrive.DriveType = Removable Then
            ' ٻӹǹ Drive
            For Each mFile In mDrive.RootFolder.Files
                ' 㹢зʴª͡ ... ˹»żšҧ  CPU ӧҹǹ
                ' зӡ觤׹ CPU ѺкԺѵԡ (д)
                DoEvents
                
                ' ʴª͡ ੾зҴҨʡФѺ
                ' Ѻҡҧ 3  (ҹ੾йʡ) ¹繵ѡõ˭
                ' ͹Ѻ Select Case ... ԨóҤҧҡ IF - THEN - ELSE ¹ФѺ
                'Select Case UCase$(Right(mFile.Path, 3))
                '    Case "BAT", "EXE", "COM", "INF", "VBS", "DLL", "OCX"
                '        lvwViewer.AddItem mFile.Path
                'End Select
                
                ' ʴ͡ҷ
                lvwViewer.AddItem mFile.Path
            Next
        End If
    Next
    
    ' ѹ¡èӹǹѺ
    fraViewer.Caption = " ӹǹ " & lvwViewer.ListCount & " " & " "
End Sub

' ҹ Remove Drive ( Flash/Thumb/Handy Drive)
Private Sub ViewFolders()
    On Error Resume Next
    Dim nFiles As Integer
    
    nFiles = lvwViewer.ListCount
    
    ' ٻӹǹ Drive 
    For Each mDrive In FSO.Drives
        ' Ǩͺ Drive еͧẺ Remove Drive ҹ ... ǡ Hard Drive ͧ
        If mDrive.IsReady = True And mDrive.DriveType = Removable Then
            ' ٻӹǹ Drive
            For Each mFolder In mDrive.RootFolder.SubFolders
                ' DoEvents ...
                ' ù任ءҹաҧ 觧ҹ 繨ӹǹ˹ҡ¹ФѺ ... ͧ
                ' кԺѵԡ (OS) öҹ CPU ҧԷҾ
                DoEvents
                
                ' ʴ͡
                lvwViewer.AddItem mFolder.Path
            Next
        End If
    Next
    
    ' ǹͧùѺӹǹ  
    If nFiles <> 0 Then
        nFiles = lvwViewer.ListCount - nFiles
        fraViewer.Caption = fraViewer.Caption & " / ӹǹ " & nFiles & " " & " "
    Else
        fraViewer.Caption = fraViewer.Caption & " ӹǹ " & lvwViewer.ListCount & " " & " "
    End If
End Sub

' 㹡ź  ͡
Private Sub cmdDelete_Click()
On Error Resume Next
Dim sRow As Integer
Dim lvwData As Integer
    
    lvwData = 0
    
    ' Ѻӹǹͧ¶١˹ ()
    For sRow = 0 To lvwViewer.ListCount - 1
       If lvwViewer.Selected(sRow) = True Then
            lvwData = lvwData + 1
       End If
    Next
    ' Ǩͺ͹աͧ͡¶١˹ () º
    If lvwData = 0 Then
        MsgBox "س͡ () ͧèźº¡͹.", vbExclamation, App.CompanyName
        Exit Sub
    End If
    
    ' ׹ѹź ()
    If MsgBox("سҵͧź () ͡?" & vbCrLf & _
                        " [OK] ͵ͧź  " & vbCrLf & _
                        " [Cancel] ͵ͧ¡ԡ.", vbOKCancel + _
                        vbQuestion + vbDefaultButton2, "׹ѹź ") _
                        = vbCancel Then Exit Sub
    
    ' ٻӹǹ¡÷ ListView
    For sRow = 0 To lvwViewer.ListCount - 1
    DoEvents
        If lvwViewer.Selected(sRow) = True Then
            lvwViewer.ListIndex = sRow
            DoEvents
            ' óշաͧ͡¶١˹ ()
            If lvwViewer.Selected(sRow) = True Then
                ' Ǩͺաѧ ()  (FilesExists/FolderExists)
                If FSO.FileExists(lvwViewer.List(sRow)) = True Then
                    ' Method ź
                    FSO.DeleteFile lvwViewer.List(sRow), True
                    ' ź¡͡ҡ ListView
                    lvwViewer.RemoveItem sRow
                ElseIf FSO.FolderExists(lvwViewer.List(sRow)) = True Then
                    ' Method ź
                    FSO.DeleteFolder lvwViewer.List(sRow), True
                    ' ź¡͡ҡ ListView
                    lvwViewer.RemoveItem sRow
                End If
            End If
        End If
    Next
End Sub

' 㹡͡
Private Sub cmdSelectALL_Click()
Dim sRow As Integer
    On Error Resume Next
    For sRow = 0 To lvwViewer.ListCount - 1
        lvwViewer.ListIndex = sRow
        lvwViewer.Selected(sRow) = True
    Next
    lvwViewer.ListIndex = 0
End Sub

' 㹡͡
Private Sub cmdDeselectALL_Click()
    On Error Resume Next
    Dim sRow As Integer
    For sRow = 0 To lvwViewer.ListCount - 1
        lvwViewer.ListIndex = sRow
        lvwViewer.Selected(sRow) = Not lvwViewer.Selected(sRow)
    Next
    lvwViewer.ListIndex = 0
End Sub

' 㹡ʴ  
Private Sub mnuViewALL_Click()
    lvwViewer.Clear
    fraViewer.Caption = ""
    Call ViewFiles
    Call ViewFolders
End Sub

' 㹡ʴ੾Ъ
Private Sub mnuViewFiles_Click()
    lvwViewer.Clear
    fraViewer.Caption = ""
    Call ViewFiles
End Sub

' 㹡ʴ੾
Private Sub mnuViewFolders_Click()
    lvwViewer.Clear
    fraViewer.Caption = ""
    Call ViewFolders
End Sub
  1. ҷӧҹռԴ ͧ¡ԡ On Error Resume Next ViewFiles ViewFolders ͡͹ФѺ ҡ Error
    Run-Time Error '429'
    ActiveX component can't create object
  2. Start --> Run о regsvr32 "c:\windows\system32\scrrun.dll" ... Ъ䢻ѭѺ
Conclusion:
ѺҤ 1 ҹ͹Ѻͧ Ҥ仡繡ùʹ ¡ýѧѹش԰ͧк ҡ㴷ºǡ Remove Drive ҷӧҹ (ͼҹ) ͡ź ӨѴѹ֧ö͡仨ҡÿ͹ - ѹ鹷ӧҹ ... ͧҧӨѴʫҡ ͧ
͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560