VBS实现的系统服务备份优化代码

代码如下:

Option Explicit
'○○○○○○○○○○○○○○○○○○○○○○○○○○○○○开始
Const blnVBSShowCaption=True
'生成的服务备份中是否添加说明
Const blnVBSShowDescription=True
'●●●●●●●●●●●●●●●●●●●●●●●●●●●●●结束
'文件读写标识常量
Const Forwriteing = 8
'读取出来的自动模式类型
Const cstrAutoForRead="Auto"
'用于设定的自动模式类型
Const cstrAutoForWrite="Automatic"
'变更历史状态
Const cstrStateNotFound="Not Found"
Const cstrStateNotSetted="Not Setted"
Const cstrStateNotChanged="Not Changed"
Const cstrStateChanged="Changed"
'服务变更类型
Class clsServiceChange
    '服务名称
    Public Name
    '服务显示名称
    Public Caption
    '服务描述
    Public Description
    '服务初始启动模式
    Public StartModeFrom
    '服务之后启动模式
    Public StartModeTo
    '服务启动变更标识
    Private Sub Class_Initialize()
        Name=""
        Caption=""
        Description=""
        StartModeFrom=""
        StartModeTo=""
    End Sub
    Public Property get State
        If StartModeFrom="" Then
            State="Not Found"
            Exit Property
        End If
        If StartModeTo="" Then
            State="Not Setted"
            Exit Property
        End If
        If StartModeFrom=StartModeTo Then
            State="Not Changed"
        Else
            State="Changed"
        End If
    End Property
