标题: 求批处理转变为VBS。
[打印本页]
作者: heicai
时间: 2007-7-11 19:38
标题: 求批处理转变为VBS。
@echo off
for %%a in (c d e f g h i) do (
if exist %%a:\nul 2>nul (
for /f "tokens=*" %%b in ('dir /s/b/a %%a:\amped.exe') do echo %%~dpb>C:\1.txt
))
::del %0
批处理总是会弹个黑框很不爽,希望高手能帮我把这段批处理转变成VBS的!谢
作者: 3742668
时间: 2007-7-11 20:47
虽然算不上什么高手,但是也知道有几种方法,这里给出比较简单的一种,仅供参考:
sFile = "c:\1.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(sFile,2,True)
sWQL = "Select * From CIM_DataFile Where " & _
"FileName = 'amped' And Extension = 'exe'"
For Each itemFile In GetObject("Winmgmts:").ExecQuery(sWQL)
oFile.WriteLine itemFile.name
Next
oFile.Close
MsgBox "执行完毕!"
作者: heicai
时间: 2007-7-11 21:00
感谢楼上的热心帮助,发现1.txt里未写入程序所在路径。不知为何
作者: 3742668
时间: 2007-7-11 21:18
如果只要路径的话可以把倒数第四行的itmeFile.Name 替换为:
itemFile.Drive & itemFile.Path
作者: heicai
时间: 2007-7-11 21:24
Originally posted by 3742668 at 2007-7-11 09:18 PM:
如果只要路径的话可以把倒数第四行的itmeFile.Name 替换为:
itemFile.Drive & itemFile.Path
提示语法错误。。。。很郁闷
作者: 3742668
时间: 2007-7-11 21:33
自己多学学基础的东西吧。
sFile = "c:\1.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(sFile,2,True)
sWQL = "Select * From CIM_DataFile Where " & _
"FileName = 'amped' And Extension = 'exe'"
For Each itemFile In GetObject("Winmgmts:").ExecQuery(sWQL)
oFile.WriteLine itemFile.Drive & itemFile.Path
Next
oFile.Close
MsgBox "执行完毕!"
作者: heicai
时间: 2007-7-11 21:53
Originally posted by 3742668 at 2007-7-11 09:33 PM:
自己多学学基础的东西吧。
sFile = "c:\1.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(sFile,2,True)
sWQ ...
我觉得VBS没批处理容易入门。哎
另外我试了下你的代码,发现无法处理中文目录。:(
作者: 3742668
时间: 2007-7-11 22:21
另外我试了下你的代码,发现无法处理中文目录。:(
请举例说明。
作者: heicai
时间: 2007-7-11 23:10
如amped.exe处在D:\热血英豪
这时1.TXT内就无任何信息