脚本编程 4 驱动器


驱动器的编程对黑客编程来说至关重要。好在vbs给我们提供了方便的集合,使得工作变得很简单。

1、检查驱动器
使用filesystemobject的driveexists方法
例如:
set fs=createobject("scripting.filesystemobject")
if fs.driveexists("h") then
......



2、获得驱动器属性
可以使用getdrive方法,然后可以通过drive对象的属性或的驱动器的属性。常用属性有
drivetype:以整数形式返回驱动器的类型 0表示unknown 1表示可移动的 2表示固定的 3表示网络驱动器 4表示cd-room
5表示ram盘



freespace:可用空间
totalsize:总空间
volumename:驱动器标卷



例如:
********************************************************
set fs=createobject("scripting.filesystemobject")
set drv=fs.getdrive("D")
t=drv.drivetype
y=drv.freespace
wscript.echo "类型" & t
wscript.echo "可用空间" & y
*******************************************************



如果大家还记得的话,应该知道还有个drives集合,这个东西比前面所说得更方便,比如我们要得到系统上所有的驱动器可以得到这个集合,然后使用foreach来检查。另外,有时候我们要编制一个病毒,可能会要感染软盘,这个时候我们需要检查软盘是不是准备好了,看下面这个程序:



**********************************************************
wscript.echo getdrivelist()



function getdrivelist() '自定义函数
dim fs,d,dc,s,n,crlf
crlf=chr(13)&chr(10)
set fs=createobject("scripting.filesystemobject")
set dc=fs.drives '获得驱动器集合
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、映射网络驱动器
网络共享对于脚本用户来说必须经过映射才能够使用。使用network对象的mapnetworkdrive方法可以实现映射。
set wn=wscript.createobject("wscript.network")
wn.mapnetworkdrive "k:","\\yaya\music",true
其中最后一个参数指定是不是永久的映射,如果不写最后一个参数,下次启动的时候,映射就会被取消。

如果要断开映射使用wn.removenetworkdrive "k:",true,true
如果网络驱动器正在使用中,要强制断开的话把第二个参数设置为true
第三个参数表示永久取消映射。
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3