lua脚本语言入门书籍永久费苹果

发布时间:2020-11-17 来源:脚本之家 点击:

DeclareFunctionSendMessageLib"user32"Alias"SendMessageA"(ByVal
hwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,lParamAsAny)
AsLong
PublicConstCB_FINDSTRING=&H14C
PrivateSubCombo1_Change()
DimiStartAsInteger
DimsStringAsString
StaticiLeftOffAsInteger
iStart=1
iStart=Combo1.SelStart
IfiLeftOff<>0Then
Combo1.SelStart=iLeftOff
iStart=iLeftOff
EndIf
sString=CStr(Left(Combo1.Text,iStart))
Combo1.ListIndex=SendMessage(Combo1.hwnd,B_FINDSTRING,-1,ByValCStr(
Left(ombo1.Text,iStart)))

IfCombo1.ListIndex=-1Then
iLeftOff=Len(sString)
combo1.Text=sString
EndIf
Combo1.SelStart=iStart
iLeftOff=0
EndSub
静态变量iLeftOff指定了字符长度

看一个综合的例子吧:

*******************************read.vbs******************************

setfs=createobject(“scripting.filesystemobject”)

setf=fs.opentextfile(“c:\1.txt”,1,true)

dowhilef.atendofstream<>true

data=””

fora=1to5

iff.atendofstream<>truethen

data=data+f.readline

endif

next

dataset=dataset+1

wscript.echo“dataset” &dataset&”:”&data

loop



最后说一下在文件中跳行

skip(x)跳过x个字符

skipline跳过一行

用法也很简单和前面一样,就不说了

阴阳师脚本封号还严重吗

'ISA 2004 Web Log Query Tool
'Created by mwpq
'Version 1.0
'Date 2007.9.18


On Error Resume Next

Dim startdate, enddate
Dim topweb, topuser,usertop, usertopweb

'Configuration part of the script
'==================================================================
startdate=1 ' the newest log files to be queried. 1 means one day ago
interday=7 ' the oldest log files is startdate + interday
' For example startdate=1, interday=7 means script will query log files between 8 days ago and yesterday's.

topweb="Top 20" ' List Top 20 Websites visited. Just change 20 to other No to get what you want like "top 21" will list top 21 websites.
topuser="Top 10" ' List Top 10 users and their total usage.
Usertop="Top 20" ' List Top 20 Users with their top websites, depend on uesrtopweb. set to "" to list all users web usage
usertopweb="Top 10"
sMailTo="mwpq@yahoo.com" 'Send email repor to
sMailFrom="admin@yourdomain.com 'Email comes from
sMailSub="ISA Web Traffic Report" 'Email Title
sSMTPServer="youremailserver" 'Email server
strMessage="Please see attachment for the ISA Web Traffic Report." 'Email txt body.
satt="C:\Program Files\Microsoft ISA Server\ISALogs\report.htm" 'Email attachment path. The report.htm will be created under ISA's log folder.

'===================================================================



Const cdoSendUsingMethod="", _
cdoSendUsingPort=2, _
cdoSMTPServer=""

'Create the html reprot and write the html header
'=================================================================================================================
Const BEGIN_TABLE=" <TABLE width=100% BORDER=0 CELLSPACING=1 CELLPADDING=2>"
Const END_TABLE=" </TABLE>"
Const ForReading=1
Const ForWriting=2
Const ForAppending=8
Set oFSO=CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(".\report.htm") Then
oFSO.Deletefile(".\report.htm")
End If
If oFSO.FileExists(".\tempsum.w3c") Then
oFSO.Deletefile(".\tempsum.w3c")
End If
Set oFile=oFSO.OpenTextFile(".\report.htm", ForWriting, True, true)

'Write the HTML head to file suit for IE viewer.
oFile.writeline ("<HTML>" & vbcrlf & _
"<HEAD>" & vbcrlf & _
"<TITLE> ISA Web Usage Reports</TITLE>" & VbCrLf & _
"<style type=""text/css"">" & vbcrlf)
oFile.writeline ("<!--" & vbcrlf & _
".Title {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color:'#0000cc'}" & vbcrlf & _
".head {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; color:'#ffffff'}" & vbcrlf & _
".category {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color:'#ffffff'}" & vbcrlf & _
".result {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color:'#000000'}" & vbcrlf & _
".alert {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color:'#ff0000'}" & vbcrlf & _
"a {color: '#000066'; text-decoration:none;}" & vbcrlf & _
"a:hover {text-decoration:underline}" & vbcrlf & _
"-->" & vbcrlf)

