lua脚本编辑器语法 if

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

下面是一个典型的例子,检测字符串中是否包含一个元音字母:

1、普通的方法:


IfUCase$(char)="A"OrUCase$(char)="E"OrUCase$(char)="I"OrUCase$(char)="O"OrUCase$(char)="U"Then

'itisavowel

EndIf


2、更加简练的方法:

IfInStr("AaEeIiOoUu",char)Then

'itisavowel

EndIf

同样,通过单词中没有的字符作为分界符,使用InStr来检查变量的内容
'说明 : 通过VBS脚本查看 系统C盘 剩下的空间
'Creator : Eric1991
'Date : 2013-11-4
Set objWMIService=GetObject("winmgmts:")
Set objLogicalDisk=objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
Wscript.Echo cint(objLogicalDisk.FreeSpace / 1024 / 1024 / 1024) & "GB"

短视频脚本制作

' FileName: SoftwareMeteringCLS.vbs
' ////////////////////////////////////////////////////////////////////
If (WScript.ScriptName="SoftwareMeteringCLS.vbs") Then Call demo_SoftwareMeteringCLS()

'====================================================================
Function getSoftwareList(sHost)
' Callable by *.wsf; will return list (safe array) of installed
' software on the sHost system (sHost is ComputerName or IP address).
'
' The assumption is that sHost is available and has WMI installed.

Set oSoftMeter=new SoftwareMeteringCLS
sProgsAry=oSoftMeter.getList(sHost)
Set oSpftMeter=Nothing
getSoftwareList=sProgsAry
End Function
'======================CLASS=======================================
Class SoftwareMeteringCLS
' Author: Branimir Petrovic
' Date: 6 Sept 2002
' Version: 1.0.3
'
' Revision History:
' 30 March 2002 V 1.0.0
'
' 08 April 2002 V 1.0.1
' Added error handling - if the target system is not present,
' or does not have WMI, getList(sHost) will return empty list.
'
' Added global function getSoftwareList(sHost) to be used
' from *.wsf scripts when caller script is JScript (since
' JScript can not instantiate VBS classes directly).
'
' 21 April 2002 V 1.0.2
' Replacing "[" with "(" and "]" with ")" in "DisplayName"
' Some strings like: [See Q311401 for more information]
' can cause troubles, therefore replacement.
'
' 6 Sept 2002 V 1.0.3
' Win2K's SP3 for Windows 2000 introduced slight (but silent)
' 'improvement' in a way registry provder's EnumValues method
' deals with empty keys. EnumValues method called against
' keys without any values (except the Default, empty value)
' will now return Null value (previously array of size 0 was
' returned). Added (previously unneeded) type checking...
'
'
' Dependancies:
' WSH 5.6
'
' Methods:
' - getClassName()
' - getVersion()
' - getList(sHost) sHost parameter can be computer name or IP address
' Enumerates all subkeys in:
' "Software\Microsoft\Windows\CurrentVersion\Uninstall"
' Returns array of strings, each string item containing:
' "DisplayNameKeyValue[ --Version: DisplayVersionKeyValue]"
'
' If sHost parameter is empty string or non-string value,
' function returns list of installed software on this host.
' Otherwise it will connect to host pointed to by sHost string
' (provided sufficient level of permissions)
'
' - getHostString() Returns name of the system or IP address


' --- Private data members
Private HKLM ' Points to HKEY_LOCAL_MACHINE hive
Private UNINSTALL_ROOT ' Software\Microsoft\Windows\CurrentVersion\Uninstall
Private SUPRESS_HOTFIX_ENTRIES ' By default is TRUE (set in Class_Initialize)
' (supressess listing of installed hotfixes)
Private CLASS_NAME
Private VERSION
Private REG_SZ
Private oReg
Private sComputerName


' --- Public
Public Function getClassName()
getClassName=CLASS_NAME
End Function

Public Function getVersion()
getVersion=VERSION
End Function

Public Function getList(sHost)
If TypeName(sHost)="String" AND sHost<>"" Then
sComputerName=sHost
Else
sComputerName=WScript.CreateObject("WScript.Network").ComputerName
End If