End Class
'文件系统
dim objFileSystem
'备份的VBS文件
Dim objVBSFile
'WshShell 对象
dim objWShell
'windows 系统管理模块
Dim objWinManagment
'系统服务集
Dim objServices
'所操作的电脑标识
Dim strComputer
'备份文件路径
Dim strVBSFilePath
'备份文件名
Dim strVBSFileName
'信息
Dim strMessage
'数组索引
Dim intIndex
'Log暂存
Dim astrLog()
'服务变更历史
Dim aobjServiceChange()
Redim aobjServiceChange(0)
Redim astrLog(0)
'添加多条变更原则
'○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○
'自己修改位置(开始)
'○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○
AddRuler "Alerter"    ,"Disabled"
AddRuler "ALG"    ,"Manual"
AddRuler "AppMgmt"    ,"Manual"
AddRuler "aspnet_state"    ,"Disabled"
AddRuler "Ati HotKey Poller"    ,"Disabled"
AddRuler "AudioAddRuler"    ,"Auto"
AddRuler "BITS"    ,"Manual"
AddRuler "Browser"    ,"Disabled"
AddRuler "CiSvc"    ,"Disabled"
AddRuler "ClipSrv"    ,"Disabled"
AddRuler "ClipAddRuler"    ,"Disabled"
AddRuler "COMSysApp"    ,"Disabled"
AddRuler "CryptSvc"    ,"Auto"
AddRuler "DcomLaunch"    ,"Auto"
AddRuler "DF5Serv"    ,"Auto"
AddRuler "Dhcp"    ,"Auto"
AddRuler "dmadmin"    ,"Manual"
AddRuler "dmserver"    ,"Manual"
AddRuler "Dnscache"    ,"Disabled"
AddRuler "ERSvc"    ,"Disabled"
AddRuler "Eventlog"    ,"Auto"
AddRuler "EventSystem"    ,"Auto"
AddRuler "FastUserSwitchingCompatibility"    ,"Disabled"
AddRuler "helpsvc"    ,"Manual"
AddRuler "HidServ"    ,"Disabled"
AddRuler "HTTPFilter"    ,"Manual"
AddRuler "ImapiService"    ,"Disabled"
AddRuler "lanmanserver"    ,"Manual"
AddRuler "lanmanworkstation"    ,"Auto"
AddRuler "LmHosts"    ,"Disabled"
AddRuler "MDM"    ,"Disabled"
AddRuler "Messenger"    ,"Disabled"
AddRuler "mnmAddRulerc"    ,"Manual"
AddRuler "mnmsrvc" , "Disabled"
AddRuler "MSDTC"    ,"Disabled"
AddRuler "MSIServer"    ,"Manual"
AddRuler "NetDDE"    ,"Disabled"
AddRuler "NetDDEdsdm"    ,"Disabled"
AddRuler "Netlogon"    ,"Manual"
AddRuler "Netman"    ,"Auto"
AddRuler "Nla"    ,"Disabled"
AddRuler "NtLmSsp"    ,"Manual"
AddRuler "NtmsSvc"    ,"Disabled"
AddRuler "NVSvc"    ,"Disabled"
AddRuler "O&O Defrag"    ,"Manual"
AddRuler "ose"    ,"Manual"
AddRuler "PlugPlay"    ,"Auto"
AddRuler "PolicyAgent"    ,"Disabled"
AddRuler "ProtectedStorage"    ,"Auto"
AddRuler "RasAuto"    ,"Disabled"
AddRuler "RasMan"    ,"Disabled"
AddRuler "RDSessMgr"    ,"Disabled"
AddRuler "RemoteAccess"    ,"Disabled"
AddRuler "RemoteRegistry"    ,"Disabled"
AddRuler "RpcLocator"    ,"Manual"
AddRuler "RpcSs"    ,"Auto"
AddRuler "RSVP"    ,"Disabled"
AddRuler "SamSs"    ,"Auto"
AddRuler "SCardSvr"    ,"Disabled"
AddRuler "Schedule"    ,"Disabled"
AddRuler "seclogon"    ,"Auto"
AddRuler "SENS"    ,"Disabled"
AddRuler "SharedAccess"    ,"Disabled"
AddRuler "ShellHWDetection"    ,"Manual"
AddRuler "sicentnetsync"    ,"Auto"
AddRuler "Spooler"    ,"Manual"
AddRuler "srservice"    ,"Disabled"
AddRuler "SSDPAddRuler"    ,"Disabled"
AddRuler "SSDPSRV"    ,"Disabled"
AddRuler "stisvc"    ,"Manual"
AddRuler "SwPrv"    ,"Disabled"
AddRuler "SysmonLog"    ,"Manual"
AddRuler "TapiAddRuler"    ,"Manual"
AddRuler "TermService"    ,"Disabled"
AddRuler "Themes"    ,"Auto"
AddRuler "TlntSvr"    ,"Disabled"
AddRuler "TrkWks"    ,"Disabled"
AddRuler "TapiSrv"    ,"Disabled"
AddRuler "UMWdf"    ,"Auto"
AddRuler "upnphost"    ,"Disabled"
AddRuler "UPS"    ,"Disabled"
AddRuler "usnjsvc"    ,"Manual"
AddRuler "VSS"    ,"Disabled"
AddRuler "VMAuthdService"    ,"Manual"
AddRuler "VMnetDHCP"    ,"Manual"
AddRuler "VMware NAT Service"    ,"Manual"
AddRuler "W32Time"    ,"Disabled"
AddRuler "WebClient"    ,"Disabled"
AddRuler "winmgmt"    ,"Auto"
AddRuler "WinVNC4"    ,"Manual"
AddRuler "WmdmPmSN"    ,"Disabled"
AddRuler "Wmi"    ,"Manual"
AddRuler "WmiApAddRuler"    ,"Manual"
AddRuler "wscsvc"    ,"Manual"
AddRuler "wuauserv"    ,"Disabled"
AddRuler "WZCSVC"    ,"Auto"
AddRuler "xmlprov"    ,"Manual"
'●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
'自己修改位置(结束)
'●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
'设定电脑为本机
strComputer = "."
Set objWShell = CreateObject("Wscript.Shell")
'备份至我的文档
strVBSFilePath = objWShell.SpecialFolders("MyDocuments") & "\ServiceBack\"
'以当前时间作为备份文件名
strVBSFileName = "Service" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & "-" & Hour(Time) & "-" & Minute(Time) &".vbs"
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
'备份文件路径存在性验证和添加文件夹
If Not objFileSystem.FolderExists(strVBSFilePath) Then
    objFileSystem.CreateFolder(strVBSFilePath)
