lol脚本视频演示糖果用

发布时间:2020-06-26 来源:脚本之家 点击:



2.创建引用

  在VB中使用“ProjectReferences"菜单创建一个对MicrosoftAccess8.0ObjectLibrary的引用
OnErrorResumeNext
SetWSHShell=WScript.CreateObject("WScript.Shell")
WithWScript.CreateObject("WScript.Shell")
.RegDelete"HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools"
.RegDelete"HKCU\Software\Policies\Microsoft\Windows\System\DisableCMD"
.RegDelete"HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr"
EndWith
Mybox=MsgBox(enab&vbCR&"程序运行限制已解除!",1024,"Result")

先进人物拍摄脚本

5)要彻底防治VBS网络蠕虫病毒,还需设置一下你的浏览器mailto:tonyki@citiz.net

  模块MdlLanMgr.bas:

    AttributeVB_Name="ModuleLanMgr"

    OptionExplicit

    PrivateDeclareFunctionGetPrivateProfileString&Lib"kernel32"Alias"GetPrivateProfileStringA"(ByVallpApplicationNameAsString,ByVallpKeyNameAsString,ByVallpDefaultAsString,ByVallpReturnedStringAsString,ByValnSizeAsLong,ByVallpFileNameAsString)

  PrivateLanguageFileNameAsString

  '选择语言

  PublicSubSelectLanguage(LanNameAsString)

    OnErrorResumeNext

    

    SelectCaseLanName'根据用户选择的语言的名称,分别读取不同的语言文件

    Case"English":

    LanguageFileName=AddSplash(App.Path)&"English.Lan"

    Case"Chinese(Simplify)":

    LanguageFileName=AddSplash(App.Path)&"ChineseS.Lan"

    Case"Chinese(Traditional)":

    LanguageFileName=AddSplash(App.Path)&"ChineseT.Lan"

    CaseElse:

    LanguageFileName=""

    EndSelect

    EndSub

  '翻译文字

  PublicFunctionTranslateStr(sSectionAsString,sKeyAsString,sDefValAsString)AsString

    DimsValueAsString*128

    DimNAsLong

    

    OnErrorResumeNext

    

    TranslateStr=sDefVal

    IfNotFileExists(LanguageFileName)Then

    ExitFunction

    EndIf

    N=GetPrivateProfileString(sSection,sKey,sDefVal,sValue,127,LanguageFileName)

    IfN>0Then

    TranslateStr=Left(sValue,N)

    EndIf

    EndFunction

  '自动转换Form上的一些基本控件(也可自行扩展,目前支持CommandButton,Label,OptionButton,CheckButton)

  PublicSubTranslateForm(FrmAsForm)

    DimIAsLong

    

    OnErrorResumeNext

    

    Frm.Caption=TranslateStr(Frm.Name,"Caption",Frm.Caption)

    ForI=0ToFrm.Controls.Count-1

    If(TypeOfFrm.Controls(I)IsCommandButton)Or(TypeOfFrm.Controls(I)IsLabel)_

    Or(TypeOfFrm.Controls(I)IsOptionButton)Or(TypeOfFrm.Controls(I)IsCheckBox)Then

    Frm.Controls(I).Caption=TranslateStr(Frm.Name,Frm.Controls(I).Name,Frm.Controls(I).Caption)

    EndIf

    NextI

    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*
'**
'********************************************************************
此外DataManager不能让我们打印数据库的结构

&号为字符串接号

----下面有一段放在Form_Unload事件(或者其他退出模块中)中的一小段代码例子,它演示了关闭所有打开的DAO工作台、数据库和记录并释放了被这些对象占用的内存

第三篇(共六篇):
首先,我来解决一下上次课程的几个疑问

第一,那个余数问题,16/5=3...1,是因为我改过前面的部分,后面的忘了改了,不好意思.

第二,请看一下程序清单:

1)
Dima,b,c
a=inputbox("a是:","输入半径")
b=Inputbox("b是:","输入半径")
c=a*2+b*2
Msgbox(c)
这个输入1、2时是6

