Script Programming 4 drive

Source: Internet
Author: User

Driver Programming is crucial for hacker programming. Fortunately, vbs provides us with a convenient set, making our work very simple.

1. Check the drive
Use the driveexists method of filesystemobject
For example:
Set fs = createobject ("scripting. filesystemobject ")
If fs. driveexists ("h") then
......

2. Get Drive attributes
You can use the getdrive method, and then use the drive object attributes or drive attributes. Common attributes are:
Drivetype: return the drive type in integer form. 0 indicates unknown 1 indicates movable 2 indicates fixed 3 indicates network drive 4 indicates cd-room
5 indicates the ramdisk

Freespace: available space
Totalsize: Total Space
Volumename: Drive 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 "available space" & y
**************************************** ***************

If you still remember, you should know that there is another drives set, which is more convenient than we mentioned earlier. For example, we need to get the set from all the drives on the system, then use foreach to check. In addition, sometimes we need to prepare a virus that may infect a floppy disk. In this case, we need to check whether the floppy disk is ready. Check the following program:

**************************************** ******************
Wscript. echo getdrivelist ()

Function getdrivelist () 'custom function
Dim fs, d, dc, s, n, crlf
Crlf = chr (13) & chr (10)
Set fs = createobject ("scripting. filesystemobject ")
Set dc = fs. drives get the drive set
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 drives
Network Sharing is only available for script users after ing. The mapnetworkdrive method of the network object can be used for ing.
Set wn = wscript. createobject ("wscript. network ")
Wn. mapnetworkdrive "k:", "\ yaya \ music", true
The last parameter specifies whether the ing is permanent. If the last parameter is not specified, the ing will be canceled at the next startup.

If you want to disconnect the ing, use wn. removenetworkdrive "k:", true, true
If the network drive is in use, set the second parameter to true to force disconnection.
The third parameter indicates that the ing is permanently canceled.

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.