End If
'备份文件存在性验证
If objFileSystem.FileExists(strVBSFilePath & strVBSFileName) Then
    '文件存在的情况下
    Msgbox "The File Has been in existence.",16,"Warning!"
Else
    '本机管理模块对象初始化
    Set objWinManagment = GetObject("Winmgmts:\\"& strComputer &"\Root\Cimv2")
    '本机服务集取得
    Set objServices =objWinManagment.ExecQuery("Select * From Win32_Service")
    '文件对象创建
    Set objVBSFile = objFileSystem.CreateTextFile(strVBSFilePath  & strVBSFileName ,ForWriteing)
    objVBSFile.WriteLine vbcrlf
    objVBSFile.WriteLine "'Runable Backup:"
    objVBSFile.WriteLine "'============================="
    objVBSFile.WriteLine "Const cstrAutoForRead=""Auto"""
    objVBSFile.WriteLine "Const cstrAutoForWrite=""Automatic"""
    objVBSFile.WriteLine "intChangeCount=0"
    objVBSFile.WriteLine "intChangeSuccessCount=0"
    objVBSFile.WriteLine "strComputer = ""."""
    objVBSFile.WriteLine "Const Forwriteing = 8"
    objVBSFile.WriteLine "If Msgbox(""Are You Sure You Want To Restore Your Service ?"",VBYesNo+vbInformation,""Restore Service"")=vbYes Then"
    objVBSFile.WriteLine "    Set objWinManagment = GetObject(""Winmgmts:\\""& strComputer &""\Root\Cimv2"")"
    objVBSFile.WriteLine "    Set objServices =objWinManagment.ExecQuery(""Select * From Win32_Service"")"
    strMessage = GOT()
    objVBSFile.WriteLine "    Set objWinManagment = Nothing"
    objVBSFile.WriteLine "    Set objServices =Nothing"
    objVBSFile.WriteLine "End If"
    objVBSFile.WriteLine "Function SRV(SRN,SRM)"
    objVBSFile.WriteLine "    For Each S In objServices"
    objVBSFile.WriteLine "        If s.Name = Srn And S.StartMode<>SRM Then"
    objVBSFile.WriteLine "           intChangeCount=intChangeCount+1 "
    objVBSFile.WriteLine "           If SRM=cstrAutoForRead Then "
    objVBSFile.WriteLine "               strStartModeTemp=cstrAutoForWrite "
    objVBSFile.WriteLine "           Else "
    objVBSFile.WriteLine "               strStartModeTemp=SRM "
    objVBSFile.WriteLine "           End If "
    objVBSFile.WriteLine "           If S.ChangeStartMode(strStartModeTemp)=0 Then "
    objVBSFile.WriteLine "               intChangeSuccessCount=intChangeSuccessCount+1 "
    objVBSFile.WriteLine "           End If "
    objVBSFile.WriteLine "        End if"
    objVBSFile.WriteLine "    Next"
    objVBSFile.WriteLine "End Function"
    If Msgbox ("Backup services Completed" & Chr(13) & strVBSFilePath  & strVBSFileName & Chr(13) & "'(" & strMessage & ")" &"Begin optimization?",VBYesNo+vbInformation,"Complete" ) = vbYes Then
        '执行服务设置
        strMessage=SRV
        Msgbox "Optimization completed!restart Your computer?" & Chr(13) & "'(" & strMessage & ")",vbOKOnly+vbInformation,"OK"
'        If Msgbox("Optimization completed!restart Your computer?" & Chr(13) & "'(" & strMessage & ")",VBYesNo+vbInformation,"OK") = vbYes Then
'          objWShell.Run "Shutdown.exe -r -t 5"
'        End if  
    End if
    'Log输出
    Call OutputLog
    '备份文件关闭
    objVBSFile.Close