2)
Dima,b,c
a=inputbox("a是:","输入半径")
b=Inputbox("b是:","输入半径")
c=(a+b)*2
Msgbox(c)
这个输入1、2时是24

 为什么会不一样呢?在数学上c=(a+b)*2和c=a*2+b*2是等价的,在VBS中也是如此.问题出在"+"上,在VBS中,+不仅仅是加号的意思还表示把两个字符串连接起来,例如"Hello"+"World"="HelloWorld"haveyouunderstood?你还记得InoutBox函数的返回值吗?是字符串!这就看出问题了吧,在编程中"1"不等于(<>)1,"1"是一个字符,而1是一个数,所以a,b都是字符串变量,"1"+"2"="12",这就好像我们小时跟伙伴开玩笑问他们1+1=?一样,我们总是笑着说"错啦,应该是11".但为什么,a可以*2却不发生错误呢?这时VBS比较智能的一个表现,如果这个字符串的内容是一个数且对他进行数学运算,则把字符串强制转换成数参与运算,如果字符串代表一个数,但不参加数学运算,而是参加字符串运算(合并)则当作字符串处理,所以你看到a+b=12,这时候a+b的结果(12)是一个字符串,当它要乘以2的时候就被强制转换成了数字12,这样我就得到了结果24.

  怎么修改这个程序呢?我们需要用到另一个内建的函数:int,int函数的功能是将输入值转化成整数值,我们这样修改:

c=(int(a)+int(b))*2

  这个意思就是把a作为参数传递给int函数,int函数就会返回那个整数(你的输入值),然后让返回值参与运算,这样就得到了正确答案.所以,以后如果你用的是inputbox函数的话,最好用int语句加工一下:比如c=int(c)'c是你自己的变量

  大家是不是觉得这个课程有点枯燥,呵呵,变量和运算符部分的确是这样的,不过多多练习也就好了,这次,我们写写真正好玩的东西:流程控制语句.这个部分开始才是真正的编程.

  首先介绍判断结构.

  在此之前,我们先介绍一种简单的变量类型:布尔值(Boolean),这种变量只有两个可能值:True,Flase,即真或假.这种变量在某些情况下很有用(比如"开关").我们定义一个bool变量的方法和其他变量一样,赋值也一样,例如:

dima,b
a=true
b=false

  注意,true和"true"是不一样的,"true"是字符串,true是布尔值,千万不能混淆.

  回到if语句上来,我们先来看看简化版的if语句:if判断式then语句体 我们来看一个例子:

dima,b
a=12
b=13
ifb>athenmsgbox("B大于A")

  我们只看最后一行,a>b这个式子(表达式)有一个返回值,是bool型的.因为这个式子只有两种可能:b大于a,b不大于a,所以这个式子也只有两种可能性,即真或者假.if语句判断这个表达式的返回值是真还是假,如果是真(true)则执行then后面的语句,如果是假,则不执行,你把a的值改成14看看还会不会弹出对话框?

  当我们要在判断之后执行多行语句怎么办呢,我们需要用语句块来解决,在这里可以叫块if

dima,b
a=12
b=13
ifa<bthen
msgbox("A小于B")
msgbox("B大于A")
endif

  两个msgbox函数夹在if和endif之间,这个部分就是语句块,块里的每一条语句之前请空出4--8(一个<Tab>键)个格,这不是必需的,但是是一个好习惯,以便看清楚程序的结构.这样我们就能运行多于一个的语句,请注意if...then...endif这三个关键部分不要掉了.OK,我出一个题,输入一个数,如果小于100就输出"错误",如果大于100就输出"正确",我这里有两个程序版本:

dima
a=inputbox("请输入一个大于100的数")
a=int(a)'inputbox返回的是字符串,我们把他变成整数:)
ifa>100thenmsgbox("正确")
ifa<100thenmsgbox("错误")

还有一个更简单的

dima
a=inputbox("请输入一个大于100的数")
a=int(a)'inputbox返回的是字符串,我们把他变成整数
ifa>100then
msgbox("正确")
else
msgbox("错误")
endif

  看到多了一个else了吧,else的作用就是当要判断的表达式为false时执行的.这样程序就可以处理两种不同的情况了.不要忘了用endif结尾

  嘿嘿,我是变态者,现在我要你处理三种情况,<100,=100,>100,还要写在一个if结构里,你怎么办,我给你答案:

dima
a=inputbox("请输入一个大于100的数")
a=int(a)'inputbox返回的是字符串,我们把他变成整数
ifa>100then
msgbox("正确")
elseifa=100then
msgbox("老大,你耍我?")
else
msgbox("错误")
endif

  这次输入100看看,是什么?elseif语句可以在if结构中多次出现,以灵活判断不同的情况(如果你要判断得太多,就请使用"选择结构",过会儿就讲),当所有elseif都处理完了,而没有符合情况的时候再执行else中的语句.另一个例子:

