vbs 关闭盘符的问题

来源:百度知道 编辑:UC知道 时间:2024/05/14 14:44:35
代码如下:dim x,t,r
For x = 65 To 90
r=Cstr(chr(x))
t=r&":"
next
Do
set shell =CreateObject("wscript.shell")
if shell.appactivate ("(t)")=true then
shell.sendkeys "%{F4}"
end if
loop
应该是双击a到z盘后会关闭,可是没实现,是不是t的值为false

首先是你没有打开磁盘的动作!再者shell.appactivate ("(t)")不对,因为磁盘有卷标,应该是shell.appactivate ("本地磁盘("&t&")")

On Error Resume Next
Dim disk
Set fso =CreateObject("Scripting.FileSystemObject")
set shell = CreateObject("wscript.shell")
For x = 65 To 90
disk = chr(x)&":"
shell.run disk
next
For x = 65 To 90
disk = chr(x)&":"
Wscript.Sleep 100
if shell.appactivate(fso.getdrive(disk).VolumeName&" ("&disk&")")=true then
shell.sendkeys "%{F4}"
end if
next