- ·上一篇文章:闽南歌曲下载(vbs+xmlhttp)hta版
- ·下一篇文章:VBS版QQ自动攻击器
- ·百度中搜索更多的关于“vbs远程开启共享(依赖rpc)”相关内容
- ·谷歌中搜索更多的关于“vbs远程开启共享(依赖rpc)”相关内容
- ******申明******
- 本站文章内容有部分为收录网络中其他网友内容,DOS资源站不保证所有的代码都适合你使用。
- 由于编辑匆忙,有可能造成某些脚本文件出现丢失代码或代码无法运行的情况,请网友根据情况自行修改。
- 如果能将出错部分反馈给我,那就更好了。
vbs远程开启共享(依赖rpc)
on error resume next
if (lcase(right(wscript.fullname,11))="wscript.exe") then
set objShell=wscript.createObject("wscript.shell")
objShell.Run("cmd.exe /k title 远程主机共享"&"& cscript //nologo " &wscript.scriptfullname)
wscript.quit
end if
dim objconnect
connect()
sub connect()
wscript.echo " #欢迎使用# "
wscript.echo "**************************************"
wscript.echo "#请输入远程主机名或IP地址#"
strcomputer=wscript.stdin.readline
set objShell=wscript.createObject("wscript.shell")
set objexec=objShell.exec("ping -n 2 -w 1000 "&strcomputer)
if instr(objexec.stdout.readall,"Reply from") then
wscript.echo
wscript.echo "#请输入用户名:"
username=wscript.stdin.readline
wscript.echo
wscript.echo "#请输入密码:"
pass=wscript.stdin.readline
wscript.echo "#正在列举共享,请等待...."
set obj=createobject("wbemscripting.swbemlocator")
set objconnect=obj.connectserver(strcomputer,"root\cimv2",username,pass)
for each ps in objconnect.execquery("select * from win32_logicaldisk where description='本地固定磁盘'")
cnt=objconnect.execquery("select * from win32_share where name='"&left(ps.name,1)&"$'").count
if cnt>0 then
share=share+"固定磁盘"+vbtab+ps.volumename+" "+ps.name&vbcrlf
else
noshare=noshare+vbcrlf+"固定磁盘"+vbtab+ps.volumename+" "+ps.name
end if
next
if noshare="" then
wscript.echo "**************************************"
wscript.echo "#所有的磁盘已经共享:"&vbcrlf&share
else
wscript.echo "**************************************"
wscript.echo "#已经共享的磁盘:"&vbcrlf&vbcrlf&share
wscript.echo "**************************************"
wscript.echo "#未共享的磁盘:"&vbcrlf&noshare
wscript.echo "**************************************"
end if
choice()
else
wscript.echo "远程主机: "&chr(34)&strcomputer&chr(34)&" ping不通."
choice()
end if
end sub
sub setshare()
wscript.echo "**************************************"
wscript.echo "请输入需要共享的磁盘"
input=wscript.stdin.readline
input=left(input,1)
input1=input&":"
set share=objconnect.get("win32_share")
errreturn=share.create(input1&"\",input&"$",0,10,"默认共享")
if errreturn=0 then
wscript.echo input&": 共享成功"
choice()
elseif errreturn=22 then
wscript.echo input &": 共享失败,该共享已经存在"
choice()
elseif errreturn=24 then
wscript.echo input &": 共享失败,该盘符不存在"
choice()
else
wscript.echo input &": 共享失败,存在未知错误"
choice()
end if
end sub
sub choice()
wscript.echo "**************************************"
wscript.echo "请输入指令:"
wscript.echo "A、添加共享"
wscript.echo "D、删除共享"
wscript.echo "L、列举共享"
wscript.echo "C、重新连接"
wscript.echo "Q、退出"
input=wscript.stdin.readline
if ucase(input)="Q" then
wscript.quit
elseif ucase(input)="D" then
delshare()
elseif ucase(input)="A" then
setshare()
elseif ucase(input)="L" then
listshare()
elseif ucase(input)="C" then
connect()
else
wscript.echo "未知的服务"
choice()
end if
end sub
sub delshare()
wscript.echo "请输入要删除的盘符名:"
input=wscript.stdin.readline
input=left(input,1)
input1=input&"$"
for each ps in objconnect.execquery("select * from win32_share where name='"&input1&"'")
errreturn=ps.delete
next
if errreturn=0 then
wscript.echo input1&" 成功删除"
choice()
else
wscript.echo input&" 删除失败,发生未知错误 "
choice()
end if
end sub
sub listshare()
for each drive in objconnect.execquery("select * from win32_share where description='默认共享'")
share1=share1+"固定磁盘:"+vbtab+left(drive.name,1)&":"+vbcrlf
next
if share1="" then
wscript.echo vbcrlf&"没有共享"
else
wscript.echo "**************************************"
wscript.echo vbcrlf&"已经存在的共享有:"&vbcrlf&share1
end if
choice()
end sub

