本帖最后由 dos时代菜鸟 于 2018-4-28 15:36 编辑
仅 在 win10 x64 环境测试通过,其他环境 暂时 未测试。脚本已经尽量避免涉及对中文信息的提取,估计 英文下也能用。
比 cmd 优势在于不必频繁 调用 Diskpart.exe 节省调取时间。
因为是 内存 运行,不需要生成临时文件,diskpart 也是已经运行了的,所以 ,可以对 脚本所在分区进行 卸载。
算是 给 dos 板块 赚点儿人气儿吧。呵呵。
l-d-1.4.vbs.zip
(1.98 KB, 下载次数: 52)
- On error resume next
- hide_cmd '调用隐藏运行代码
- set ws=createObject("wscript.shell")
- Set diskpart = ws.Exec("diskpart.exe")
- DIM DISK
- vol_line2=fresh()
- wscript.echo vol_line2
- volx2=volx()
- with diskpart
- x=""
- do until x=false
- x=inputbox("盘 卷 盘符 大小 格式 卷标"&chr(10)&_
- "------------------------------------"&chr(10)&_
- vol_line2&chr(10)&_
- "请输入一个卷对应的序号:("&word(vol_line2,2)&"...)","选择装/卸一个卷")
- ln=0
- find=0
- for each v in split(word(vol_line2,2),",")
- ln=ln+1
- if v<>"" and v=x then
- find=1
- if vol_d(vol_line2,ln)=" " then
- wscript.echo "需要挂载"
- wscript.echo volx2
- y=""
- y=inputbox("盘 卷 盘符 大小 格式 卷标"&chr(10)&_
- "------------------------------------"&chr(10)&_
- vol_line2&chr(10)&_
- "请输入一个盘符:"&chr(10)&_
- "卷: "&v&" --> "&volx2,"输入一个盘符")
- find2=0
- for each v2 in split(volx2,",")
- if v2<>"" and v2=Ucase(y) then
- .StdIn.WriteLine "select vol "&v
- .StdIn.WriteLine "Assign Letter="&v2
- wscript.echo list1(1,2)
- find2=1
- exit for
- end if
- next
- if find2=0 then msgbox "输入错误!"
- else
- wscript.echo "需要卸载"
- .StdIn.WriteLine "select vol "&v
- .StdIn.WriteLine "remove "
- wscript.echo list1(1,2)
- end if
- vol_line2=fresh()
- volx2=volx()
- exit for
- end if
- next
- if x<>"" and find=0 then msgbox "输入错误!"
- loop
- .StdIn.WriteLine "exit"
- Do Until .Status=1
- wscript.sleep 100
- Loop
- End with
- '-------------获取卷序列列表
- function fresh()
- with diskpart
- .StdIn.WriteLine "list disk"
- fresh=""
- for each d in split(word(line0(list1(1,1)) , 2 ),",")
- if d<>"" then
- .StdIn.WriteLine "select disk "&d
- .StdIn.WriteLine "detail disk"
- DISK=D
- fresh=fresh&vline(wordl(line0(list1(2,1)),2))
- end if
- next
- end with
- End function
- '-------------获取未使用的盘符列表
- function volx()
- with diskpart
- volx="C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z"
- .StdIn.WriteLine "list vol"
- for each d in split(word0(wordl(line0(list1(1,1)),2) , 7,1 ),",")
- if d<>" " and d<>"" then
- volx=replace(volx,d&",","")
- end if
- next
- end with
- End function
- '----------找出所选卷的盘符
- Function vol_d(lx,lv)
- vol_d=""
- l=""
- ln2=0
- for n=1 to len(lx)
- if mid(lx,n,1)=chr(10) and l<>chr(10) then
- ln2=ln2+1
- if ln2=lv then vol_d=mid(l,11,1)
- l=""
- else
- l=l&mid(lx,n,1)
- end if
- next
- End function
- '----------根据 卷列表信息流 整理出 整理出 带有磁盘编号的 卷信息流-----------
- Function vline(lx)
- vline=""
- l=""
- for n=1 to len(lx)
- if mid(lx,n,1)=chr(10) and l<>chr(10) then
- vline=vline&" "&DISK&" "&mid(l,1,7)&mid(l,41,9)&" "&mid(l,24,7)&mid(l,11,13)&chr(10)
- l=""
- else
- l=l&mid(lx,n,1)
- end if
- next
- End function
- '------------获取某个字符流中各行的某个范围(r~s)的字符串
- Function word0( lx , r ,s)
- word0=""
- l=""
- for n=1 to len(lx)
- if mid(lx,n,1)=chr(10) and l<>chr(10) then
- word0=word0&mid(l,r,s)&","
- l=""
- else
- l=l&mid(lx,n,1)
- end if
- next
- End function
- '-------------获取文本流中 各行第r个单词及其后内容---
- Function wordl(lx,r)
- wordl=""
- l=""
- for n=1 to len(lx)
- if mid(lx,n,1)=chr(10) and l<>chr(10) then
- i=0
- s=0
- for x=1 to len(l)
- if mid(l,x,1)<>" " then
- if s=0 then i=i+1
- s=1
- if i=r then
- wordl=wordl&mid(l,x)&chr(10)
- exit for
- end if
- else
- s=0
- end if
- next
- l=""
- else
- l=l&mid(lx,n,1)
- end if
- next
- End function
- '------------获取某个字符流中各行的某个单词,组合成一个由","隔断的字符串
- Function word( lx , r)
- word=""
- l=""
- for n=1 to len(lx)
- if mid(lx,n,1)=chr(10) and l<>chr(10) then
- parts=split(l)
- ps=0
- for each p in parts
- if p<>"" then
- ps=ps+1
- if ps=r then word=word&p&","
- end if
- next
- l=""
- else
- l=l&mid(lx,n,1)
- end if
- next
- End function
- '------------获取某个字符流中有价值的各行---标记字符"-"-----------
- Function line0(lx)
- line0=""
- l=""
- s=0
- for n=1 to len(lx)
- if mid(lx,n,1)=chr(10) and l<>chr(10) then
- if left(l,1)="-" then s=1
- if s=1 and left(l,1)<>"-" then
- if left(l,1)="*" then l=mid(l,3)
- line0=line0&l&chr(10)
- end if
- l=""
- else
- l=l&mid(lx,n,1)
- end if
- next
- End function
- '返回 diskpart.stdout 字符指针位置开始计算,第m条命令及其后面的n条命令的输出结果
- function list1(m,n)
- list1=""
- with diskpart
- .stdin.WriteLine "rem "
- i=0
- Do While i<(m+n)
- strFromProc=replace(replace(trim(.StdOut.ReadLine()),chr(10),""),chr(13),"")&chr(10)
- if instr(1,strFromProc,">")>0 then
- i=i+1
- elseif i>(m-1) and strfromproc<>chr(10) then
- list1=list1&strfromproc
- end if
- Loop
- end with
- end function
- '----------------隐藏运行代码-----------------------
- Sub hide_cmd()
- set ws=createObject("wscript.shell")
- hide= """" & WScript.scriptFullName & """"
- if WScript.Arguments.count=0 then
- ws.run "cscript.exe " & hide &" -hide " ,0,false
- WScript.quit
- elseif WScript.Arguments(WScript.Arguments.count-1)<>"-hide" then
- args=" "
- for each arg in WScript.Arguments
- args=args&" "& """" & arg & """"
- next
- ws.run "cscript.exe " & hide &args &" -hide " ,0,false
- WScript.quit
- end if
- end Sub
- '-----------------隐藏代码结束----------------------
复制代码
|