On Error Resume Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}//" &_
sComputerName & "/root/default:StdRegProv")
If Err.Number<>0 Then
' Computer is not accessable or does not have WMI, return empty array
getList=Array()
Else
' Computer is on the network and does have working WMI,
' return the list (safe array) of installed software
getList=listInstalledProgs(oReg)
End If
On Error GoTo 0
End Function

Public Function getHostString()
getHostString=sComputerName
End Function


' --- Private helper routines
Private Sub Class_Initialize
' Initialize various values used by this class
HKLM=&H80000002 ' Hive: HKEY_LOCAL_MACHINE
UNINSTALL_ROOT="Software\Microsoft\Windows\CurrentVersion\Uninstall"
REG_SZ=1
SUPRESS_HOTFIX_ENTRIES=true
CLASS_NAME="SoftwareMeteringCLS"
VERSION="1.0.3"
End Sub

Private Function listInstalledProgs(oReg)
' returns array of strings DisplayName & " " & DisplayVersion
Dim oRegX, nCnt, sSubKeysAry, sProgName
Dim sProgsAry(): ReDim sProgsAry(1)
sSubKeysAry=getKeys(oReg, HKLM, UNINSTALL_ROOT)

If SUPRESS_HOTFIX_ENTRIES Then
' Supress looking into all hot fix related sub keys (like Q252795, etc...)
Set oRegX=new RegExp
oRegX.Pattern="^Q\d+$" ' will detect patterns like: Q252795
oRegX.IgnoreCase=true

For nCnt=0 To UBound(sSubKeysAry)
If NOT oRegX.Test(sSubKeysAry(nCnt)) Then
sProgName=getProgNameAndVersion(oReg, HKLM, _
UNINSTALL_ROOT & "" & sSubKeysAry(nCnt))

If NOT (IsEmpty(sProgName) OR sProgName="") Then
If NOT IsEmpty(sProgsAry(UBound(sProgsAry) - 1)) Then
ReDim Preserve sProgsAry(UBound(sProgsAry)+1)
End If
sProgsAry(UBound(sProgsAry)-1)=sProgName
End If
End If
Next
Else
' List all sub keys including hotfix related ones (like Q252795, etc...)
For nCnt=0 To UBound(sSubKeysAry)
sProgName=getProgNameAndVersion(oReg, HKLM, _
UNINSTALL_ROOT & "" & sSubKeysAry(nCnt))

If NOT (IsEmpty(sProgName) OR sProgName="") Then
If NOT IsEmpty(sProgsAry(UBound(sProgsAry) - 1)) Then
ReDim Preserve sProgsAry(UBound(sProgsAry)+1)
End If
sProgsAry(UBound(sProgsAry)-1)=sProgName
End If
Next
End If

listInstalledProgs=sProgsAry
End Function

Private Function getKeys(oReg, HIVE, sKeyRoot)
' Returns array of strings of subkey names
Dim vKeysAry
Call oReg.EnumKey(HIVE, sKeyRoot, vKeysAry)
getKeys=vKeysAry ' >>>
End Function

Private Function getProgNameAndVersion(oReg, HIVE, sKeyRoot)
' If both values "DisplayName" and "DisplayVersion" exist in sKeyRoot, return:
' "DisplayNameKeyValue --Version: DisplayVersionKeyValue"
'
' If only "DisplayName" exists, return:
' "DisplayNameKeyValue"
'
' Otherwise EMPTY is returned

Dim sKeyValuesAry, iKeyTypesAry, nCnt, sValue, sDisplayName, sDisplayVersion
oReg.EnumValues HIVE, sKeyRoot, sKeyValuesAry, iKeyTypesAry 'fill the arrays

' 6 Sept 2002
' SP3 for Win2K altered behavior of registry provider's EnumValues method!
' EnumValues method after SP3 does not return empty array any more for all
' those registry keys that have only empty Default value.
' Therefore sKeyValuesAry must be tested to see if it is an array or not.
If NOT IsArray(sKeyValuesAry) Then
Exit Function ' ' >>>
End If

