Jump to content

Picking Up Drives In VB


Recommended Posts

Is there a way t create a program in VB6 that will run at startu and continuously scan for a certain drive (in this case, my external one). AND, if the said drive is detecte, do one thing, and as soon as it is not deteced, do something else?

Link to comment
Share on other sites


Is there a way t create a program in VB6 that will run at startu and continuously scan for a certain drive (in this case, my external one). AND, if the said drive is detecte, do one thing, and as soon as it is not deteced, do something else?

How about a VBS Script that does the same thing. Here is a example script for you to try.

Save As ActiveDrives.vbs

 
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim C1, Drv, Z1
StrD = "A_FILE_OR_SOMETHING_TO_CHECK_FOR"

Do
For Each Drv In Fso.Drives
If Drv.IsReady Then
'/-> There Was Something On The Drive
Act.Run("%Comspec% /C @Echo Off && CLS && MODE 55,5 && COLOR F3 && " &_
"Echo. && Echo " & Chr(187) & Chr(160) & Drv.DriveLetter & ":\ && " &_
"Echo " & Drv.VolumeName & " && ping -n 2 127.0.0.1>nul"),1,True
If Fso.FileExists(Drv.DriveLetter & ":\" & StrD) Then
'/-> Exit The First Loop Code
C1 = 1
'Place What You Want To Do Here
End If
If Fso.FolderExists(Drv.DriveLetter & ":\" & StrD) Then
'/-> Exit The First Loop Code
C1 = 1
'Place What You Want To Do Here
End If
Else
'/-> The Drive Is Empty This Could Be The Floppy, CD Or DVD, USB Drive
Act.Run("%Comspec% /C @Echo Off && CLS && MODE 55,5 && COLOR F3 && " &_
"Echo. && Echo " & Chr(187) & Chr(160) & Drv.DriveLetter & ":\ && " &_
"ping -n 2 127.0.0.1>nul"),1,True
End If
WScript.Sleep 1000
'/-> Exit The Inside Loop When C1 = 1
If C1 = 1 Then WScript.Quit
Next
'/-> Check To See If The Exit Code Is True, After The Inside Loop Has Ran
If C1 = 1 Then
WScript.Quit
Else
Z1 = Act.Popup("Did You Want To Continue With The Script.",7,"Exit Or Continue",4132)
'This Is For No You Do Not Want To Continue, Other Wise It Starts The Inside Loop Again
If Z1 = 7 Then C1 = 1
End If
Loop Until C1 = 1

Edited by gunsmokingman
Link to comment
Share on other sites

That's going to create a lot of disc activity... what is your goal with this?

jcarle,

Sure a program doing a scan, every 1 second for example, adds a little cpu activity but if the drive is not connected then it does not create activity on that disk. A call to GetDriveType, PathIsRoot or PathIsDirectory might be somehow a good choice IMHO, depending on which one have the less footprints.

Link to comment
Share on other sites

Thank you for the code. I figured it would be continually scanning things.

I was actually hoping for some kind of interface API with a Windows dll that will create activity only when the dll activates, but since we dont even know how to zip natively in windows, i doubt microsoft has released this

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...