Script Programming 4 Drive _vbs

Source: Internet
Author: User
Drive programming is critical to hacker programming. The good news is that VBS provides us with a convenient collection that makes it easy to work.

1. Check Drive
Driveexists method of using FileSystemObject
For example:
Set Fs=createobject ("Scripting.FileSystemObject")
If Fs.driveexists ("H") then
......



2. Get Drive Properties
You can use the Getdrive method, and you can then drive the properties of the object or the drive's properties. Common properties are
DriveType: Returning the type 0 of a drive as an integer means that unknown 1 indicates that a removable 2 represents a fixed 3 indicating that network drive 4 represents Cd-room
5 means RAM disk



FreeSpace: Free Space
TotalSize: Total Space
VolumeName: Drive Label Volume



For example:
********************************************************
Set Fs=createobject ("Scripting.FileSystemObject")
Set Drv=fs.getdrive ("D")
T=drv.drivetype
Y=drv.freespace
WScript.Echo "Type" & T
WScript.Echo "Free Space" & Y
*******************************************************



If you remember, you should know that there is a drives set, which is more convenient than the previous one, for example, we have to get all the drives on the system to get the collection and then use foreach to check it. In addition, sometimes we have to develop a virus, may be to infect the floppy disk, this time we need to check whether the floppy disk is ready to see the following program:



**********************************************************
WScript.Echo Getdrivelist ()



function getdrivelist () ' Custom functions
Dim Fs,d,dc,s,n,crlf
CRLF=CHR (&CHR) (10)
Set Fs=createobject ("Scripting.FileSystemObject")
Set Dc=fs.drives ' Get drive Collection
For each D in DC
N= ""
S=s &d.driveletter & "--"
If D.drivetype=remote Then
N=d.sharename
ElseIf D.isready Then
N=d.volumename
End If
S=s & n& CRLF
Next
Getdrivelist=s
End Function
***********************************************************



3. Map Network Drive
Network shares must be mapped before they can be used by script users. You can implement mappings using the MapNetworkDrive method of the network object.
Set Wn=wscript.createobject ("Wscript.Network")
Wn.mapnetworkdrive "K:", "\\yaya\music", True
The last parameter specifies whether it is a permanent mapping, and if you do not write the last argument, the mapping will be canceled the next time you start.

If you want to disconnect the mapping using Wn.removenetworkdrive "K:", True,true
If a network drive is in use, set the second argument to true if you want to force a disconnect
The third parameter represents a permanent cancellation of the mapping.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.