End if
'对象释放
For intIndex=0 To Ubound(aobjServiceChange)
    Set aobjServiceChange(intIndex)= Nothing
Next
Erase aobjServiceChange   
Erase astrLog
Set objFileSystem=Nothing
Set objVBSFile=Nothing
Set objWShell=Nothing
Set objWinManagment=Nothing
Set objServices=Nothing
Wscript.quit
''''''''''''''''''''''''''''''''''
'记录Log信息
''''''''''''''''''''''''''''''''''
Function WriteLog(strTemp)
    '检测当前数组值是否被初始化并初始化为空值
    If Isempty(astrLog(Ubound(astrLog))) Then
        astrLog(Ubound(astrLog))=""
    End If
    astrLog(Ubound(astrLog))=astrLog(Ubound(astrLog)) & strTemp
End Function
''''''''''''''''''''''''''''''''''
'按行记录Log信息
''''''''''''''''''''''''''''''''''
Function WriteLineLog(strTemp)
    '检测当前数组值是否被初始化并初始化为空值
    If Isempty(astrLog(Ubound(astrLog))) Then
        astrLog(Ubound(astrLog))=""
    End If
    astrLog(Ubound(astrLog))=astrLog(Ubound(astrLog)) & strTemp
    Redim Preserve astrLog(Ubound(astrLog)+1)
    astrLog(Ubound(astrLog))=""
End Function
''''''''''''''''''''''''''''''''''
'输出Log信息
''''''''''''''''''''''''''''''''''
Function OutputLog()
    '数组计数器
    Dim intIndex
    'Log输出出错计数
    Dim intLogOutputError
    intLogOutputError=0
    For intIndex=0 To Ubound(astrLog)
        On Error Resume Next
            objVBSFile.WriteLine "'" & astrLog(intIndex)
            If Err.Number<>0 Then
                intLogOutputError=intLogOutputError+1
                objVBSFile.WriteLine "'???????????????Illegal Code????????????????"
            End If
        On Error Goto 0
    Next
    If intLogOutputError<>0 Then
        objVBSFile.WriteLine "'???????????????Log Output Error(" & intLogOutputError & ")????????????????"
    End If