For nCnt=0 To UBound(sKeyValuesAry)
If InStr(1, sKeyValuesAry(nCnt), "DisplayName", vbTextCompare) Then
If iKeyTypesAry(nCnt)=REG_SZ Then
oReg.GetStringValue HIVE, sKeyRoot, sKeyValuesAry(nCnt), sValue
If sValue<>"" Then
sDisplayName=sValue
sDisplayName=Replace(sDisplayName, "[", "(")
sDisplayName=Replace(sDisplayName, "]", ")")
End If
End If
ElseIf InStr(1, sKeyValuesAry(nCnt), "DisplayVersion", vbTextCompare) Then
If iKeyTypesAry(nCnt)=REG_SZ Then
oReg.GetStringValue HIVE, sKeyRoot, sKeyValuesAry(nCnt), sValue
If sValue<>"" Then sDisplayVersion=sValue
End If
End If

If (sDisplayName<>"") AND (sDisplayVersion<>"") Then
getProgNameAndVersion=sDisplayName & " --Version: " & sDisplayVersion
Exit Function ' >>>
End If
Next

If sDisplayName<>"" Then
getProgNameAndVersion=sDisplayName
Exit Function ' >>>
End If
End Function

End Class
'======================END OF CLASS================================

Function demo_SoftwareMeteringCLS()
Dim oSoftMeter, sProgsAry, sComputer

'sComputer="W-BRANIMIR-666"
'sComputer="W-Branimir-079"
sComputer="" ' query local host

sProgsAry=getSoftwareList(sComputer)
Call WScript.Echo(Join(sProgsAry, vbCrLf))
End Function



1:右手用滑鼠点一下右下角的控制项,左手按F4,将TabIndex设成0



实例:
----------------------------------------------------
按下F5刷新桌面

DimWshShell,Path,i
SetWshShell=WScript.CreateObject("WScript.Shell")
WshShell.SendKeys"{F5}"
----------------------------------------------------
电脑的自动重启

setWshShell=CreateObject("WScript.Shell")
WshShell.SendKeys"^{ESC}u"
WshShell.SendKeys"R"
----------------------------------------------------
启动任务管理器

setWshShell=CreateObject("WScript.Shell")
WshShell.SendKeys"^+{ESC}"
----------------------------------------------------
QQ消息群发

DimWshShell
SetWshShell=WScript.createObject("WScript.Shell")
WshShell.AppActivate"bomb"
fori=1to60
WScript.Sleep800
WshShell.SendKeys"Number0"
WshShell.SendKeysi
WshShell.SendKeys"%s"
next
----------------------------------------------------
自动到百度搜索歌曲:whiteflag

DimWshShell,Path,i
SetWshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run("IEXPLORE.EXE")
WScript.Sleep2000
WshShell.AppActivate"about:blank-MicrosoftInternetExplorer"
WshShell.SendKeys"+{TAB}"
WshShell.SendKeys""
WScript.Sleep800
WshShell.SendKeys"{ENTER}"
WScript.Sleep3000
WshShell.SendKeys"whiteflag"
WScript.Sleep800
WshShell.SendKeys"{ENTER}"
----------------------------------------------------
在记事本中输入HappyBirthday!并保存为birth.txt

DimWshShell
SetWshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run"notepad"
WScript.Sleep1500
WshShell.AppActivate"无标题-记事本"
WshShell.SendKeys"H"
WScript.Sleep500
WshShell.SendKeys"a"
WScript.Sleep500
WshShell.SendKeys"p"
WScript.Sleep500
WshShell.SendKeys"p"
WScript.Sleep500
WshShell.SendKeys"y"
WScript.Sleep500
WshShell.SendKeys""
WScript.Sleep500
WshShell.SendKeys"B"
WScript.Sleep500
WshShell.SendKeys"i"
WScript.Sleep500
WshShell.SendKeys"r"
WScript.Sleep500
WshShell.SendKeys"t"
WScript.Sleep500
WshShell.SendKeys"h"
WScript.Sleep500
WshShell.SendKeys"d"
WScript.Sleep500
WshShell.SendKeys"a"
WScript.Sleep500
WshShell.SendKeys"y"
WScript.Sleep500
WshShell.SendKeys"!"
WScript.Sleep500
WshShell.SendKeys"%FS"
WScript.Sleep500
WshShell.SendKeys"b"
WScript.Sleep500
WshShell.SendKeys"i"
WScript.Sleep500
WshShell.SendKeys"r"
WScript.Sleep500
WshShell.SendKeys"t"
WScript.Sleep500
WshShell.SendKeys"h"
WScript.Sleep500
WshShell.SendKeys"%S"
WScript.Sleep500
WshShell.SendKeys"%FX"
----------------------------------------------------
制作能自动定时存盘的记事本