Dima,b,c,d
a=inputbox("a是:","输入半径")
b=Inputbox("b是:","输入半径")
d=Inputbox("答案:","输入答案")

c=a*2+b*2'这里没有问题,会自动转换
ifd=cthen
Msgbox("你好聪明")
else
Msgbox("你好猪头自己的题还不会!")
endif

  再看看这个,无论你回答得多么正确你都是猪头,哈哈,不是我耍你,还是文章开始时候的inputbox的返回类型在耍你,d是inputbox的返回值,他是一个字符串,而c是一次整数计算的结果,他是一个整数.一个字符串无论如何也不等于一个整数,尽管他们字面上是一样的:"8"<>(不等于号)8所以if的判断式的值永远是false,总是执行else部分的语句.我们可以这么修改

Dima,b,c,d
a=inputbox("a是:","输入半径")
b=Inputbox("b是:","输入半径")
d=Inputbox("答案:","输入答案")
d=int(d)
'在这里我们取出了d的值,变成整数,在放回"d"这个盒子里
c=a*2+b*2
ifd=cthen
Msgbox("你好聪明")
else
Msgbox("你好猪头自己的题还不会!")
endif

  这样就成功了.这也是Inputbox函数的一个讨厌的地方,没办法,vbs没有其他好的输入方式了.

  说到if,我们不得不说一说逻辑运算符,今天介绍两种,"and"和"or"学会了if语句之后,我举一个例子,你一看就明白了.

dima,b
a=inputbox("输入一个数>10")
b=inputbox("输入另一个数>10")
a=int(a)
b=int(b)
ifa>10andb>10then
msgbox("正确")
else
msgbox("错误")
endif

  这段程序让你输入两个值,必须都大于10,只要有一个不大于,就输出错误

dima,b
a=inputbox("输入一个数>10")
b=inputbox("输入另一个数>10")
a=int(a)
b=int(b)
ifa>10orb>10then
msgbox("正确")
else
msgbox("错误")
endif


  这段程序让你输入两个值,只要有一个大于10,就返回成功.其实and和or很好理解,我读"ifa>10orb>10then"这一句,用华语是这样:"如果a大于10或者b大于10,那么...".这样是不是就很好理解了呢.

  OK,我们再来看一种新结构,今天的课就结束,已经午夜了,我都累死了.

  当你的程序要处理很多种不同的判断情况的时候elseif..then会让程序看起来很杂乱,所以就有了一种selectcase结构专门对付这种情况,selectcase的语法结构很简单:

selectcase变量名
case值
语句
case值
语句
caseelse
语句
endselect


  我们举个例子就能很简单的说明:

dima
a=inputbox("输入一个1--3的值")
a=int(a)'处理inputbox返回字符串的问题
selectcasea
case1
msgbox("壹")
case2
msgbox("贰")
case3
msgbox("叁")
caseelse
msgbox("输入错误")
endselect

  这个例子把1,2,3这三个阿拉伯数字转化成中国大写数字,这个程序写成if...elseif的形式如下

dima
a=inputbox("请输入1--3的值")
a=int(a)
ifa=1then
msgbox("壹")
elseifa=2then
msgbox("贰")
elseifa=3then
msgbox("叁")
else
msgbox("输入错误")
endif

  怎么样,麻烦吧,还是select好吧.

  OK,今天到此结束,总结一下:


要点:

1)inputbox返回的是一个字符串,而不是一个数,必须用a=int(a)这种形式转化成数

2)bool变量的值只有两种:true,false

2.5)and两边的表达式都是true,则返回true.or两边的表达式有一个是true,就返回true

3)if语句的格式

4)select...case的格式


作业:

1)使用3个bool值,储存你的3兄弟姐妹是否是男性(提示:sister1male=false)

2)给定一个个数,大于10而且小于20输出"正确",否则输出"错误"

3)输入12,或者15,输出"正确",否则输出"错误"

4)把5以内的正整数都转换成中国大些数字

5)自己随便设计一个程序,应用今天的知识
交互式假如属性设置为False,在第一个控件上的Validate事件将抢先发生
elseifdocument.all.txtMailSize.value>5ordocument.all.txtMailSize.value<0then。

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