skyearth
初级用户
积分 34
发帖 13
注册 2006-7-20
状态 离线
|
『楼 主』:
初来乍到,献上小礼--VBS转BAT命令
这是一个VBS程序,主要用于将VBS脚本转成BAT方式执行,可能在某些方面方便一些,本人出于对BAT批处理的爱好,也经常将BAT不能解决的问题用VBS实现,然后再变换为BAT执行,呵呵,有点“那个”,是不是!哈哈!真笑了
REM 将VBS转成BAT执行脚本 1.2
REM VBS2BAT VBS脚本名 BAT脚本名 临时脚本名
Dim I, VbsName, BatName, DesName
For I = 0 To WScript.Arguments.Count - 1
If I = 0 Then VbsName = WScript.Arguments(I)
If I = 1 Then BatName = WScript.Arguments(I)
If I = 2 Then DesName = WScript.Arguments(I)
Next
IF Len(VbsName) > 0 Then
Dim fso,f1,r,aryline,strline
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(VbsName) then VbsName = VbsName & ".VBS"
IF Len(BatName) = 0 Then
IF Ucase(Right(VbsName,4)) = ".VBS" Then BatName = Left(VbsName,Len(VbsName) - 4) & ".BAT"
IF Len(BatName) = 0 Then BatName = VbsName & ".BAT"
End IF
IF fso.FileExists(VbsName) then
Set f1 = fso.OpenTextFile(VbsName,1)
r = f1.ReadAll
f1.Close
'插入ECHO --- >>TEMP.VBS
r = replace(r, chr(10),"", 1)
If len(r) > 0 Then
aryline = split(r, chr(13))
IF Len(DesName) = 0 Then DesName = "%TEMP%\_ST0101_.VBS"
'IF Len(DesName) = 0 Then DesName = "_ST0101_.VBS"
'生成文件头
r = "@ECHO OFF" & vbnewline _
& "SET _WSH_=%WINDIR%\SYSTEM32\WScript.exe" & vbnewline _
& "SET _SCP_=" & DesName & vbnewline _
& "IF NOT EXIST ""%_WSH_%"" GOTO :END" & vbnewline _
& "IF EXIST ""%_SCP_%"" DEL ""%_SCP_%"""
for i = lbound(aryline) to ubound(aryline)
strline = trim(aryline(i))
'替换">","<"," &","|"
strline = replace(strline, ">", "^>", 1)
strline = replace(strline, "<", "^<", 1)
strline = replace(strline, " &", " ^&", 1)
strline = replace(strline, "|", "^|", 1)
strline = LTrimTab(strline)
If Left(strline,1) = "'" or Lcase(Left(strline,4)) = "rem " then strline = ""
'添加BAT生成语句
If Len(strline) > 0 Then
r = r & vbnewline & "ECHO " & strline & " >>%_SCP_%"
End If
next
'生成文件尾
r = r & vbnewline _
& """%_WSH_%"" ""%_SCP_%"" %*" & vbnewline _
& ":END" & vbnewline _
& "SET _WSH_=" & vbnewline _
& "SET _SCP_="
Set f1 = fso.OpenTextFile(BatName,2,True)
f1.Write r
f1.Close
MsgBox BatName & " create finished.",64,"VBS2BAT"
End If
End IF
End IF
'过滤左边的TAB符
Function LTrimTab(SpecStr)
Dim C, F
For C = 1 to Len(SpecStr)
If Mid(SpecStr,C,1) = chr(9) Then
F = F + 1
Else
If F > 0 Then
LTrimTab = Mid(SpecStr, C)
Else
LTrimTab = SpecStr
End If
Exit Function
End If
Next
End Function
|
|