vbscript - Keep Windows Script in same Command Window -
i have following script following on virtuozzo hardware node. : running ves : prompt veid : established connections on port 3389 specified veid : prompt ip block : create ip security policy block specified ip : reset terminal sessions
so works way want except can't figure out how have occur in single cmd prompt rather spawning new command prompts. if remove cmd /k exec commands nothing displayed. missing simple?
set oshell = createobject ("wscript.shell") getrunningvelistcmd = "cmd /k echo 'list running ves' & vzlist -a | find ""running""" getrunningvelist = oshell.run (getrunningvelistcmd,1,false) strveid = inputbox("enter veid","enter veid") whosethebrutecmd = "cmd /k echo 'whose brute' & vzctl exec "&strveid & " netstat -ano | find "":3389""" whosethebrute = oshell.run (whosethebrutecmd,1,false) strip = inputbox("enter ip address block","enter ip address block") blockcmd = "cmd /k echo 'create policy' & vzctl exec "&strveid & " netsh ipsec static add policy description=""block rule"" name=""blocked traffic"" && echo. && echo 'create filter list' && vzctl exec "&strveid & " netsh ipsec static add filterlist name=""ip block list"" && echo. && echo 'create filter' && vzctl exec "&strveid & " netsh ipsec static add filter filterlist=""ip block list"" srcaddr="&strip & " dstaddr=any description=""hacker ip"" && echo. && echo 'define filter action' && vzctl exec "&strveid & " netsh ipsec static add filteraction name=""block"" action=block && echo. && echo 'add rule filter action' && vzctl exec "&strveid & " netsh ipsec static add rule name=""block rule"" policy=""blocked traffic"" filterlist=""ip block list"" filteraction=""block"" activate=yes && echo. && echo 'assign policy' && vzctl exec "&strveid & " netsh ipsec static set policy name=""blocked traffic"" assign=yes && echo. && echo. && echo 'reset sessions press enter' && vzctl exec "&strveid & " rwinsta rdp-tcp && echo. && echo 'you terminated brute!'" blockthebrute = oshell.run (blockcmd,1,false) set oshell = nothing wscript.quit(0)
the 'programmatically correct way' solve problem write .hta gui. if willing use cscript run script, may acceptable ui without work. don't have *ware, poc script:
' bstep00.vbs - keep-windows-script-in-same-command-window
option explicit dim owsh : set owsh = createobject( "wscript.shell" ) dim scmd, oex, sfn, iret scmd = "fkdir.bat" set oex = owsh.exec( scmd ) if not oex.stdout.atendofstream wscript.echo oex.stdout.readall() wscript.stdout.write "file type: " sfn = wscript.stdin.readline() scmd = "fktype.bat " & sfn set oex = owsh.exec( scmd ) if not oex.stdout.atendofstream wscript.echo oex.stdout.readall() else wscript.echo "(1) oex.stdout.atendofstream" end if else wscript.echo "(0) oex.stdout.atendofstream" end if wscript.echo "done."
uses dir
(get/show info) , type
(use user's input based on info) demonstrate components: .exec , .bat files (like
fktype.bat: @echo off type %1
). using .bat (or .cmd) files solves 2 problems: "complex command lines" , "%comspec% starting", don't tempted avoid them putting more text scmd.
output of sample session:
cscript bstep00.vbs 07.10.2011 13:48 29 fkdir.bat 07.10.2011 14:01 20 fktype.bat file type: fkdir.bat @echo off dir | find "bat" done.
Comments
Post a Comment