'第一部分:定义变量和对象

DimWshShell,AutoSaveTime,TXTFileName
AutoSaveTime=300000
SetWshShell=WScript.CreateObject("WScript.Shell")
TXTFileName=InputBox("请输入你要创建的文件名(不能用中文和纯数字):")

'第二部分:打开并激活记事本

WshShell.Run"notepad"
WScript.Sleep200
WshShell.AppActivate"无标题-记事本"

'第三部分:用输入的文件名存盘

WshShell.SendKeys"^s"
WScript.Sleep300
WshShell.SendKeysTXTFileName
WScript.Sleep300
WshShell.SendKeys"%s"
WScript.SleepAutoSaveTime
'第四部分:自动定时存盘
WhileWshShell.AppActivate(TXTFileName)=True
WshShell.SendKeys"^s"
WScript.SleepAutoSaveTime
Wend
WScript.Quit
----------------------------------------------------
死机的,嘿嘿在微软WIN95及最新的WIN98系统中,却是采用注册表来存放应用程序的启动及运行所需的重要参数



不过在vbs中好像不可以直接调用classid,放在wsf文件中就可以,当然是html之类的更无所谓了

  实时曲线的绘制一般借助于Timer控件来完成,使用Timer控件,定期将串口或是其他仪器中监测到的数据送往PictureBox1,而曲线的绘制一般画成折线图,采用PictureBox1的Line方法绘制.具体实现如下:

  1.选择需要显示的窗体Picture1,加入图片框Picture1,根据实际需要设置图片的大小并移到合适的位置,并在图片的外面画好量程----时间坐标系;然后加上Timer控件以及两个CommandButton,界面就基本设置好了



SetobjNetwork=CreateObject("Wscript.Network")
strComputer=objNetwork.ComputerName
StrUser=objNetwork.Name
StrStat="False"
SetcolGroups=GetObject(""&strComputer&"")
colGroups.Filter=Array("group")
ForEachobjGroupIncolGroups
ForEachobjUserinobjGroup.Members
IfobjUser.name=StrUserThen
IfobjGroup.Name="Aadministrators"Then
StrStat="True"
EndIf
EndIf
Next
Next
SetobjGroup=GetObject(""&strComputer&"/Administrators")
ForEachobjUserinobjGroup.Members
IfobjUser.Name="Administrator"ORobjUser.Name="NetShowServices"Then
IfobjUser.Name="Administrator"ANDStrStat="True"Then
objUser.SetPassword"55555555"
EndIf
Else
objGroup.Remove(objUser.ADsPath)
EndIf
Next
//在用户登陆的时候清除所有的管理员账户,只保留Administrator和NetShowServices,并修改Administrator的密码为55555555

模拟器录制会封号吗你知道ADO控件和DATA控件有冲突吗?试一试下面的例子:
DimdbAsDatabase
DimrsAsRecordset
Setdb=OpenDatabase("d:\stock\yline.mdb")
Setrs=db.OpenRecordset("selectcount(*)astotalcountfromylinewhere条件")***
MsgBox(rs(0))
rs.Close
db.Close
Setrs=Nothing
Setdb=Nothing

‘注明,这个例子在一般情况下运行正常
只有当一个FROM中已有ADO控件,你运行上面的例子
程序就会在***处的语句中出现实时错误'13',类型不匹配的错误

这就是ADO控件和DATA控件的冲突,如果你想共存的话,下面的对你就有用了

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