End Function
''''''''''''''''''''''''''''''
'添加变更原则
'''''''''''''''''''''''''''''''''
Function AddRuler(SRN,SRM)
    Dim intIndex
    '遍历所有已经存在服务以防止重复
    For intIndex=0 To Ubound(aobjServiceChange)-1
        If aobjServiceChange(intIndex).Name=SRN Then
            WriteLineLog "???????????????" & SRN & "'s Ruler duplicated ????????????????"
            Exit Function
        End If
    Next
    Set aobjServiceChange(Ubound(aobjServiceChange))=New clsServiceChange
    '记录服务名称
    aobjServiceChange(Ubound(aobjServiceChange)).Name=SRN
    '记录服务要变更成的启动模式
    aobjServiceChange(Ubound(aobjServiceChange)).StartModeTo=SRM
    Redim Preserve aobjServiceChange(Ubound(aobjServiceChange)+1)
End Function
''''''''''''''''''''''''''''''
'服务状态取得备份
''''''''''''''''''''''''''''''
Function GOT()
    '系统服务
    Dim objService
    '服务名
    Dim strServiceName
    '服务显示名
    Dim strServiceCaption
    '服务启动模式
    Dim strServiceMode
    '服务描述
    Dim strServiceDescription
    '变更计数
    Dim intChangeCount
    '有效规则计数
    Dim intRuleredCount
    '规则计数
    Dim intRuler
    '数组索引
    Dim intIndex
    '与规则匹配上标识
    Dim blnMatch
    intChangeCount=0
    intRuleredCount=0
    intRuler=Ubound(aobjServiceChange)-1
    WriteLineLog vbcrlf
    WriteLineLog "Optimize Needed:"
    WriteLineLog "============================="
    For Each objService in objServices
        blnMatch=False
        strServiceName = objService.Name
        strServiceCaption=objService.Caption
        strServiceMode = objService.StartMode
        strServiceDescription=objService.Description
        If IsNull(strServiceDescription) Then
            strServiceDescription=""
        End If
        strServiceDescription=Replace(strServiceDescription,vbcrlf,"")
        '是否在备份代码中显示说明
        If blnVBSShowCaption Then
            objVBSFile.Write "'"
            '避免出现乱码的情况出错
            On Error Resume Next
                objVBSFile.Write "(" & strServiceCaption & ") "
                '是否在备份代码中显示说明
                If blnShowDescription Then
                    objVBSFile.Write " [" & strServiceDescription & "]"
                End If
                objVBSFile.Writeline ""
                Err.clear
            On Error Goto 0
        End If
        objVBSFile.WriteLine "    SRV """& strServiceName &""","""& strServiceMode &""""
        '变更检测(用于Log输出)
        For intIndex=0 To Ubound(aobjServiceChange)-1
            '验证是否名称相同
            If strServiceName=aobjServiceChange(intIndex).Name Then
                '修改是否匹配上的标识
                blnMatch=True
                '记录匹配上的数目
                intRuleredCount=intRuleredCount+1
                '记录服务起始启动方式
                aobjServiceChange(intIndex).StartModeFrom=strServiceMode
                '记录服务显示名称
                aobjServiceChange(intIndex).Caption=strServiceCaption
                '记录服务描述
                aobjServiceChange(intIndex).Description=strServiceDescription
                '验证是否需要变更
                If strServiceMode<>aobjServiceChange(intIndex).StartModeTo Then
                    '需要变更计数
                    intChangeCount=intChangeCount+1
                    WriteLineLog strServiceName & vbTab & "(" & strServiceCaption &")"  & "[" & strServiceDescription &"]"
                    WriteLineLog strServiceMode & vbTab & "--->" & vbTab & aobjServiceChange(intIndex).StartModeTo
                End If
                '查找到服务之后退出循环
                Exit For
            End If
        Next
        '在规则中未规定的服务添加
        If blnMatch=False then
            Set aobjServiceChange(Ubound(aobjServiceChange))=New clsServiceChange
            '记录服务名称
            aobjServiceChange(Ubound(aobjServiceChange)).Name=objService.Name
            '记录服务别名
            aobjServiceChange(Ubound(aobjServiceChange)).Caption=objService.Caption
            '记录服务描述
            aobjServiceChange(Ubound(aobjServiceChange)).Description=objService.Description
            '记录服务初始的启动模式
            aobjServiceChange(Ubound(aobjServiceChange)).StartModeFrom=objService.StartMode
            Redim Preserve aobjServiceChange(Ubound(aobjServiceChange)+1)
        End If
    Next
    objVBSFile.WriteLine "    Msgbox ""Service Reset Completed"" & ""("" & intChangeSuccessCount &""/"" & intChangeCount & "")"" "
    GOT="Service:" & objServices.Count  & ",Ruler:" & intRuler & ",Rulered:" & intRuleredCount & ",NotRulered:" & objServices.Count-intRuleredCount & ",ChangeNeed:" & intChangeCount & ""
    WriteLineLog "***********************************************************************************"
    WriteLineLog GOT
    WriteLineLog "***********************************************************************************"
    '输出未做规定的
    WriteLineLog vbcrlf
    WriteLineLog "-----------------------------"
    WriteLineLog "Not Rulered:"
    WriteLineLog "-----------------------------"
    '遍历变更历史
    For intIndex=0 To Ubound(aobjServiceChange)-1
        '服务变更状态检测
        If aobjServiceChange(intIndex).State=cstrStateNotSetted Then
            '未设定的服务信息输出
            WriteLineLog """" & aobjServiceChange(intIndex).Name  & """" & vbTab & ",""" & aobjServiceChange(intIndex).StartModeFrom & """" & vbTab & "(" & aobjServiceChange(intIndex).Caption & ")" & "[" & aobjServiceChange(intIndex).Description & "]"
        End If
    Next
    '清空对象
    Set objService=Nothing
End Function
''''''''''''''''''''''''''''''''''''''''''''
'服务设定函数
''''''''''''''''''''''''''''''''''''''''''''
Function SRV()
    '系统服务
    Dim objService
    '数组计数
    Dim intIndex
    '服务描述
    Dim strServiceDescription
    '要设定的服务启动方式暂存
    Dim strStartModeTemp
    '服务启动方式修改成功计数
    Dim intChangeSuccessCount
    '服务启动方式修改不成功计数
    Dim intChangeNotSuccessCount
    intChangeSuccessCount=0
    intChangeNotSuccessCount=0
    WriteLineLog vbcrlf
    WriteLineLog "============================="
    WriteLineLog "Optimize Record:"
    WriteLineLog "============================="
    '修改失败的Log标题
    WriteLineLog "-----------------------------"
    WriteLineLog "Change False:"
    WriteLineLog "-----------------------------"
    '遍历服务集
    For Each objService In objServices
        For intIndex=0 To Ubound(aobjServiceChange)-1
            If objService.Name=aobjServiceChange(intIndex).Name Then
                '启动方式判断
                If aobjServiceChange(intIndex).State=cstrStateChanged Then
                    '修改启动方式
                    If aobjServiceChange(intIndex).StartModeTo=cstrAutoForRead Then
                        '要设定启动类型为自启动时
                        strStartModeTemp=cstrAutoForWrite
                    Else
                        '设定服务类型不是自启动时
                        strStartModeTemp=aobjServiceChange(intIndex).StartModeTo
                    End If
                    '修改服务启动方式
                    If objService.ChangeStartMode(strStartModeTemp)=0 Then
                        '修改成功计数
                        intChangeSuccessCount=intChangeSuccessCount+1
                    Else
                        '修改不成功计数
                        intChangeNotSuccessCount=intChangeNotSuccessCount+1
                        '记录未修改成功的服务
                        WriteLineLog objService.Name & "(" & objService.Caption & ")" & "[" & objService.Description & "]"
                        '记录该服务所应该做的变更
                        WriteLineLog objService.StartMode & vbTab & "--->" & vbTab & aobjServiceChange(intIndex).StartModeTo
                    End If
                End If
                '查找到服务之后退出循环
                Exit For
            End If
        Next
    Next
    SRV="Successed:" & intChangeSuccessCount & ",NotSuccessed:" & intChangeNotSuccessCount
    WriteLineLog "***********************************************************************************"
    WriteLineLog SRV
    WriteLineLog "***********************************************************************************"
    '清空对象
    Set objService=Nothing
End Function

(0)

相关推荐

  • VBS实现的系统服务备份优化代码

    复制代码 代码如下: Option Explicit'○○○○○○○○○○○○○○○○○○○○○○○○○○○○○开始Const blnVBSShowCaption=True'生成的服务备份中是否添加说明Const blnVBSShowDescription=True'●●●●●●●●●●●●●●●●●●●●●●●●●●●●●结束'文件读写标识常量Const Forwriteing = 8'读取出来的自动模式类型Const cstrAutoForRead="Auto"'用于设定的自动模式

  • vbs后台运行bat删除自身的代码

    知道真实路径的情况下 复制代码 代码如下: set fso=wscript.createobject("scripting.filesystemobject") fso.deletefile "c:\windows\system32\run.cmd" fso.deletefile "c:\windows\system32\run.vbs" 不知道具体的路径情况下,可以用如下代码: 复制代码 代码如下: Set fso =CreateObject(

  • php 备份数据库代码(生成word,excel,json,xml,sql)

    单表备份代码: 复制代码 代码如下: <?php    class Db    {        var $conn; function Db($host="localhost",$user="root",$pass="root",$db="test")        {          if(!$this->conn=mysql_connect($host,$user,$pass))          die(

  • win2003系统服务及优化建议

    win2003系统服务及优化建议 1.Application Layer Gateway Service ALG(应用层网关). 为Internet连接共享和Internet连接防火墙提供第三方协议插件的支持.该服务进程名为Alg.exe. 依存关系:Internet Connection Firewall(ICF)/Internet Connection Sharing(ICS) 建议:如果你不使用因特网联机共享(ICS)提供多台计算机的因特网存取和因特网联机防火墙(ICF)软件,停止. 2.

  • Oracle分页查询性能优化代码详解

    对于数据库中表的数据的 Web 显示,如果没有展示顺序的需要,而且因为满足条件的记录如此之多,就不得不对数据进行分页处理.常常用户并不是对所有数据都感兴趣的,或者大部分情况下,他们只看前几页. 通常有以下两种分页技术可供选择. Select * from ( Select rownum rn,t.* from table t) Where rn>&minnum and rn<=&maxnum 或者 Select * from ( Select rownum rn,t.* fro

  • Java编程实现快速排序及优化代码详解

    普通快速排序 找一个基准值base,然后一趟排序后让base左边的数都小于base,base右边的数都大于等于base.再分为两个子数组的排序.如此递归下去. public class QuickSort { public static <T extends Comparable<? super T>> void sort(T[] arr) { sort(arr, 0, arr.length - 1); } public static <T extends Comparabl

  • JavaScript深入V8引擎以及编写优化代码的5个技巧

    概述 JavaScript引擎是执行 JavaScript 代码的程序或解释器.JavaScript引擎可以实现为标准解释器,或者以某种形式将JavaScript编译为字节码的即时编译器. 以为实现JavaScript引擎的流行项目的列表: V8 - 开源,由 Google 开发,用 C ++ 编写 Rhino - 由 Mozilla 基金会管理,开源,完全用 Java 开发 SpiderMonkey - 是第一个支持 Netscape Navigator 的 JavaScript 引擎,目前正

  • PHP内存溢出优化代码详解

    相信很多人做大批量数据导出和数据导入的时候,经常会遇到PHP内存溢出的问题,在解决了问题之后,总结了一些经验,整理成文章记录下. 优化点 1.优化SQL语句,避免慢查询,合理的建立索引,查询指定的字段,sql优化这块在此就不展开了. 2.查询的结果集为大对象时转数组处理,框架中一般有方法可以转,如Laravel中有toArray(),Yii2中有asArray(). 3.对于大数组进行数据切割处理,PHP函数有array_chunk().array_slice(). 4.对于大型的字符串和对象,

  • Javascript前端优化代码

    if 判断的优化 JavaScript条件语句在我们平时的开发中是不可避免要用到的,但是很多时候我们的代码写的并不好,一连串的if-else或者多重嵌套判断都会使得代码很臃肿,下面举例进行优化. 需求:现在有 4 个产品,分别是手机.电脑.电视机.游戏机,当然每个产品显示的价格不一样. 1.最简单的方法:if 判断 let commodity = { phone: '手机', computer: '电脑', television: '电视', gameBoy: '游戏机', } function

  • 使用compose函数优化代码提高可读性及扩展性

    目录 前言 场景说明 需求更新 需求再更新 需求再再更新 compose 函数 composePromise 逐渐美丽起来 阶段总结 前言 本瓜知道前不久写的<JS 如何函数式编程>系列各位可能并不感冒,因为一切理论的东西如果脱离实战的话,那就将毫无意义. 于是乎,本瓜着手于实际工作开发,尝试应用函数式编程的一些思想. 最终惊人的发现:这个实现过程并不难,但是效果却不小! 实现思路:借助 compose 函数对连续的异步过程进行组装,不同的组合方式实现不同的业务流程. 这样不仅提高了代码的可读

随机推荐