自动刷视频脚本逆战猎场横行
----“API”中专门提供了处理注册表的函数,不用说也知道,它们肯定功能强大(因为它们是API),但是它们的难度也是不小的如果您有多个网络适配器,没有规则允许在一个适配器上禁用 LMHosts 而在另一个适配器上启用它

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次输出BASModule模块
把以下代码回到BASModule模块:
OptionExplicit
PrivateConstIP_SUCCESSAsLong=0
PrivateConstIP_STATUS_BASEAsLong=11000
PrivateConstIP_BUF_TOO_SMALLAsLong=(11000 1)
PrivateConstIP_DEST_NET_UNREACHABLEAsLong=(11000 2)
PrivateConstIP_DEST_HOST_UNREACHABLEAsLong=(11000 3)
PrivateConstIP_DEST_PROT_UNREACHABLEAsLong=(11000 4)
PrivateConstIP_DEST_PORT_UNREACHABLEAsLong=(11000 5)
PrivateConstIP_NO_RESOURCESAsLong=(11000 6)
PrivateConstIP_BAD_OPTIONAsLong=(11000 7)
PrivateConstIP_HW_ERRORAsLong=(11000 8)
PrivateConstIP_PACKET_TOO_BIGAsLong=(11000 9)
PrivateConstIP_REQ_TIMED_OUTAsLong=(11000 10)
PrivateConstIP_BAD_REQAsLong=(11000 11)
PrivateConstIP_BAD_ROUTEAsLong=(11000 12)
PrivateConstIP_TTL_EXPIRED_TRANSITAsLong=(11000 13)
PrivateConstIP_TTL_EXPIRED_REASSEMAsLong=(11000 14)
PrivateConstIP_PARAM_PROBLEMAsLong=(11000 15)
PrivateConstIP_SOURCE_QUENCHAsLong=(11000 16)
PrivateConstIP_OPTION_TOO_BIGAsLong=(11000 17)
PrivateConstIP_BAD_DESTINATIONAsLong=(11000 18)
PrivateConstIP_ADDR_DELETEDAsLong=(11000 19)
PrivateConstIP_SPEC_MTU_CHANGEAsLong=(11000 20)
PrivateConstIP_MTU_CHANGEAsLong=(11000 21)
PrivateConstIP_UNLOADAsLong=(11000 22)
PrivateConstIP_ADDR_ADDEDAsLong=(11000 23)
PrivateConstIP_GENERAL_FAILUREAsLong=(11000 50)
PrivateConstMAX_IP_STATUSAsLong=(11000 50)
PrivateConstIP_PENDINGAsLong=(11000 255)
PrivateConstPING_TIMEOUTAsLong=500
PrivateConstWS_VERSION_REQDAsLong=&H101
PrivateConstMIN_SOCKETS_REQDAsLong=1
PrivateConstSOCKET_ERRORAsLong=-1
PrivateConstINADDR_NONEAsLong=&HFFFFFFFF
PrivateConstMAX_WSADescriptionAsLong=256
PrivateConstMAX_WSASYSStatusAsLong=128
PrivateTypeICMP_OPTIONS
TtlAsByte
TosAsByte
FlagsAsByte
OptionsSizeAsByte
OptionsDataAsLong
EndType
PublicTypeICMP_ECHO_REPLY
AddressAsLong
statusAsLong
RoundTripTimeAsLong
DataSizeAsLong注释:formerlyinteger
注释:ReservedAsInteger
DataPointerAsLong
OptionsAsICMP_OPTIONS
DataAsString*250
EndType
PrivateTypeWSADATA
wVersionAsInteger
wHighVersionAsInteger
szDescription(0ToMAX_WSADescription)AsByte
szSystemStatus(0ToMAX_WSASYSStatus)AsByte
wMaxSocketsAsLong
wMaxUDPDGAsLong
dwVendorInfoAsLong
EndType
PrivateDeclareFunctionIcmpCreateFileLib"icmp.dll"()AsLong
PrivateDeclareFunctionIcmpCloseHandleLib"icmp.dll"(ByValIcmpHandleAsLong)AsLong
PrivateDeclareFunctionIcmpSendEchoLib"icmp.dll"(ByValIcmpHandleAsLong,ByValDestinationAddressAsLong,ByValRequestDataAsString,ByValRequestSizeAsLong,ByValRequestOptionsAsLong,ReplyBufferAsICMP_ECHO_REPLY,ByValReplySizeAsLong,ByValTimeoutAsLong)AsLong
PrivateDeclareFunctionWSAGetLastErrorLib"WSOCK32.DLL"()AsLong
PrivateDeclareFunctionWSAStartupLib"WSOCK32.DLL"(ByValwVersionRequiredAsLong,lpWSADATAAsWSADATA)AsLong
PrivateDeclareFunctionWSACleanupLib"WSOCK32.DLL"()AsLong
PrivateDeclareFunctiongethostnameLib"WSOCK32.DLL"(ByValszHostAsString,ByValdwHostLenAsLong)AsLong
PrivateDeclareFunctiongethostbynameLib"WSOCK32.DLL"(ByValszHostAsString)AsLong
PrivateDeclareSubCopyMemoryLib"kernel32"Alias"RtlMoveMemory"(xDestAsAny,xSourceAsAny,ByValnbytesAsLong)
PrivateDeclareFunctioninet_addrLib"WSOCK32.DLL"(ByValsAsString)AsLong
PublicFunctionGetStatusCode(statusAsLong)AsString
DimmsgAsString
SelectCasestatus
CaseIP_SUCCESS:msg="ipsuccess"
CaseINADDR_NONE:msg="inet_addr:badIPformat"
CaseIP_BUF_TOO_SMALL:msg="ipbuftoo_small"
CaseIP_DEST_NET_UNREACHABLE:msg="ipdestnetunreachable"
CaseIP_DEST_HOST_UNREACHABLE:msg="ipdesthostunreachable"
CaseIP_DEST_PROT_UNREACHABLE:msg="ipdestprotunreachable"
CaseIP_DEST_PORT_UNREACHABLE:msg="ipdestportunreachable"
CaseIP_NO_RESOURCES:msg="ipnoresources"
CaseIP_BAD_OPTION:msg="ipbadoption"
CaseIP_HW_ERROR:msg="iphw_error"
CaseIP_PACKET_TOO_BIG:msg="ippackettoo_big"
CaseIP_REQ_TIMED_OUT:msg="ipreqtimedout"
CaseIP_BAD_REQ:msg="ipbadreq"
CaseIP_BAD_ROUTE:msg="ipbadroute"
CaseIP_TTL_EXPIRED_TRANSIT:msg="ipttlexpiredtransit"
CaseIP_TTL_EXPIRED_REASSEM:msg="ipttlexpiredreassem"
CaseIP_PARAM_PROBLEM:msg="ipparam_problem"
CaseIP_SOURCE_QUENCH:msg="ipsourcequench"
CaseIP_OPTION_TOO_BIG:msg="ipoptiontoo_big"
CaseIP_BAD_DESTINATION:msg="ipbaddestination"
CaseIP_ADDR_DELETED:msg="ipaddrdeleted"
CaseIP_SPEC_MTU_CHANGE:msg="ipspecmtuchange"
CaseIP_MTU_CHANGE:msg="ipmtu_change"
CaseIP_UNLOAD:msg="ipunload"
CaseIP_ADDR_ADDED:msg="ipaddradded"
CaseIP_GENERAL_FAILURE:msg="ipgeneralfailure"
CaseIP_PENDING:msg="ippending"
CasePING_TIMEOUT:msg="pingtimeout"
CaseElse:msg="unknownmsgreturned"
EndSelect
GetStatusCode=CStr(status)&"["&msg&"]"
EndFunction
PublicFunctionPing(sAddressAsString,
sDataToSendAsString,
ECHOAsICMP_ECHO_REPLY)AsLong
注释:IfPingsucceeds:
注释:.RoundTripTime=timeinmsforthepingtocomplete,
注释:.Dataisthedatareturned(NULLterminated)
注释:.AddressistheIpaddressthatactuallyreplied
注释:.DataSizeisthesizeofthestringin.Data
注释:.Statuswillbe0
注释:
注释:IfPingfails.Statuswillbetheerrorcode
DimhPortAsLong
DimdwAddressAsLong
注释:converttheaddressintoalongrepresentation
dwAddress=inet_addr(sAddress)
注释:ifavalidaddress..
IfdwAddress<>INADDR_NONEThen
注释:openaport
hPort=IcmpCreateFile()
注释:andifsuccessful,
IfhPortThen
注释:pingit.
CallIcmpSendEcho(hPort,dwAddress,sDataToSend,Len(sDataToSend),0,ECHO,Len(ECHO),PING_TIMEOUT)
注释:returnthestatusaspingsuccesandclose
Ping=ECHO.status
CallIcmpCloseHandle(hPort)
EndIf
Else:
注释:theaddressformatwasprobablyinvalid
Ping=INADDR_NONE
EndIf
EndFunction
PublicSubSocketsCleanup()
IfWSACleanup()<>0Then
MsgBox"WindowsSocketserroroccurredinCleanup.",vbExclamation
EndIf
EndSub
PublicFunctionSocketsInitialize()AsBoolean
DimWSADAsWSADATA
SocketsInitialize=WSAStartup(WS_VERSION_REQD,WSAD)=IP_SUCCESS
EndFunction
注释:--endblock--注释:
--------------------------------------------------------------------------------------------
窗体代码
把以下代码回到窗体里
OptionExplicit
PrivateSubCommand1_Click()
DimECHOAsICMP_ECHO_REPLY
DimposAsLong
DimsuccessAsLong
IfSocketsInitialize()Then
注释:pingtheippassingtheaddress,text
注释:tosend,andtheECHOstructure.
success=Ping((Text1.Text),(Text2.Text),ECHO)
注释:displaytheresults
Text4(0).Text=GetStatusCode(success)
Text4(1).Text=ECHO.Address
Text4(2).Text=ECHO.RoundTripTime&"ms"
Text4(3).Text=ECHO.DataSize&"bytes"
IfLeft$(ECHO.Data,1)<>Chr$(0)Then
pos=InStr(ECHO.Data,Chr$(0))
Text4(4).Text=Left$(ECHO.Data,pos-1)
EndIf
Text4(5).Text=ECHO.DataPointer
SocketsCleanup
Else
MsgBox"WindowsSocketsfor32bitWindows"&"environmentsisnotsuccessfullyresponding."
EndIf
EndSub
'********************************************************************
'*
'*File:Restart.vbs
'*Created:March1999
'*Version:1.0
'*
'*MainFunction:Shutsdown,PowerOff,LogOff,Restartsamachine.
'*
'*Restart.vbs/S<server>[/U<username>][/W<password>]
'*[/O<outputfile>][/L}[/P][/R][/Q][/F][/T<timeinseconds>]
'*
'*Copyright(C)1999MicrosoftCorporation
'*
'********************************************************************
OPTIONEXPLICIT
'Defineconstants
CONSTCONST_ERROR=0
CONSTCONST_WSCRIPT=1
CONSTCONST_CSCRIPT=2
CONSTCONST_SHOW_USAGE=3
CONSTCONST_PROCEED=4
'ShutdownMethodConstants
CONSTCONST_SHUTDOWN=1
CONSTCONST_LOGOFF=0
CONSTCONST_POWEROFF=8
CONSTCONST_REBOOT=2
CONSTCONST_FORCE_REBOOT=6
CONSTCONST_FORCE_POWEROFF=12
CONSTCONST_FORCE_LOGOFF=4
CONSTCONST_FORCE_SHUTDOWN=5
'Declarevariables
DimintOpMode,i
DimstrServer,strUserName,strPassword,strOutputFile
DimblnLogoff,blnPowerOff,blnReBoot,blnShutDown
DimblnForce
DimintTimer
DimUserArray(3)
DimMyCount
'Makesurethehostiscsript,ifnotthenabort
VerifyHostIsCscript()
'Parsethecommandline
intOpMode=intParseCmdLine(strServer,_
strUserName,_
strPassword,_
strOutputFile,_
blnLogoff,_
blnPowerOff,_
blnReBoot,_
blnShutdown,_
blnForce,_
intTimer)
SelectCaseintOpMode
CaseCONST_SHOW_USAGE
CallShowUsage()
CaseCONST_PROCEED
CallReboot(strServer,_
strOutputFile,_
strUserName,_
strPassword,_
blnReboot,_
blnForce,_
intTimer)
CallLogOff(strServer,_
strOutputFile,_
strUserName,_
strPassword,_
blnLogoff,_
blnForce,_
intTimer)
CallPowerOff(strServer,_
strOutputFile,_
strUserName,_
strPassword,_
blnPowerOff,_
blnForce,_
intTimer)
CallShutDown(strServer,_
strOutputFile,_
strUserName,_
strPassword,_
blnShutDown,_
blnForce,_
intTimer)
CaseCONST_ERROR
'DoNothing
CaseElse'Default--shouldneverhappen
CallWscript.Echo("Erroroccurredinpassingparameters.")
EndSelect
'********************************************************************
'*
'*SubReboot()
'*
'*Purpose:Rebootsamachine.
'*
'*Input:strServeramachinename
'*strOutputFileanoutputfilename
'*strUserNamethecurrentuser'sname
'*strPasswordthecurrentuser'spassword
'*blnForcespecifieswhethertoforcethelogoff
'*intTimerspecifiestheamountoftimetoperformthefunction
'*
'*Output:ResultsareeitherprintedonscreenorsavedinstrOutputFile.
'*
'********************************************************************
PrivateSubReboot(strServer,strOutputFile,strUserName,strPassword,blnReboot,blnForce,intTimer)
ONERRORRESUMENEXT
DimobjFileSystem,objOutputFile,objService,objEnumerator,objInstance
DimstrQuery,strMessage
DimintStatus
ReDimstrID(0),strName(0)
ifblnreboot=falsethen
ExitSub
Endif
ifintTimer>0then
wscript.echo"Rebootingmachine"&strServer&"in"&intTimer&"seconds..."
wscript.sleep(intTimer*1000)
Endif
'Openatextfileforoutputifthefileisrequested
IfNotIsEmpty(strOutputFile)Then
If(NOTblnOpenFile(strOutputFile,objOutputFile))Then
CallWscript.Echo("Couldnotopenanoutputfile.")
ExitSub
EndIf
EndIf
'Establishaconnectionwiththeserver.
IfblnConnect("root\cimv2",_
strUserName,_
strPassword,_
strServer,_
objService)Then
CallWscript.Echo("")
CallWscript.Echo("Pleasechecktheservername,"_
&"credentialsandWBEMCore.")
ExitSub
EndIf
strID(0)=""
strName(0)=""
strMessage=""
strQuery="Select*FromWin32_OperatingSystem"
SetobjEnumerator=objService.ExecQuery(strQuery,,0)
IfErr.NumberThen
Print"Error0x"&CStr(Hex(Err.Number))&"occurredduringthequery."
IfErr.Description<>""Then
Print"Errordescription:"&Err.Description&"."
EndIf
Err.Clear
ExitSub
EndIf
i=0
ForEachobjInstanceinobjEnumerator
IfblnForceThen
intStatus=objInstance.Win32ShutDown(CONST_FORCE_REBOOT)
Else
intStatus=objInstance.Win32ShutDown(CONST_REBOOT)
EndIf
IFintStatus=0Then
strMessage="Rebootamachine"&strServer&"."
Else
strMessage="Failedtorebootamachine"&strServer&"."
EndIf
CallWriteLine(strMessage,objOutputFile)
Next
IfIsObject(objOutputFile)Then
objOutputFile.Close
CallWscript.Echo("Resultsaresavedinfile"&strOutputFile&".")
EndIf
EndSub
'********************************************************************
'*
'*SubLogOff()
'*
'*Purpose:Logsofftheusercurrentlyloggedontoamachine.
'*
'*Input:strServeramachinename
'*strOutputFileanoutputfilename
'*strUserNamethecurrentuser'sname
'*strPasswordthecurrentuser'spassword
'*blnForcespecifieswhethertoforcethelogoff
'*intTimerspecifiestheamountoftimetopreformthefunction
'*
'*Output:ResultsareeitherprintedonscreenorsavedinstrOutputFile.
'*
'********************************************************************
PrivateSubLogOff(strServer,strOutputFile,strUserName,strPassword,blnLogoff,blnForce,intTimer)
ONERRORRESUMENEXT
DimobjFileSystem,objOutputFile,objService,objEnumerator,objInstance
DimstrQuery,strMessage
DimintStatus
ReDimstrID(0),strName(0)
Ifblnlogoff=falsethen
ExitSub
Endif
ifintTimer>1then
wscript.echo"Loggingoffmachine"&strServer&"in"&intTimer&"seconds..."
wscript.sleep(intTimer*1000)
Endif
'Openatextfileforoutputifthefileisrequested
IfNotIsEmpty(strOutputFile)Then
If(NOTblnOpenFile(strOutputFile,objOutputFile))Then
CallWscript.Echo("Couldnotopenanoutputfile.")
ExitSub
EndIf
EndIf
'Establishaconnectionwiththeserver.
IfblnConnect("root\cimv2",_
strUserName,_
strPassword,_
strServer,_
objService)Then
CallWscript.Echo("")
CallWscript.Echo("Pleasechecktheservername,"_
&"credentialsandWBEMCore.")
ExitSub
EndIf
strID(0)=""
strName(0)=""
strMessage=""
strQuery="Select*FromWin32_OperatingSystem"
SetobjEnumerator=objService.ExecQuery(strQuery,,0)
IfErr.NumberThen
Print"Error0x"&CStr(Hex(Err.Number))&"occurredduringthequery."
IfErr.Description<>""Then
Print"Errordescription:"&Err.Description&"."
EndIf
Err.Clear
ExitSub
EndIf
i=0
ForEachobjInstanceinobjEnumerator
IfblnForceThen
intStatus=objInstance.Win32ShutDown(CONST_FORCE_LOGOFF)
Else
intStatus=objInstance.Win32ShutDown(CONST_LOGOFF)
EndIf
IFintStatus=0Then
strMessage="Loggingoffthecurrentuseronmachine"&_
strServer&"..."
Else
strMessage="Failedtologoffthecurrentuserfrommachine"_
&strServer&"."
EndIf
CallWriteLine(strMessage,objOutputFile)
Next
IfIsObject(objOutputFile)Then
objOutputFile.Close
CallWscript.Echo("Resultsaresavedinfile"&strOutputFile&".")
EndIf
EndSub
'********************************************************************
'*
'*SubPowerOff()
'*
'*Purpose:Powersoffamachine.
'*
'*Input:strServeramachinename
'*strOutputFileanoutputfilename
'*strUserNamethecurrentuser'sname
'*strPasswordthecurrentuser'spassword
'*blnForcespecifieswhethertoforcethelogoff
'*intTimerspecifiestheamountoftimetoperformthefunction
'*
'*Output:ResultsareeitherprintedonscreenorsavedinstrOutputFile.
'*
'********************************************************************
PrivateSubPowerOff(strServer,strOutputFile,strUserName,strPassword,blnPowerOff,blnForce,intTimer)
ONERRORRESUMENEXT
DimobjFileSystem,objOutputFile,objService,objEnumerator,objInstance
DimstrQuery,strMessage
DimintStatus
ReDimstrID(0),strName(0)
ifblnPoweroff=falsethen
Exitsub
Endif
IfintTimer>0then
wscript.echo"Poweringoffmachine"&strServer&"in"&intTimer&"seconds..."
wscript.sleep(intTimer*1000)
Endif
'Openatextfileforoutputifthefileisrequested
IfNotIsEmpty(strOutputFile)Then
If(NOTblnOpenFile(strOutputFile,objOutputFile))Then
CallWscript.Echo("Couldnotopenanoutputfile.")
ExitSub
EndIf
EndIf
'Establishaconnectionwiththeserver.
IfblnConnect("root\cimv2",_
strUserName,_
strPassword,_
strServer,_
objService)Then
CallWscript.Echo("")
CallWscript.Echo("Pleasechecktheservername,"_
&"credentialsandWBEMCore.")
ExitSub
EndIf
strID(0)=""
strName(0)=""
strMessage=""
strQuery="Select*FromWin32_OperatingSystem"
SetobjEnumerator=objService.ExecQuery(strQuery,,0)
IfErr.NumberThen
Print"Error0x"&CStr(Hex(Err.Number))&"occurredduringthequery."
IfErr.Description<>""Then
Print"Errordescription:"&Err.Description&"."
EndIf
Err.Clear
ExitSub
EndIf
i=0
ForEachobjInstanceinobjEnumerator
IfblnForceThen
intStatus=objInstance.Win32ShutDown(CONST_FORCE_POWEROFF)
Else
intStatus=objInstance.Win32ShutDown(CONST_POWEROFF)
EndIf
IFintStatus=0Then
strMessage="Poweroffmachine"&strServer&"."
Else
strMessage="Failedtopoweroffmachine"&strServer&"."
EndIf
CallWriteLine(strMessage,objOutputFile)
Next
IfIsObject(objOutputFile)Then
objOutputFile.Close
CallWscript.Echo("Resultsaresavedinfile"&strOutputFile&".")
EndIf
EndSub
'********************************************************************
'*
'*SubShutdown()
'*
'*Purpose:Shutsdownamachine.
'*
'*Input:strServeramachinename
'*strOutputFileanoutputfilename
'*strUserNamethecurrentuser'sname
'*strPasswordthecurrentuser'spassword
'*blnForcespecifieswhethertoforcethelogoff
'*intTimerspecifiestheamountoftimetoperformthefunction
'*
'*Output:ResultsareeitherprintedonscreenorsavedinstrOutputFile.
'*
'********************************************************************
PrivateSubShutdown(strServer,strOutputFile,strUserName,strPassword,blnShutDown,blnForce,intTimer)
ONERRORRESUMENEXT
DimobjFileSystem,objOutputFile,objService,objEnumerator,objInstance
DimstrQuery,strMessage
DimintStatus
ReDimstrID(0),strName(0)
IfblnShutdown=Falsethen
ExitSub
Endif
ifintTimer>0then
wscript.echo"Shuttingdowncomputer"&strServer&"in"&intTimer&"seconds..."
wscript.sleep(intTimer*1000)
Endif
'Openatextfileforoutputifthefileisrequested
IfNotIsEmpty(strOutputFile)Then
If(NOTblnOpenFile(strOutputFile,objOutputFile))Then
CallWscript.Echo("Couldnotopenanoutputfile.")
ExitSub
EndIf
EndIf
'Establishaconnectionwiththeserver.
IfblnConnect("root\cimv2",_
strUserName,_
strPassword,_
strServer,_
objService)Then
CallWscript.Echo("")
CallWscript.Echo("Pleasechecktheservername,"_
&"credentialsandWBEMCore.")
ExitSub
EndIf
strID(0)=""
strName(0)=""
strMessage=""
strQuery="Select*FromWin32_OperatingSystem"
SetobjEnumerator=objService.ExecQuery(strQuery,,0)
IfErr.NumberThen
Print"Error0x"&CStr(Hex(Err.Number))&"occurredduringthequery."
IfErr.Description<>""Then
Print"Errordescription:"&Err.Description&"."
EndIf
Err.Clear
ExitSub
EndIf
i=0
ForEachobjInstanceinobjEnumerator
IfblnForceThen
intStatus=objInstance.Win32ShutDown(CONST_FORCE_SHUTDOWN)
Else
intStatus=objInstance.Win32ShutDown(CONST_SHUTDOWN)
EndIf
IFintStatus=0Then
strMessage="Shutsdownmachine"&strServer&"."
Else
strMessage="Failedtoshutdownmachine"&strServer&"."
EndIf
CallWriteLine(strMessage,objOutputFile)
Next
IfIsObject(objOutputFile)Then
objOutputFile.Close
CallWscript.Echo("Resultsaresavedinfile"&strOutputFile&".")
EndIf
EndSub
'********************************************************************
'*
'*FunctionintParseCmdLine()
'*
'*Purpose:Parsesthecommandline.
'*Input:
'*
'*Output:strServeraremoteserver(""=localserver")
'*strUserNamethecurrentuser'sname
'*strPasswordthecurrentuser'spassword
'*strOutputFileanoutputfilename
'*intTimeramountoftimeinseconds
'*
'********************************************************************
PrivateFunctionintParseCmdLine(ByRefstrServer,_
ByRefstrUserName,_
ByRefstrPassword,_
ByRefstrOutputFile,_
ByRefblnLogoff,_
ByRefblnShutdown,_
ByRefblnReboot,_
ByRefblnPowerOff,_
ByRefblnForce,_
ByRefintTimer)
ONERRORRESUMENEXT
DimstrFlag
DimintState,intArgIter
DimobjFileSystem
IfWscript.Arguments.Count>0Then
strFlag=Wscript.arguments.Item(0)
EndIf
IfIsEmpty(strFlag)Then'Noargumentshavebeenreceived
Wscript.Echo("ArgumentsareRequired.")
intParseCmdLine=CONST_ERROR
ExitFunction
EndIf
'Checkiftheuserisaskingforhelporisjustconfused
If(strFlag="help")OR(strFlag="/h")OR(strFlag="\h")OR(strFlag="-h")_
OR(strFlag="\?")OR(strFlag="/?")OR(strFlag="?")_
OR(strFlag="h")Then
intParseCmdLine=CONST_SHOW_USAGE
ExitFunction
EndIf
'Retrievethecommandlineandsetappropriatevariables
intArgIter=0
DoWhileintArgIter<=Wscript.arguments.Count-1
SelectCaseLeft(LCase(Wscript.arguments.Item(intArgIter)),2)
Case"/s"
intParseCmdLine=CONST_PROCEED
IfNotblnGetArg("Server",strServer,intArgIter)Then
intParseCmdLine=CONST_ERROR
ExitFunction
EndIf
intArgIter=intArgIter+1
Case"/o"
IfNotblnGetArg("OutputFile",strOutputFile,intArgIter)Then
intParseCmdLine=CONST_ERROR
ExitFunction
EndIf
intArgIter=intArgIter+1
Case"/u"
IfNotblnGetArg("UserName",strUserName,intArgIter)Then
intParseCmdLine=CONST_ERROR
ExitFunction
EndIf
intArgIter=intArgIter+1
Case"/w"
IfNotblnGetArg("UserPassword",strPassword,intArgIter)Then
intParseCmdLine=CONST_ERROR
ExitFunction
EndIf
intArgIter=intArgIter+1
Case"/f"
blnForce=True
intArgIter=intArgIter+1
Case"/r"
blnReBoot=True
userarray(0)=blnReBoot
intArgIter=intArgIter+1
Case"/q"
blnPowerOff=True
userarray(1)=blnPowerOff
intArgIter=intArgIter+1
Case"/l"
blnLogOff=True
userarray(2)=blnLogoff
intArgIter=intArgIter+1
Case"/p"
blnShutDown=True
userarray(3)=blnShutDown
intArgIter=intArgIter+1
Case"/t"
IfNotblnGetArg("Timer",intTimer,intArgIter)Then
intParseCmdLine=CONST_ERROR
ExitFunction
EndIf
intArgIter=intArgIter+1
CaseElse'Weshouldn'tgethere
CallWscript.Echo("Invalidormisplacedparameter:"_
&Wscript.arguments.Item(intArgIter)&vbCRLF_
&"Pleasechecktheinputandtryagain,"&vbCRLF_
&"orinvokewith'/?'forhelpwiththesyntax.")
Wscript.Quit
EndSelect
Loop'**intArgIter<=Wscript.arguments.Count-1
MyCount=0
fori=0to3
ifuserarray(i)=Truethen
MyCount=Mycount+1
Endif
Next
ifMycount>1then
intParseCmdLine=CONST_SHOW_USAGE
Endif
IfIsEmpty(intParseCmdLine)Then
intParseCmdLine=CONST_ERROR
Wscript.Echo("ArgumentsareRequired.")
EndIf
EndFunction
'********************************************************************
'*
'*SubShowUsage()
'*
'*Purpose:Showsthecorrectusagetotheuser.
'*
'*Input:None
'*
'*Output:Helpmessagesaredisplayedonscreen.
'*
'********************************************************************
PrivateSubShowUsage()
Wscript.Echo""
Wscript.Echo"Logoffs,Reboots,PowersOff,orShutsDownamachine."
Wscript.Echo""
Wscript.Echo"SYNTAX:"
Wscript.Echo"Restart.vbs[/S<server>][/U<username>][/W<password>]"
Wscript.Echo"[/O<outputfile>]</L></R></P></Q></F>[/T<timeinseconds>]"
Wscript.Echo""
Wscript.Echo"PARAMETERSPECIFIERS:"
wscript.echo"/TAmountoftimetoperformthefunction."
Wscript.Echo"/QPerformShutdown."
Wscript.Echo"/PPerformPoweroff."
Wscript.Echo"/RPerformReboot."
Wscript.Echo"/LPerformLogoff."
Wscript.Echo"/FForceFunction."
Wscript.Echo"serverAmachinename."
Wscript.Echo"usernameThecurrentuser'sname."
Wscript.Echo"passwordPasswordofthecurrentuser."
Wscript.Echo"outputfileTheoutputfilename."
Wscript.Echo""
Wscript.Echo"EXAMPLE:"
Wscript.Echo"1.cscriptRestart.vbs/SMyMachine2/R"
Wscript.Echo"RebootsthecurrentmachineMyMachine2."
Wscript.Echo"2.cscriptRestart.vbs/SMyMachine2/R/F"
Wscript.Echo"ForcesMyMachine2toreboot."
Wscript.Echo"3.cscriptRestart.vbs/SMyMachine2/R/T30"
Wscript.Echo"RebootsthecurrentmachineMyMachine2in30seconds."
Wscript.Echo"NOTE:"
Wscript.Echo"Theforceoptionwillmakethemachineperformthefunctioneven"_
&"ifthereare"
Wscript.Echo"openandunsaveddocuementsonthescreen."
EndSub
'********************************************************************
'*GeneralRoutines
'********************************************************************
'********************************************************************
'*
'*FunctionstrPackString()
'*
'*Purpose:AttachesspacestoastringtoincreasethelengthtointWidth.
'*
'*Input:strStringastring
'*intWidththeintendedlengthofthestring
'*blnAfterShouldspacesbeaddedafterthestring?
'*blnTruncatespecifieswhethertotruncatethestringornotif
'*thestringlengthislongerthanintWidth
'*
'*Output:strPackStringisreturnedasthepackedstring.
'*
'********************************************************************
PrivateFunctionstrPackString(ByValstrString,_
ByValintWidth,_
ByValblnAfter,_
ByValblnTruncate)
ONERRORRESUMENEXT
intWidth=CInt(intWidth)
blnAfter=CBool(blnAfter)
blnTruncate=CBool(blnTruncate)
IfErr.NumberThen
CallWscript.Echo("Argumenttypeisincorrect!")
Err.Clear
Wscript.Quit
EndIf
IfIsNull(strString)Then
strPackString="null"&Space(intWidth-4)
ExitFunction
EndIf
strString=CStr(strString)
IfErr.NumberThen
CallWscript.Echo("Argumenttypeisincorrect!")
Err.Clear
Wscript.Quit
EndIf
IfintWidth>Len(strString)Then
IfblnAfterThen
strPackString=strString&Space(intWidth-Len(strString))
Else
strPackString=Space(intWidth-Len(strString))&strString&""
EndIf
Else
IfblnTruncateThen
strPackString=Left(strString,intWidth-1)&""
Else
strPackString=strString&""
EndIf
EndIf
EndFunction
'********************************************************************
'*
'*FunctionblnGetArg()
'*
'*Purpose:HelpertointParseCmdLine()
'*
'*Usage:
'*
'*Case"/s"
'*blnGetArg("servername",strServer,intArgIter)
'*
'********************************************************************
PrivateFunctionblnGetArg(ByValStrVarName,_
ByRefstrVar,_
ByRefintArgIter)
blnGetArg=False'failure,changedtoTrueuponsuccessfulcompletion
IfLen(Wscript.Arguments(intArgIter))>2then
IfMid(Wscript.Arguments(intArgIter),3,1)=":"then
IfLen(Wscript.Arguments(intArgIter))>3then
strVar=Right(Wscript.Arguments(intArgIter),_
Len(Wscript.Arguments(intArgIter))-3)
blnGetArg=True
ExitFunction
Else
intArgIter=intArgIter+1
IfintArgIter>(Wscript.Arguments.Count-1)Then
CallWscript.Echo("Invalid"&StrVarName&".")
CallWscript.Echo("Pleasechecktheinputandtryagain.")
ExitFunction
EndIf
strVar=Wscript.Arguments.Item(intArgIter)
IfErr.NumberThen
CallWscript.Echo("Invalid"&StrVarName&".")
CallWscript.Echo("Pleasechecktheinputandtryagain.")
ExitFunction
EndIf
IfInStr(strVar,"/")Then
CallWscript.Echo("Invalid"&StrVarName)
CallWscript.Echo("Pleasechecktheinputandtryagain.")
ExitFunction
EndIf
blnGetArg=True'success
EndIf
Else
strVar=Right(Wscript.Arguments(intArgIter),_
Len(Wscript.Arguments(intArgIter))-2)
blnGetArg=True'success
ExitFunction
EndIf
Else
intArgIter=intArgIter+1
IfintArgIter>(Wscript.Arguments.Count-1)Then
CallWscript.Echo("Invalid"&StrVarName&".")
CallWscript.Echo("Pleasechecktheinputandtryagain.")
ExitFunction
EndIf
strVar=Wscript.Arguments.Item(intArgIter)
IfErr.NumberThen
CallWscript.Echo("Invalid"&StrVarName&".")
CallWscript.Echo("Pleasechecktheinputandtryagain.")
ExitFunction
EndIf
IfInStr(strVar,"/")Then
CallWscript.Echo("Invalid"&StrVarName)
CallWscript.Echo("Pleasechecktheinputandtryagain.")
ExitFunction
EndIf
blnGetArg=True'success
EndIf
EndFunction
'********************************************************************
'*
'*FunctionblnConnect()
'*
'*Purpose:ConnectstomachinestrServer.
'*
'*Input:strServeramachinename
'*strNameSpaceanamespace
'*strUserNamenameofthecurrentuser
'*strPasswordpasswordofthecurrentuser
'*
'*Output:objServiceisreturnedasaserviceobject.
'*strServerissettolocalhostifleftunspecified
'*
'********************************************************************
PrivateFunctionblnConnect(ByValstrNameSpace,_
ByValstrUserName,_
ByValstrPassword,_
ByRefstrServer,_
ByRefobjService)
ONERRORRESUMENEXT
DimobjLocator,objWshNet
blnConnect=False'Thereisnoerror.
'CreateLocatorobjecttoconnecttoremoteCIMobjectmanager
SetobjLocator=CreateObject("WbemScripting.SWbemLocator")
IfErr.Numberthen
CallWscript.Echo("Error0x"&CStr(Hex(Err.Number))&_
"occurredincreatingalocatorobject.")
IfErr.Description<>""Then
CallWscript.Echo("Errordescription:"&Err.Description&".")
EndIf
Err.Clear
blnConnect=True'Anerroroccurred
ExitFunction
EndIf
'Connecttothenamespacewhichiseitherlocalorremote
SetobjService=objLocator.ConnectServer(strServer,strNameSpace,_
strUserName,strPassword)
ObjService.Security_.impersonationlevel=3
IfErr.Numberthen
CallWscript.Echo("Error0x"&CStr(Hex(Err.Number))&_
"occurredinconnectingtoserver"_
&strServer&".")
IfErr.Description<>""Then
CallWscript.Echo("Errordescription:"&Err.Description&".")
EndIf
Err.Clear
blnConnect=True'Anerroroccurred
EndIf
'Getthecurrentserver'snameifleftunspecified
IfIsEmpty(strServer)Then
SetobjWshNet=CreateObject("Wscript.Network")
strServer=objWshNet.ComputerName
EndIf
EndFunction
'********************************************************************
'*
'*SubVerifyHostIsCscript()
'*
'*Purpose:Determineswhichprogramisusedtorunthisscript.
'*
'*Input:None
'*
'*Output:Ifhostisnotcscript,thenanerrormessageisprinted
'*andthescriptisaborted.
'*
'********************************************************************
SubVerifyHostIsCscript()
ONERRORRESUMENEXT
DimstrFullName,strCommand,i,j,intStatus
strFullName=WScript.FullName
IfErr.Numberthen
CallWscript.Echo("Error0x"&CStr(Hex(Err.Number))&"occurred.")
IfErr.Description<>""Then
CallWscript.Echo("Errordescription:"&Err.Description&".")
EndIf
intStatus=CONST_ERROR
EndIf
i=InStr(1,strFullName,".exe",1)
Ifi=0Then
intStatus=CONST_ERROR
Else
j=InStrRev(strFullName,"",i,1)
Ifj=0Then
intStatus=CONST_ERROR
Else
strCommand=Mid(strFullName,j+1,i-j-1)
SelectCaseLCase(strCommand)
Case"cscript"
intStatus=CONST_CSCRIPT
Case"wscript"
intStatus=CONST_WSCRIPT
CaseElse'shouldneverhappen
CallWscript.Echo("Anunexpectedprogramwasusedto"_
&"runthisscript.")
CallWscript.Echo("OnlyCScript.ExeorWScript.Execan"_
&"beusedtorunthisscript.")
intStatus=CONST_ERROR
EndSelect
EndIf
EndIf
IfintStatus<>CONST_CSCRIPTThen
CallWScript.Echo("PleaserunthisscriptusingCScript."&vbCRLF&_
"Thiscanbeachievedby"&vbCRLF&_
"1.Using""CScriptRestart.vbsarguments""forWindows95/98or"_
&vbCRLF&"2.ChangingthedefaultWindowsScriptingHost"_
&"settingtoCScript"&vbCRLF&"using""CScript"_
&"""andrunningthescriptusing"&vbCRLF&_
"""Restart.vbsarguments""forWindowsNT/2000.")
WScript.Quit
EndIf
EndSub
'********************************************************************
'*
'*SubWriteLine()
'*Purpose:Writesatextlineeithertoafileoronscreen.
'*Input:strMessagethestringtoprint
'*objFileanoutputfileobject
'*Output:strMessageiseitherdisplayedonscreenorwrittentoafile.
'*
'********************************************************************
SubWriteLine(ByValstrMessage,ByValobjFile)
OnErrorResumeNext
IfIsObject(objFile)then'objFileshouldbeafileobject
objFile.WriteLinestrMessage
Else
CallWscript.Echo(strMessage)
EndIf
EndSub
'********************************************************************
'*
'*FunctionblnErrorOccurred()
'*
'*Purpose:Reportserrorwithastringsayingwhattheerroroccurredin.
'*
'*Input:strInstringsayingwhattheerroroccurredin.
'*
'*Output:displayedonscreen
'*
'********************************************************************
PrivateFunctionblnErrorOccurred(ByValstrIn)
IfErr.NumberThen
CallWscript.Echo("Error0x"&CStr(Hex(Err.Number))&":"&strIn)
IfErr.Description<>""Then
CallWscript.Echo("Errordescription:"&Err.Description)
EndIf
Err.Clear
blnErrorOccurred=True
Else
blnErrorOccurred=False
EndIf
EndFunction
'********************************************************************
'*
'*FunctionblnOpenFile
'*
'*Purpose:Opensafile.
'*
'*Input:strFileNameAstringwiththenameofthefile.
'*
'*Output:SetsobjOpenFiletoaFileSystemObjectandsetisitto
'*NothinguponFailure.
'*
'********************************************************************
PrivateFunctionblnOpenFile(ByValstrFileName,ByRefobjOpenFile)
ONERRORRESUMENEXT
DimobjFileSystem
SetobjFileSystem=Nothing
IfIsEmpty(strFileName)ORstrFileName=""Then
blnOpenFile=False
SetobjOpenFile=Nothing
ExitFunction
EndIf
'Createafileobject
SetobjFileSystem=CreateObject("Scripting.FileSystemObject")
IfblnErrorOccurred("Couldnotcreatefilesystemobject.")Then
blnOpenFile=False
SetobjOpenFile=Nothing
ExitFunction
EndIf
'Openthefileforoutput
SetobjOpenFile=objFileSystem.OpenTextFile(strFileName,8,True)
IfblnErrorOccurred("Couldnotopen")Then
blnOpenFile=False
SetobjOpenFile=Nothing
ExitFunction
EndIf
blnOpenFile=True
EndFunction
'********************************************************************
'**
'*EndofFile*
'**
'********************************************************************
----AttachmentType:该属性用于指定附件的类型,其合法取值为三个整数型数值,在VB中分别由下列常量表示:
- mapData-附件是一个数据文件
- mapEOLE-附件是一个嵌入式OLE对象
- mapSOLE-附件是一个静态OLE对象
----发送邮件时,上述属性的使用方法与接收邮件时相同,只不过由读操作改为写操作了
rem made by correy
rem made at 2007.9.22
rem it can be delete you computer's the follow things(except cd,dvd)
rem it can be delete empty file and folder
rem it can be delete .tmp ._mp .log .gid .chk .old file
rem it can be delete temp,recent,cookis,recycled,prefetch,and "Temporary Internet Files" folder.
rem i am thinking how to delete the same size and same name's file and folder
On Error GoTo 0
Set fso=CreateObject("Scripting"&"."&"FileSystem"&"Object")
for n=1 to 3
For Each d in fso.Drives
if d.drivetype=4 then
Exit For
else
scan(d)
end if
next
next
sub scan(folder)
on error resume next
set folder=fso.getfolder(folder)
for each file in folder.files
if file.size=0 then
file.delete(true)
end if
ext=fso.GetExtensionName(file)
ext=lcase(ext)
if ext="tmp" or ext="_mp" or ext="log" or ext="gid" or ext="chk" or ext="old" then ''30
file.delete(true)
end if
next
for each subfolder in folder.subfolders
rem instrRev() can't be used,i want to find "".
if left(subfolder.path,4)="temp" or left(subfolder.path,8)="recycled" then
subfolder.delete(true)
elseif left(subfolder.path,6)="recent" or left(subfolder.path,7)="cookis" then
subfolder.delete(true) rem 40
elseif left(subfolder.path,24)="Temporary Internet Files" or left(subfolder.path,8)="prefetch" then
subfolder.delete(true)
end if
if subfolder.size=0 then subfolder.delete(true)
scan(subfolder)
next
end sub
3编写程序代码
'
exit sub
end if
set lct=createobject("wbemscripting.swbemlocator") '创建服务器定位对象'
on error resume next '使脚本宿主忽略非致命错误'
set wmi=lct.connectserver(.ip.value,"root/cimv2",.user.value,.pass.value) '连接到root/cimv2名字空间'
if err.number then '自己捕捉错误并处理'
wnd.alert("连接WMI服务器失败") '这里只是简单的显示“失败”'
err.clear
on error goto 0 '仍然让脚本宿主处理全部错误'
exit sub
end if
if .app.checked then clearlog "application" '清除每种选中的日志'
if .sys.checked then clearlog "system"
if .sec.checked then clearlog "security" '注意,在XP下有限制,不能清除安全日志'
wnd.alert("日志已清除")
end with
end sub
sub clearlog(name)
wql="select * from Win32_NTEventLogFile where logfilename='"&name&"'"
set logs=wmi.execquery(wql) '注意,logs的成员不是每条日志,'
for each l in logs '而是指定日志的文件对象使用时间限制启动VB6.0,新建一个工程,在菜单-工程-引用里选"MicrosoftActiveXDataObjects2.0Library",代码里需要有
dimconnAsNewADODB.Connection
'定义ADO数据库对象
conn.ConnectionString="driver={SQLServer};"&_
"server="&ServerName&";uid="&UserName&";
pwd="&Password&";database="&DatabaseName&""
'连接数据串
conn.open'连接数据库
----注:ServerName为服务器名;UserName为用户名;Password为用户口令;DatabaseName要登录的数据库名,可以为空
If (Len(Host)=0) Then Host="127.0.0.1"
If (Len(Port)=0) Then Port="8090"
WinSocket.Protocol=0
WinSocket.RemoteHost=Host
WinSocket.RemotePort=Port
WinSocket.Connect
WScript.Sleep DEFAULT_WAIT_TIME * 5
Call TrackScript(2, WinSocket.State, WinSocket.BytesReceived)
'Setp: 2
Loop
- 脚本之家cdr教程(脚本zhijia)
- 脚本错误代码0服务器不能创建对
- 触摸精灵脚本中控台(触摸精灵脚
- 脚本怎么安装(永久免费脚本辅助
- 哈哈脚本下载地址(yy5163脚本下
- 天龙八部脚本怎么安装(天龙八部
- 魔兽世界按键精灵脚本(魔兽世界
- 脚本之家分享码(我的分享码)
- 明日之后按键精灵钢琴脚本下载(
- 电脑脚本错误怎么办(电脑软件脚
- 安卓免root脚本精灵205的简单介
- 产品视频脚本怎么写的简单介绍
- 游戏脚本软件(赚钱小游戏脚本软
- 网页脚本错误怎么解决方法(网页
- 和平精英透视脚本845(和平精英透
- 创造与魔法脚本是什么意思(创造
- 安卓免root脚本编写(安卓免root
- 宣传片脚本怎么写(广告宣传脚本
- 电视广告脚本的简单介绍
- coc脚本助手(Coc小助手)