|
From the News Page 9 | |
DOS.Shell.bat -- Tool. Get information about any DOS command in XP.
Strings.com.vbs.vbs -- Someone said "Strings.COM" won't work in XP.
InputBox.bat -- How to get input in DOS batch (including VBS).
FTP.vbs -- Export and FTP upload favorites.
FTP.vbs -- A better version.
CopyFromStartMenuToDesktop.bat -- "JW" want to COPY in Netherlands.
FireWall.vbs -- A very thin wall! :-). (Additionally UseNet link).
Bug.vbs -- Step through a file: (output that was created by Debug).
DOS.Shell.bat (is creating DOS.Shell.vbs)
Win9X/XP
::@ [ "DOS.Shell.bat" by Benny Pedersen, http://2dos.homepage.dk ]
::@ [ Usage. For example, input the word xcopy in any dialogBox, ]
::@ [ or write an integer (if specified within the menu). ]
@ echo off %[ DOS.Shell.bat ]%
@ if exist %0.bat %0.bat %[ Get bat extension ]%
@ find.exe<%0 /v "@">%temp%.\DOS.Shell.vbs
@ start wScript.exe %temp%.\DOS.Shell.vbs [it's a self deleting file]
@ for %%c in (cls exit) do %%c
function DK (xx)'[convert to Danish language, DK("") = "æøåÆØÅ"]
xx=replace(xx, chr(145),chr(230)): xx=replace(xx, chr(155),chr(248))
xx=replace(xx, chr(134),chr(229)): xx=replace(xx, chr(146),chr(198))
xx=replace(xx, chr(157),chr(216)): DK=replace(xx, chr(143),chr(197))
end function
dim obj,fso, a,b, c
set obj = wscript.createObject("wScript.shell")
set fso = createObject("scripting.fileSystemObject")
if not obj.expandEnvironmentStrings("%OS%")="Windows_NT" then c=100
if not fso.fileExists(obj.expandEnvironmentStrings("%winDir%")_
& "\system32\Help.exe")then c=c+20
if not fso.fileExists(obj.expandEnvironmentStrings("%winDir%")_
& "\system32\Find.exe")then c=c+3
if c>0then msgBox"This program requires a working system, WinNT/XP. "_
, 50, right(c+10^4,4): set fso= nothing :obj.run "%comSpec% /c"_
& "erase %temp%.\DOS.Shell.vbs",0,-1:set obj= fso : wScript.quit
obj.run"%comSpec% /c%winDir%\system32\help|%winDir%\"_
& "system32\find/v""HELP""> %temp%\1.tmp",0,-1
obj.run"%comSpec% /c echo:#>> %temp%\1.tmp",0,-1
obj.run"%comSpec% /c erase %temp%\8.vbs",0,-1
dim r: set r= fso.openTextFile(obj.expandEnvironmentStrings("%temp%")_
& "\1.tmp",1)
dim w: set w= fso.openTextFile(obj.expandEnvironmentStrings("%temp%")_
& "\8.vbs",8,1): set fso= nothing
w.writeLine"function DK (xx) xx=replace(xx,chr(145),chr(230)):xx=rep"_
& "lace(xx,chr(155),chr(248)):xx=replace(xx,chr(134),chr(229)):xx="_
& "replace(xx,chr(146),chr(198)):xx=replace(xx,chr(157),chr(216)):"_
& "DK=replace(xx,chr(143),chr(197)):end function" & vbCrLf _
& "sub MakeFile(x,i)if isNumeric(i)then dim r:set r= createObject("_
& """scripting.fileSystemObject"").openTextFile(wScript.scriptFull"_
& "Name,1):for L=-x to i:i=mid(r.readLine,8,8):next:set r=nothing"&_
vbCrLf & "dim obj:set obj=wscript.createObject(""wScript.shell""):"_
& "obj.run""%comSpec% /c""&i&""/?>""""%temp%\~""&i,0,1:a=createObj"_
& "ect(""scripting.fileSystemObject"").openTextFile(obj.expandEnvi"_
& "ronmentStrings(""%temp%"")&""\~""&i,1).readAll" & vbCrLf _
& "set w=createObject(""scripting.fileSystemObject"").openTextFile"_
& "(obj.expandEnvironmentStrings(""%temp%"")&""\~""&i,2,1):w.write"_
& "Line DK(a):w.close:set w=nothing" & vbCrLf _
& "obj.run""%comSpec% /cNotepad """"%temp%\~""&i,0,1:obj.run""%com"_
& "Spec% /cDel """"%temp%\~""&i,0: set obj=nothing: wScript.quit" &_
vbCrLf & "end sub" & vbCrLf & "dim i" & vbCrLf
a=r.readLine:DO until a="#":w.writeLine"i=(inputBox(_"
do: c=abs(c)+1:b=r.readLine: if left(b,8)=string(8," ")then
w.writeLine"+"""&mid(c+100,2)&": "&left(a,8)&vbTab&DK(mid(a,9))_
& DK(mid(b,9))&"""&vbCr&vbCr _": a=r.readLine
else w.writeLine"+"""&mid(c+100,2)&": "&left(a,8)&vbTab&DK(mid(a,9))_
& """&vbCr&vbCr _": a=b
end if:loop until c mod 10=9 or a="#"
w.writeLine",""Input Command or Filename"","&c+1&",4999,999))"_
& vbCrLf & vbCrLf & "if i=""""then wscript.quit" & vbCrLf _
& "if isNumeric(i)then if 1*i>" & c-1-(c mod 10) & " and "_
& "1*i=<"&c&"then MakeFile "&.7*(c-(c mod 10))+8 &",fix(i-sgn(i)/2"_
& "+1)" & vbCrLf & "if not isNumeric(i)then MakeFile,i"&vbCrLf: c=-c
LOOP:w.close:set w=nothing:set r=w:obj.run"wScript.exe %temp%\8.vbs",_
,1:obj.run"%comSpec% /cDel %temp%.\1.tmp&&del %temp%.\8.vbs&&del " _
& "%temp%.\DOS.Shell.vbs&&Erase %temp%.\~*.",0:set obj= fso
|
Modified Okt 2, 2002:
Erase %temp%.\~*.
Missing dot prefixed the Back Slash became obvious after
I changed my Temp location from whatever default to Z:\.
|
Strings.com.vbs.vbs (is created of a batch file)
Win9X/XP
@echo off %[This line must be line num 1 without blank line(s) above]%
Rem: Strings.com in Win9X/ME/NT/XP...
Rem: To see how it works with the old/bad "Strings.com" instead of the
Rem: substituted VBS file, prefix line num 3 with a double colon (::),
if not (%1)==() goto %1 %[This is line num 2]%
%comspec% /c%0 vb>%temp%.\Strings.com.vbs.vbs Windows_NT
if not exist %temp%.\strings.com.vb* goto start (USING Strings.com)
if Windows_NT==%OS% color 1f&&%0 call wScript.exe %temp%.\ .vbs.vbs
%0 start.exe/wait wScript.exe %temp%.\ .vbs.vbs
:call [WinXP]
:start [Win9X]
%1 %2 %3strings.com%4 M = MONTH
%1 %2 %3strings.com%4 month = month
if %2.==wScript.exe. for %%c in (call del) do %%c %temp%.\~.bat
echo. Var [M] = [%M%]
echo. Var [Month] = [%Month%]
echo.--------------------------------------
%1 %2 %3strings.com%4 Date = Date
%1 %2 %3strings.com%4 T = That > nul
if %2.==wScript.exe. for %%c in (call del) do %%c %temp%.\~.bat
echo. Var [Date] = [%Date%]
echo. Var [T] = [%T%]
echo. Var [M] = [%M%]
echo.
if %2.==wScript.exe. del %temp%.\Strings.com.vbs.VBS
for %%I in (M Month Date T) do set %%I=
for %%I in (pause cls goto:EOF) do %%I.
: vb
echo Dim obj,arg:set obj=wscript.createObject("wScript.shell")
echo set arg=wScript.arguments:if not arg.count=3then wScript.quit
echo select case lcase(arg(2)):case"month"obj.run"%%comSpec%% /c"_
echo +"echo set "+arg(0)+"="+ucase(left(monthName(month(now)),1))_
echo +mid(monthName(month(now)),2)+">>%%temp%%.\~.bat",0,1
echo case"date"obj.run"%%comSpec%% /cEcho set "+arg(0)+"="+mid("Jan"_
echo +"uary%%--%%February%%-%%March%%----%%April%%----%%May%%------"_
echo +"%%June%%-----%%July%%-----%%August%%---%%September%%%%Octobe"_
echo +"r%%--%%November%%-%%December%%-%%", 11*month(now)-10, 11)+" "_
if not %2.==%OS%. echo &day(now)&", "&year(now)&">>%%temp%%.\~.bat",0,1
if %2 == %OS% echo ^&day(now)^&", "^&year(now)^&">>%%temp%%.\~.bat",0,1
echo case else msgBox vbCr+"No implementation of: "+vbTab+vbCr+vbCr _
echo +arg(2)+vbCr,16: end select
:EOF
|
Links:
Useful reply by Phil Robyn
|
InputBox.bat
Win9X/XP
@echo off
%1 for %%C in (start goto:EOF) do %%C /min %comSpec% /c"%0" goto:Begin
: Begin [unWrap the following, ONE LINE with 1 left margin as 2 spaces:]
echo.wScript.createObject("wScript.shell").run"%comSpec% /c>%temp%.\~.
bat echo.set i="""+inputBox("Prompt","?","Default")+"""",0,1.>%temp%.\~.
vbs
start/wait wScript.exe %temp%.\~.vbs
call %[Line no 6.]% %temp%.\~.bat
if Windows_NT==%OS% start /max %comSpec% /t:f0/k"%0" goto:Maximized ~~
if Win9X==Win9X%OS% start /max %comSpec% /c%0 goto:Maximized ~ %i%
set i=
for %%E in (vbs bat) do del %temp%.\~.%%E
exit[minComSpec]
: Maximized
%[unQuoted]% if Win9X==Win9X%OS% set i=%3
echo.
for %%~ in (%i%) do echo. [input] = [%%%2]
%[Quoted, WinXP users can simply use ~ instead of ~~ (see line no 7)]%
if Win9X==Win9X%OS% set i=
echo. [input] = [%i%%3]
for %%C in (echo pause cls exit[maxComSpec]) do %%C.
: EOF
@goto --- Skip the following ---
Benny Pedersen,
PS. (For more information, visit the UseNet Groups).
PS.PS. The label named Maximized, probably do not need to be used.
Use 1 of the following (The Ugly, The Nice or The OOPS) instead:
(line no 8.)
%Ugly% start/max %comSpec% /cfor %%C in (prom
pt:$ cls pause"[input]=[%i%]>nul") do %%C
%Nice% start/max %comSpec% /cfor %%C in ("prom
pt:[input]=[%i%]$_$_" "cls>con" pause) do %%C
%OOPS% start/max %comSpec% /cfor %%C in ("prom
pt:$_[input]=[%i%]$_>nul" cls pause :) do %%C
BTW. The above won't work in WinXP (only to be used within Win9X).
In order to include the prefixed %Description%, leave those as
blank without setting the variable such as, for example:
SET Ugly=Mother-in-law.
: --- Skipped ---
|
Links:
The Usenet
|
FTP.vbs
Win9X/XP
' [if u wish, u may modify the prompts about HOST, USER and PASSWORD.]
dim obj: set obj= wScript.createObject("wScript.shell")
' [Export favorites?]
wScript.createObject("shell.uiHelper").importExportFavorites 0,_
obj.expandEnvironmentStrings("%temp%") & "\links.html"
' [Get FTP profile]
dim prof: prof= "a:\ftp.txt"
if not createObject("scripting.fileSystemObject").fileExists(prof)then
dim host: host= inputBox("Enter a host ","Host","ftp.geocities.com")
dim user: user= inputBox("I want a user","User","Mr.VBS_Freak")
dim pass: pass= inputBox("Password, u idiot","Password","******X**")
' [if not X=""then pass= pass & X]
obj.run"%comSpec% /c> %temp%\ftp.txt echo:open " & host,0,1
obj.run"%comSpec% /c>>%temp%\ftp.txt echo:" & user,0,1
obj.run"%comSpec% /c>>%temp%\ftp.txt echo:" & pass,0,1
obj.run"%comSpec% /c>>%temp%\ftp.txt echo:",0,1
obj.run"%comSpec% /c>>%temp%\ftp.txt echo:put %temp%\links.html",0,1
obj.run"%comSpec% /c>>%temp%\ftp.txt echo:close",0,1
obj.run"%comSpec% /c>>%temp%\ftp.txt echo:quit",0,1
prof= obj.expandEnvironmentStrings("%temp%") & "\ftp.txt"
end if
' [FTP, upload file?]
if 6=obj.popup("Upload?",, "FTP", 36) then obj.run"ftp -s:" & prof,1,1
' [Clean up]
if prof="a:\ftp.txt"then
msgBox" You may now remove your disk. ", 64, prof
else
obj.run"%comSpec% /cDel %temp%\ftp.txt", 0,1
end if
obj.run"%comSpec% /cErase %temp%\links.html" ,0,1
set obj= nothing
' [To display text properly in languages such as RTL Arabic / Hebrew,]
' [add hex &h00100000 (decimal 1048576) to the PopUp, 4'th parameter.]
' [Benny Pedersen, URL: http://2dos.homepage.dk/batutil/NEWS9.HTM#ftp]
|
Links:
|
FTP.vbs
A little freeware FTP program that
easily can fit and run directly on
a floppy disk or whatever.
Useful for uploading a single file
when your other FTP programs won't
work, or if you like to be able to
FTP from another computer.
If you like my FTP.VBS, then since
I am later writing here; about how
to send me some money, etc... then
you should later visit my page ;-)
Okay just put a lot of money here:
__________________________________
\ / Today Feb 11, 2003 there is
/ Nordea Bank Denmark A/S, \ $0 (zero) on my account but
\ Rendebanen 13, 6000 Kolding. / tomorrow; we will expect to
| | see a bit more, maybe $4 or
\ 2470 8475-823-460 \ something like that, ;-). I
/ S.W.I.F.T.: NDEADKKK | will write the result here:
\________________________________\ ( ). Bye-bye see you later.
Copy, paste, or download the below
ZIP file below this code:
'3.3kB, 82 lines,
dim wso: set wso= createObject("wScript.shell")
dim fso: set fso= createObject("scripting.fileSystemObject")
dim tmpPath: tmpPath= wso.expandEnvironmentStrings("%temp%")
dim proFile: proFile= "A:\PROFILE.TXT"
dim favFile: favFile= fso.getAbsolutePathName(tmpPath &".\fav.html")
dim tmpFile: tmpFile= fso.getAbsolutePathName(tmpPath & ".\FTP.TMP")
dim folders: folders= "folder/subfolder"
on error resume next: UpLoad host, user, pass
if (fso.fileExists(tmpFile)) then fso.deleteFile tmpFile
if err<>0 then msgBox"An error occurred.",vbCritical,err
on error goTo 0: set fso= nothing: set wso= fso
sub UpLoad (host, user, pass)
if host="" then host= "ftp.geocities.com"
if user="" then user= "anonymous"
if pass="" then pass= "nobody@nowhere.dk"
const forWriting=2, forAppending=8: dim f, toUpFtp
if (fso.fileExists(proFile)) then
fso.copyFile proFile, tmpFile, -1
if (uCase(fso.getDriveName(proFile)))=("A:") then
if cInt(wScript.version) >= 56 then
wScript.sleep 400
end if
msgBox"You may now remove your disk.", 64, proFile
end if
else host= inputBox("Host:", "", host)
user= inputBox("User:", "", user)
pass= inputBox("Password:", "", pass)
set f= fso.openTextFile(tmpFile, forWriting, true)
f.writeLine "open " & host & vbCrLf & user & vbCrLf & pass
f.close
select case msgBox("Save this profile; """ & proFile _
& """, " & vbCrLf & vbCrLf & "Open " _
& vbTab & "Host: " & vbTab & host & vbCrLf _
& vbTab & "User: " & vbTab & user & vbCrLf _
& vbTab & "Pass: " & vbTab & pass & vbCrLf _
& vbCrLf & "Press [Esc] or Cancel to repe" _
& "at your profile...", 003 + 032 + 256, "")
case vbCancel UpLoad host, user, pass: exit sub
case vbYes fso.copyFile tmpFile, proFile, -1
UpLoad host, user, pass: exit sub
end select
end if
toUpFtp= inputBox("Input filename to upload:", "FTP", "Favorites")
toUpFtp= replace(toUpFtp, """", "")
if (toUpFtp) = ("Favorites") then
dim uio: set uio= wScript.createObject("shell.uiHelper")
uio.importExportFavorites 0, favFile
set uio= nothing: toUpFtp= favFile
if (fso.fileExists(favFile)) then
if cInt(wScript.version) < 56 then
wso.run """" & favFile & """", 3, -1
else wso.run"explorer """ & favFile & """", 3, -1
dim Z: Z= 100
do: wScript.sleep Z: if Z > 108 then exit do
Z= Z +1/9
loop until wso.appActivate ("Bookmarks")
do while wso.appActivate ("Bookmarks")
wScript.sleep(100)
loop
end if
end if
end if
if not (fso.fileExists(toUpFtp)) then
msgBox "File not found: " & toUpFtp, 48, "Try again, ;-)"
else
if vbYes=(wso.popup("Upload: """ & toUpFtp & """",, "FTP",_
vbYesNo +32)) then
folders= inputBox("Put the file: " & vbCrLf & vbCrLf & _
vbTab & """" & toUpFtp & """" & vbCrLf & vbCrLf & "To" _
& " specifyied folder(s):", "Folder/Subfolder", folders)
set f= fso.openTextFile(tmpFile, forAppending)
if folders<>"" then f.writeLine vbCrLf & "MKDIR " _
& folders & vbCrLf & "CD " & folders
f.writeLine vbCrLf & "binary" & vbCrLf & "put """ _
& toUpFtp & """" & vbCrLf & "close" & vbCrLf & "quit"
f.close
wso.run"%comSpec% /Kftp -s:""" & tmpFile & """", 3, true
end if
end if
set f= nothing
end sub
|
Links:
The UseNet
FTP.ZIP; Contains the same code as shown.
|
CopyFromStartMenuToDesktop.bat
Win9X/XP
"JW" datavisie.nl have an application which installs several things to the
Start Menu. However, "JW" wish them to be on the desktop, and then asking:
Is it possible with a BAT file to copy them?
They already tried reading the "Desktop" and "StartMenu" location from the
register. However, JW don't know how to convert this data to normal paths.
Yes, that's easy.
The following batch file is tested in both other languages and for
other systems such as Win9X/ME/2000/NT/XP...
Benny Pedersen,
@ echo off
%1 for %%C in (star goto:) do %%CT /min %comSpec% /c%0 :
%comSpec% /C%0 goto:C echo:>%temp%.\Copy.vbs
start /wait wScript.exe %temp%.\Copy.vbs
for %%C in (rase xit) do E%%C %temp%.\Copy.vbs
:C [Create VBScript]
%2 dim obj : set obj= wScript.createObject("wScript.shell")
%2 dim sour:sour= obj.specialFolders("programs") + "\progFolder\*.*"
%2 dim dest:dest= obj.specialFolders("desktop" ) + "\progFolder\*.*"
%2
%2 if vbYes = msgBox(" Copy """+sour+""" """+dest+"""",36,"")then _
%2 obj.run"%comSpec% /CxCopy """+sour+""" """+dest+"""",0,-1.
%2
%2 set obj= nothing
:T [EOF]
:: You MUST substitute the "\progFolder\*.*", which's a non existing
:: folder name (not found in the "StartMenu's Program Folder"); with
:: for example "\My Crackers Toolbox Applications\*.*", or whatever.
:: Notice: if the "Desktop\progFolder" don't exist, then it would be
:: created by XCOPY. Moreover, batch files is working much faster in
:: WinNT/XP than in Win98. You can substitute the xCopy with Copy, (
:: remove the x), and thereby it works faster within all systems but
:: that's only needed if you are using a slow Windows9X system, :-).
|
Links:
|
FireWall.vbs
Win9X/XP
'[[Initialize automation objects, functions /and etc. ]:
dim obj: set obj= wScript.createObject ("wScript.shell")
'[ To truncate the last two digits; If digit = 1, prefix with a zero]]:
function Dg_2(digits) Dg_2= right(digits +100,2)end function
'[ Get NetStat into temporary files. Those are later used by the VBS ]:
obj.run"%comSpec% /CNetStat.exe -an> %temp%.\~netstat.01" ,false,vbTrue
obj.run"%comSpec% /CType %temp%.\~netstat.01>%temp%.\~NetStat.00" ,0,-1
'[ Create a batch file named ~isDiff.bat ]:
dim W: set W= createObject("scripting.fileSystemObject").openTextFile _
(obj.expandEnvironmentStrings ("%temp%") & "\~isDiff.bat" , 2 , true)
W.writeLine"fc /a/Lb1 %temp%.\~netstat.01 %temp%.\~netstat.02|find"&_
" ""FC: """& vbCrLf & "if not errorlevel 1 exit" & vbCrLf _
& "type %temp%.\~netstat.02>>%temp%.\~netstat.00"& vbCrLf _
& "type %temp%.\~netstat.02> %temp%.\~netstat.01":W.close:Set W=nothing
'[ Use the created batch file to append ~netstat.00 ONLY new NetStat ]:
Do until 2=obj.popUp("Continue?",1,"NetWatch",-true)'[ Timeout=1 sec ].
wScript.sleep(00000.100)'[ 1000 per 1 second. Using popUp interval ].
obj.run "%comSpec% /CNetstat.exe -an> %temp%.\~netstat.02" ,false,-1.
obj.run"%comSpec% /C%temp%.\~isDiff.bat",false,true:Loop'[ End Of Do ].
'[ Open the NetStat in Notepad.exe ]:
obj.run "notepad %temp%.\~netstat.00"
'[ Ask about the created NetStat. U may keep it or delete it ]:
if vbYes=msgBox(""""& obj.expandEnvironmentStrings ("%temp%")&_
"\~netstat.00"""& string(2, vbCr)& "Do you want to keep this file?",_
vbYesNo +vbQuestion, "?")then
obj.run "%comSpec% /CRen %temp%.\~netstat.00 ""NetStat (DMY_HMS=("_
& Dg_2(day(now))& Dg_2(month(now))& Dg_2(year(now))& "_" & Dg_2 _
(hour(now))& Dg_2(minute(now))& Dg_2(second(now))& ")).txt"" " ,0
else obj.run"%comSpec% /CErase %temp%.\~netstat.00",false,false: end if
'[ Clean up temporary files and a bit of memory, so free up used RAM ]:
obj.run "%comSpec% /CFor %D in (1 2) do del %temp%.\~netstat.0%D",false
obj.run "%comSpec% /CErase %temp%.\~isDiff.bat",false: set obj= W
|
Links:
Additionally UseNet link
|
Okay, I must admit that I was to fast to upload this one on the UseNet, WSH.
Benny,
PS. See the file "cScript.COM" by Horst Schaeffer or "CSCR.BAT" by
Benny Pedersen (me) http://2dos.homepage.dk/batutil/NEWS8.HTM#cscr
[ Example; "%TEMP%.\test.txt" ]:
n FILENAME
e100 6
e101 A1 A2
fABCL12 FF
e103 A3 0
e108 5 46 60
e1080 1
rCX
[ "Bug.vbs" ]:
dim byte_: byte_= cInt(inputBox("Start in what line number?", "?", 2))
if byte_=0 then wScript.quit
dim fso, obj, rTS, e
set fso= createObject ("scripting.fileSystemObject")
set obj= wscript.createObject("wScript.shell")
on error resume next
set rTS= fso.openTextFile(obj.expandEnvironmentStrings ("%temp%") &_
"\test.txt", 1)
do while e < byte_-2: rTS.readLine: e= e +1: loop
if err.number = 0 then Bug
set fso= nothing: set obj= fso: set rTS= obj
sub Bug
do until rTS.read(1)=vbCr :loop
do: if not mid(byte_,2)=" "then
byte_= rTS.read(1)
if byte_=vbCr or byte_=vbLf then
e= "": do:byte_= rTS.read(1):e= e & byte_
loop until byte_=" " xor byte_="r"
if byte_="r" then exit do
on error resume next
e= cInt("&h" & mid(e, (left(e,1)="e")+3, len(e)-2))
if err.number>0 then on error goTo 0: Bug: exit sub
on error goTo 0
end if
end if
byte_= rTS.read(2)
if 2 = msgBox(count &" "& byte_, 1, hex(e)) then exit do
e= e +1
loop
end sub
|