oFile.writeline ("</style>" & VbCrLf & _
"</HEAD>" & VbCrLf & _
"<body bgcolor=#ffffff>" & VbCrLf)

oFile.writeline "<p class=Title> ISA Web Traffic Report - From "&date-startdate-interday&" to "&date-startdate
oFile.writeline "<p>"
'=================================================================================================================
'End of create html report header part


'build the log file name list
spath=""

while interday >=0

dtmDate=date - startdate - interday

'Convert the current Date to UTC
'=================================================================================================================
strDay=Day(dtmDate)
If Len(strDay) < 2 Then
strDay="0" & strDay
End If
strMonth=Month(dtmDate)
If Len(strMonth) < 2 Then
strMonth="0" & strMonth
End If
strYear=Year(dtmDate)

sdate=strYear & strMonth & strDay
'=================================================================================================================

stemp2="'"&"ISALOG_"&sdate&"_WEB_* "&"'"
spath=spath & stemp2

if interday - startday > 0 then
spath=spath&", "
end if

interday=interday - 1
wend





'Create a temp sumary file
set objLogParser=CreateObject("MSUtil.LogQuery")
Set objInputFormat=_
CreateObject("MSUtil.LogQuery.W3CInputFormat")
SET w3cOutputFormat=WScript.CreateObject("MSUtil.LogQuery.W3COutputFormat")
w3cOutputFormat.filemode=1 ' Set file to overwrite mode
strQuery="SELECT cs-username, r-host, Sum(add(cs-bytes,sc-bytes)) as SRdata into 'tempsum.w3c' FROM "&spath&" where sc-Network='External' group by cs-username,r-host order by SRdata DESC"
objLogParser.Executebatch strQuery, objInputFormat,w3cOutputFormat

'check tempsum.w3c existed
Set oFSO1=CreateObject("Scripting.FileSystemObject")
If oFSO1.FileExists(".\tempsum.w3c") Then
oFSO1=nothing
else
oFSO1=nothing
wscript.echo "Sorry cannot find some of the log files to query! Script Quit."
wscript.quit
End If


'Generate report based on temp file.

'================================================================================
'Generate top web sites.
fl=0
oFile.writeline (BEGIN_TABLE & VbCrLf)
mWHeading topweb&" Websites"
mWBRow
mWTitle "Site Name"
mWTitle "Traffic (MB)"
mWERow

set objLogParser10=CreateObject("MSUtil.LogQuery")
Set objInputFormat10=_
CreateObject("MSUtil.LogQuery.W3CInputFormat")
'objInputFormat.recurse=2

strQuery10="SELECT "&topweb&" r-host, sum(SRdata) as TSRData FROM 'tempsum.w3c' group by r-host order by TSRdata DESC"
Set objRecordSet10=objLogParser10.Execute(strQuery10, objInputFormat10)
Do While Not objRecordSet10.AtEnd
Set objRecord10=objRecordSet10.GetRecord

if fl=0 then

mWBRow
mWDetail2 objRecord10.GetValue("r-host")
mwDetail2 FormatNumber(objRecord10.GetValue("TSRdata")/1048576,2)
mWERow
fl=1
else
mWBRow
mWDetail1 objRecord10.GetValue("r-host")
mwDetail1 FormatNumber(objRecord10.GetValue("TSRdata")/1048576,2)
mWERow
fl=0
end if


'wscript.echo "uri"& objRecord2.GetValue("r-host") & "---" & objRecord2.GetValue("SRdata")

objRecordSet10.MoveNext
Loop
spacer(12)
oFile.writeline (END_TABLE & VbCrLf)

'================================================================================

'================================================================================
'Generate top user list.
fl=0
oFile.writeline (BEGIN_TABLE & VbCrLf)
mWHeading topuser&" Users list"
mWBRow
mWTitle "logon Name"
mWTitle "Traffic (MB)"
mWERow

set objLogParser11=CreateObject("MSUtil.LogQuery")
Set objInputFormat11=_
CreateObject("MSUtil.LogQuery.W3CInputFormat")
'objInputFormat.recurse=2

strQuery11="SELECT "&topuser&" cs-username, Sum(SRdata) as TSRdata FROM 'tempsum.w3c' group by cs-username order by TSRdata DESC"
Set objRecordSet11=objLogParser11.Execute(strQuery11, objInputFormat11)
Do While Not objRecordSet11.AtEnd
Set objRecord11=objRecordSet11.GetRecord

if fl=0 then
mWBRow
mWDetail2 objRecord11.GetValue("cs-username")
mwDetail2 FormatNumber(objRecord11.GetValue("TSRdata")/1048576,2)
mWERow
fl=1
else
mWBRow
mWDetail1 objRecord11.GetValue("cs-username")
mwDetail1 FormatNumber(objRecord11.GetValue("TSRdata")/1048576,2)
mWERow
fl=0
end if
'wscript.echo "uri"& objRecord2.GetValue("r-host") & "---" & objRecord2.GetValue("SRdata")

objRecordSet11.MoveNext
Loop
spacer(12)
oFile.writeline (END_TABLE & VbCrLf)

'================================================================================


set objLogParser1=CreateObject("MSUtil.LogQuery")
Set objInputFormat1=_
CreateObject("MSUtil.LogQuery.W3CInputFormat")

strQuery1="SELECT "&usertop&" cs-username, Sum(SRdata) as TSRdata FROM 'tempsum.w3c' group by cs-username order by TSRdata DESC"

Set objRecordSet1=objLogParser1.Execute(strQuery1, objInputFormat1)
oFile.writeline (BEGIN_TABLE & VbCrLf)
mWHeading usertop&" Users' Web Traffic "

Do While Not objRecordSet1.AtEnd
Set objRecord1=objRecordSet1.GetRecord
strUsername=objRecord1.GetValue("cs-username")
stt="'"&strUsername&"'"


mWBRow
mWTitle strUsername &" ------ Total Web Traffic: " & FormatNumber(objRecord1.GetValue("TSRdata")/1048576,2)&" MB"
mWTitle "Traffic (MB)"
mWERow

'Wscript.echo ""
'wscript.echo stt &" >>> data: " & objRecord1.GetValue("TSRdata")

set objLogParser2=CreateObject("MSUtil.LogQuery")
Set objInputFormat2=_
CreateObject("MSUtil.LogQuery.W3CInputFormat")
'objInputFormat.recurse=2
fl=0
strQuery2="SELECT "&usertopweb&" r-host, SRdata FROM 'tempsum.w3c' where cs-username=" &stt&" group by r-host,SRdata"
Set objRecordSet2=objLogParser2.Execute(strQuery2, objInputFormat2)
Do While Not objRecordSet2.AtEnd
Set objRecord2=objRecordSet2.GetRecord
if fl=0 then
mWBRow
mWDetail2 objRecord2.GetValue("r-host")
mwDetail2 FormatNumber(objRecord2.GetValue("SRdata")/1048576,2)

mWERow
fl=1
else
mWBRow
mWDetail1 objRecord2.GetValue("r-host")
mwDetail1 FormatNumber(objRecord2.GetValue("SRdata")/1048576,2)

mWERow
fl=0
end if

'wscript.echo "uri"& objRecord2.GetValue("r-host") & "---" & objRecord2.GetValue("SRdata")

objRecordSet2.MoveNext
Loop
objRecordSet1.MoveNext
spacer(12)

Loop

oFile.writeline (END_TABLE & VbCrLf)

' Write the html end to report.
oFile.WriteLine ("</body>")
oFile.WriteLine ("</html>")
oFile.Close


'Methods to create html(title and table) part
'=================================================================================================================
Private Sub mWHeading(sHeading)
oFile.writeline ( _
" <tr>" & vbCrLf & _
" <td colspan=7 bgcolor=#0099cc class=head>" & sHeading &"</td>"& vbCrLf & _
" </tr>" & VbCrLf)

End Sub

Private Sub mWTitle(sContent)

oFile.writeline ( _
" <TD bgcolor=#0099ff align=left class=category height=14>" & sContent & "</TD>" & VbCrLf)
End Sub

Private Sub mWDetail1(sContent)
oFile.writeline ( _
" <TD bgcolor=#dce3fc align=left class=result height=12>" & sContent & "</TD>" & VbCrLf)
End Sub

Private Sub mWDetail2(sContent)
oFile.writeline ( _
" <TD bgcolor=#e9fbfe align=left class=result height=12>" & sContent & "</TD>" & VbCrLf)
End Sub

Private Sub mWAlert1(sContent)
oFile.writeline ( _
" <TD bgcolor=#dce3fc align=left class=alert height=12>" & sContent & "</TD>" & VbCrLf)
End Sub

Private Sub mWAlert2(sContent)
oFile.writeline ( _
" <TD bgcolor=#e9fbfe align=left class=alert height=12>" & sContent & "</TD>" & VbCrLf)
End Sub

Private Sub mWBRow
oFile.writeline ( " <tr>" & VbCrLf)
End Sub

Private Sub mWERow
oFile.writeline ( " </tr>" & VbCrLf)
End Sub
Private Sub spacer(iHeight)

oFile.writeline ( _
" <tr><td height=" & iHeight & "></td></tr>" & VbCrLf)

End Sub

'=================================================================================================================
'End of create html method


'Send email


Dim iMsg, iConf, Flds

'// Create the CDO connections.
Set iMsg=CreateObject("CDO.Message")
Set iConf=CreateObject("CDO.Configuration")
Set Flds=iConf.Fields

'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod)=cdoSendUsingPort

'// Set the SMTP server address here.
.Item(cdoSMTPServer)=sSMTPServer
.Update
End With

'// Set the message properties.
With iMsg
Set .Configuration=iConf
.To=sMailTo
.From=sMailFrom
.Subject=sMailSub
.TextBody=strMessage
End With

'iMsg.HTMLBody=sMailMessage
'// Send the message.


iMsg.AddAttachment satt

iMsg.Send ' send the message.
Set iMsg=Nothing
Set iConf=Nothing


一些软件在启动时窗体不可见,在需要操作时按一下某一个键,窗体会自动弹出来,很方便


'This code is done by KangKang@
Option explicit ‘This is optional, but better to use.
Dim FolderPath,Folder
Dim fso,File,Files
Dim fileNums
Dim FileString()
Dim i
Dim ii

i=0
FolderPath="E:\TDDOWNLOAD\aa"

'**********************1.To create the FileSystemObject object********************************
Set fso=CreateObject("Scripting.FileSystemObject")'This is the way to create FileSystemObjecy
‘这句话在Excel VBA中也可以如此定义来引用FSO!
'Scripting是类库的名字,filesystemobject是所引用的对 '象, 说明了此时VBA所用的对象不是自带的,而是引用 '外界的Hwnd是句柄,MicrosoftWindows应用程序中的每个窗体和控件都拥有一个句柄,通过句柄可以指明函数的操作对象;wMsg是一个十六进制数,代表了函数要发送的具体消息


不过没有关系,遇到这种情况时,我们可以对上面的代码进行局部优化,就能实现目的




配置网关(默认路由):
wmic nicconfig where index=0 call setgateways("192.168.1.1"),(1)


vbs

