Analog VBS - Macro

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
koleviko
Junior Coder
Posts: 45
Joined: Thu Nov 20, 2008 2:59 pm

Analog VBS - Macro

Post by koleviko » Thu Mar 08, 2012 6:24 pm

How to make this VBS script of Macro???

Code: Select all

VBStart
Set WSHshell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each Drive In FSO.Drives
	If (Drive.drivetype = 1)Then

	MsgBox("Flash.")
End If
Next
VBEND

MIX
Or to make this VBS script combined and Macro???

Code: Select all

VBStart
Set WSHshell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each Drive In FSO.Drives
	If (Drive.drivetype = 1)Then

	MsgBox("Flash.")
End If
Next
VBEND

//Mix VBS&Macro

if>%Drive.drivetype%=1,,bye
MessageModal>  Do something
goto>end
//.........................
label>bye
MessageModal>Good bye
Label>end

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Mar 08, 2012 6:51 pm

My original post is located here http://www.mjtnet.com/forum/post20560.html#20560

Code: Select all

/*
Drive types
: Unknown
: Removable
: Fixed
: Network
: CD-ROM
: RAM
*/
//Set type of active drives you want to search for
Let>TypeOfDrive=: Removable

//Get list of all available Drives
VBSTART
Option Explicit

' Drive type constants
Function GetDrives
Const Unknown = 0 'Unknown
Const Removable = 1 ' Removable
Const Fixed = 2 ' Fixed medium (hard disk)
Const Remote = 3 ' Network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk

Dim Text, Title
Dim fso, oDrive, curDrive ' Object variables

Dim drtype(6)
drtype(0) = ": Unknown"
drtype(1) = ": Removable"
drtype(2) = ": Fixed"
drtype(3) = ": Network"
drtype(4) = ": CD-ROM"
drtype(5) = ": RAM"

Set fso = CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
  Text = Text & curDrive.DriveLetter' Drive letter
  Text = Text & drtype(curDrive.DriveType)
  Text = Text & vbCrLf
Next
GetDrives = Text
End Function
VBEND

VBEval>GetDrives,DriveInfo
MessageModal>DriveInfo

Separate>DriveInfo,CRLF,Lines
Let>DRIVE_LIST=
Let>Kline=0
Let>TotalActiveDrives=0
label>Get Drives List
Add>Kline,1

Let>CurrentLine=Lines_%Kline%
//Check if drive is removable
Separate>%CurrentLine%,%TypeOfDrive%,var

//If var count equals 2 drive is removable
if>%var_count%=2
//Set list of removable drives
StringReplace>CurrentLine,%TypeOfDrive%,,DRIVE_LETTER
ConCat>DRIVE_LIST,%DRIVE_LETTER%
Add>TotalActiveDrives,1
endif

if>%var_count%=0,Drives Result
goto>Get Drives List

label>Drives Result
MessageModal>Available Drives: %DRIVE_LIST%

Let>SourceString=%DRIVE_LIST%
Let>DriveList=
Let>KK=0

Repeat>KK
Let>KK=KK+1

MidStr>SourceString,KK,1,DriveLetter

//Check if Removable Drive is active
IfFileExists>%DriveLetter%:\NUL
//Set Active Drives
ConCat>DriveList,%DriveLetter%%CRLF%
endif

Until>KK=%TotalActiveDrives%

MessageModal>Active Drives%CRLF%%DriveList%

koleviko
Junior Coder
Posts: 45
Joined: Thu Nov 20, 2008 2:59 pm

Post by koleviko » Thu Mar 08, 2012 7:51 pm

Very long, but now works !!!
Ã’hank you. ;)

Code: Select all

VBSTART
Function GetDrives
Dim drtype(6)
drtype(1) = "Removable"
Set fso = CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
 Text = Removable & drtype(curDrive.DriveType)
Next
GetDrives = Text
End Function
VBEND

VBEval>GetDrives,DriveInfo
if>DriveInfo=Removable
MessageModal>yes Flash
goto>end
Endif
MessageModal>no Flash
label>end

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts