这阵子终于可以经常碰电脑拉!!!
刚尝试,脚本写的不完整,比如一些输出输入到后来没有 .close
这个脚本是刚测试成功,所以只带有聊天部分,网络配置得事先按要求配置好。
需要环境:
两台电脑互相开启了目录共享并映射给对方, 映射盘符为X:
共享目录下建立 chat 文件夹,里面放入下面的 “talktest.vbs ”
其中一方执行,脚本提示
等待响应..
待对方执行后
.双方连接完成!
(我是通过删除或建立某个指定文件来判断的^_^,没啥好方法了,因为
情况可能有很多种。。。
先打开a: 如果存在x 则等待x消失 ,
b后打开: 如果存在x 则删除x这样子来响应的。不存在则反)
之后输入字符,对方应该是可看到的,我这边的另一台电脑是可以。
要结束的时候输入 end 并回车~ 对方也会得到结束的提示。
set wsx=createobject("wscript.shell")
if wscript.arguments.count = 0 then
wsx.run _
"cmd /c mode con cols=80 lines=25 &cscript //logo " _
&wscript.scriptname & " 0",3
wsx.run _
"cmd /c mode con cols=80 lines=5 &title Inputbox &cscript //nologo " _
&wscript.scriptname & " 1",3
wscript.quit
elseif wscript.arguments(0) = 1 then
call readinput()
wscript.quit
elseif wscript.arguments(0) = 0 then
call scroll()
wscript.quit
end if
sub readinput()
bok="x:\chat\talk.x"
btalk="x:\chat\talk.txt"
aok="talk.x"
atalk="talk.txt"
set fs=createobject("scripting.filesystemobject")
if fs.fileexists(aok) then
fs.deletefile(aok)
else
fs.createtextfile(aok)
end if
set writex=fs.createtextfile(atalk,true)
do
wscript.stdout.write "say:"
set inp=wscript.stdin
inpinfo=inp.readline
writex.writeline inpinfo
loop until inpinfo = "end"
wscript.sleep 1000
wscript.quit
end sub
sub scroll()
bok="x:\chat\talk.x"
btalk="x:\chat\talk.txt"
aok="talk.x"
atalk="talk.txt"
set wsx=createobject("wscript.shell")
set fs=createobject("scripting.filesystemobject")
set output=wscript.stdout
for i = 1 to 3
output.writeline ""
next
output.write "等待响应"
if fs.fileexists(bok) then
call wait(bok,true) '因存在而等待
else
call wait(bok,false) '因不存在而等待
end if
if fs.fileexists(aok) then
fs.deletefile(aok)
else
fs.createtextfile(aok)
end if
output.writeline "双方连接完成! " &vbcrlf & "对方: " &vbcrlf
call wait(btalk,false) '因不存在而等待
set talkx=fs.opentextfile(btalk,1)
set oursx=fs.opentextfile(atalk,1)
do
if talkx.atendofstream then
wscript.sleep 800
else
info=talkx.readline
output.writeline info
end if
if oursx.atendofstream = false then
if oursx.readline = "end" then
output.writeline "Closing..."
wscript.sleep 1000
wscript.quit
end if
end if
loop until info = "end"
output.writeline "Script: He was close the chatbox. "
output.writeline "Script: Input 'end' (at smallbox) and press enter to exit..."
while oursx.atendofstream = true
wscript.sleep 800
wend
wscript.quit
end sub
sub wait(filename,have)
set fs=createobject("scripting.filesystemobject")
set output=wscript.stdout
while fs.fileexists(filename) = have
output.write "."
wscript.sleep 1000
wend
End sub
Last edited by 523066680 on 2009-9-14 at 12:20 ]