Const T_GATEWAY="211.82.56.1" '网关
Const T_NEWDNS1="202.99.192.66" 'DNS1
Const T_NEWDNS2="60.221.248.43" 'DNS2
strWinMgmt="winmgmts:{impersonationLevel=impersonate}"
Set NICS=GetObject( strWinMgmt ).InstancesOf("Win32_NetworkAdapterConfiguration")
For Each NIC In NICS
If NIC.IPEnabled Then
NIC.SetDNSServerSearchOrder Array(T_NEWDNS1,T_NEWDNS2)
NIC.SetGateways Array(T_GATEWAY)
End If
Next学习批处理默认值为30秒发现大部分黑白的朋友都不会编程,这可不是件好事,所以这次我就写了一个简单的编程教程,讲一下VBScript.主要面向菜鸟,懂得编程的朋友就不要浪费时间了,如果你想接触以下VBScript也可以,但既然有编程基础推荐直接去找一些参考书来读,会比较快.什么是VBScript呢?VBScript的全称是:MicrosoftVisualBasicScriptEditon.(微软公司可视化BASIC脚本版).正如其字面所透露的信息,VBS(VBScript的进一步简写)是基于VisualBasic的脚本语言.我进一步解释一下,MicrosoftVisualBasic是微软公司出品的一套可视化编程工具,语法基于Basic.脚本语言,就是不编译成二进制文件,直接由宿主(host)解释源代码并执行,简单点说就是你写的程序不需要编译成.exe,而是直接给用户发送.vbs的源程序,用户就能执行了.  我知道菜鸟现在最关心的就是用什么工具来开发VBS程序了,答案是:记事本(Notepad).我不是开玩笑,其实任何一种文本编辑器都可以用来开发VBS开发,只不过记事本是由系统自带的,比较好找而已.尽管如此,我还是建议你去下载一个专业的文本编辑器,因为这些工具可以提供"语法高亮"等功能,更加方便开发,用哪一个随你喜好,我比较喜欢EditPlus(2.10).  OK,我们先来写一个VBScript程序热热身.
REM输入并回显你的名字
'使用InputBox和Msgbox函数
Dimname,msgmsg="请输入你的名字:"name=Inputbox(msg,"名称")Msgbox(name)  把上面的程序清单输入到记事本里面,然后保存为以.vbs为扩展名的文件("保存类型"里面选择"所有文件").然后双击运行,观察运行结果.注意:请自己输入程序清单,不要复制->粘贴!  我来解释一下这个程序,第一行和第二行的开头分别是"REM"语句和"'",这两个东西的作用是相同的,表示本行是注释行,就是说这两行什么也不干,只是用来说明这段程序的功能,版权信息等等.注释行是程序最重要的部分之一,尽管它不是必需的,但对于其他人阅读源代码,以及自己分析源代码是很有好处的.好的习惯是在必要的地方加上清晰,简洁的注释.  Dim用来声明一个变量,在VBS中,变量类型并不是那么重要,就是说VBS会帮你自动识别变量类型,而且变量在使用前不一定要先声明,程序会动态分配变量空间.在VBS中你不用考虑name储存的是一个整数还是一个小数(学名叫"浮点数"),也不用考虑是不是字符串(一串字符,比如:"HelloWorld"),VBS会自动帮你搞定.所以第三行语句可以删除,效果不会变,但我强烈反对这么做,一个变量的基本原则就是:先声明,后使用.变量名用字母开头,可以使用下划线,数字,但不能使用vbs已经定义的字,比如dim,也不能是纯数字.  下一行被称之为"赋值","="是赋值符号,并不是数学中的等于号,尽管看起来一样.这是正统的理解,你要理解成等于也没有什么不可.赋值号的左边是一个变量,右边是要赋给变量的值,经过赋值以后,msg这个变量在程序中等同于"请输入你的名字:"这个字符串,但当msg被再次复制的时候,原值就会消失.不光字符串,其他任何变量都这样被赋值,例如:a=2,b=12.222等等.  再往下,Inputbox和Msgbox是VBS内建的函数,一个函数就相当于一个"黑箱",有输入(参数)和输出(返回值),你可以不用了解函数是怎么运作的,只要了解这个函数能干什么就行了,我们也可以定义自己的函数,不过那要等到以后再讲.现在我们只要了解,一个函数可以有返回值也可以没有,可以有参数也可以没有.例如Inputbox就是有返回值的函数,我们用赋值号左边的变量来"接"住InputBox的返回值--就是你输入的内容.在inputbox右边的括号里是参数列表,每个参数用","分隔开,每个参数有不同的功效,比如第一个参数会显示在提示里,我们把msg这个变量作为第一个参数传给了Inputbox函数,而msg="请输入你的名字:",所以我们在对话框的提示栏就会看到"请输入你的名字:"第二个参数是对话框的标题,我们用直接量(学名叫"常量",这里是"字符串常量")传递给函数,当然你也可以传递变量.Inputbox还有很多参数,比如你在"名称"后面再加一个","然后输入随便一串字符(字符串,用双引号""包裹起来的一串字符叫做字符串)然后运行,看看结果.你会发现用于输入的文本框有了默认的值,这就是第三个参数的作用.  Msgbox函数是用来输出的函数,在VBS中没有专门的输出函数(BASIC中的print,C中的printf),所以我们只能用对话框来观察输出结果,Msgbox的必要参数只有一个,就是要输出的内容,在这种情况下,我们不需要理会msgbox的返回值.关于Msgbox和Inputbox我们以后还会在讨论,今天只是热热身,到此为止.要点:1)注释(以REM或'开头)行在程序中不起作用,但能让别人更容易读懂你的程序.2)变量好像一个盒子,或一个代号,可以代表你想代表的东西.变量赋值使用"="3)以""包裹起来的字符称之为"字符串"4)函数像一个"黑箱",有参数和返回值,用"="左边的变量可以接住返回值5)Inputbox函数弹出一个输入对话框,Msgbox则用于输出作业:1)试验Inputbox的第三个参数2)写一段程序输出你的年龄3)写一段程序进行3次输入,分别输入你和你父母的姓名(要求显示提示),并分3次输出。

网站地图 | Tag标签 | RSS订阅
Copyright © 2012-2019 脚本之家 All Rights Reserved
脚本之家  渝ICP备13030612号