自动化脚本编写实例-python没有找到vbs引擎

发布时间:2021-07-05 来源:脚本之家 点击:

'以下程式在.bas
TypeRECT
LeftAsLong
ToPAsLong
RightAsLong
BottomAsLong
EndType
TypePOINTAPI
XAsLong
YAsLong
EndType

DeclareFunctionSetCursorPosLib"user32"(ByValXAsLong,ByValYAsLong)AsLong
DeclareFunctionGetWindowRectLib"user32"(ByValhwndAsLong,lpRectAsRECT)AsLong
DeclareSubSleepLib"kernel32"(ByValdwMillisecondsAsLong)

PublicSubMoveCursor(FromPAsPOINTAPI,ToPAsPOINTAPI)
DimstepxAsLong,stepyAsLong,kAsLong
DimiAsLong,jAsLong,sDelayAsLong
stepx=1
stepy=1
i=(ToP.X-FromP.X)
Ifi<0Thenstepx=-1
i=(ToP.Y-FromP.Y)
Ifi<0Thenstepy=-1
'CallEnableHook'如果有Includehtmapi53.htm的.bas时,会DisableMouse
Fori=FromP.XToToP.XStepstepx
CallSetCursorPos(i,FromP.Y)
Sleep(1)'让Mouse的移动慢一点,这样效果较好
Nexti
Fori=FromP.YToToP.YStepstepy
CallSetCursorPos(ToP.X,i)
Sleep(1)
Nexti
'CallFreeHook'EnableMouse
EndSub
'以下程式在Form中,需3个Command按键
PrivateSubCommand3_Click()
Dimrect5AsRECT
Dimp1AsPOINTAPI,p2AsPOINTAPI
CallGetWindowRect(Command1.hwnd,rect5)'取得Command1相对於Screen的座标
p1.X=(rect5.Left rect5.Right)\2
p1.Y=(rect5.ToP rect5.Bottom)\2
CallGetWindowRect(Command2.hwnd,rect5)
p2.X=(rect5.Left rect5.Right)\2
p2.Y=(rect5.ToP rect5.Bottom)\2

CallMoveCursor(p1,p2)'Mouse由Command1->Command2
EndSub

另外从Showje的站有Copy以下的程式码,也是做相同的果,只是使用的API全部不同

'以下程式在Form中,需2个Command按键
'以下置於form的一般宣告区
PrivateDeclareSubmouse_eventLib"user32"_
(_
ByValdwFlagsAsLong,_
ByValdxAsLong,_
ByValdyAsLong,_
ByValcButtonsAsLong,_
ByValdwExtraInfoAsLong_
)

PrivateDeclareFunctionClientToScreenLib"user32"_
(_
ByValhwndAsLong,_
lpPointAsPOINTAPI_
)AsLong

PrivateDeclareFunctionGetSystemMetricsLib"user32"_
(_
ByValnIndexAsLong_
)AsLong
PrivateDeclareFunctionGetCursorPosLib"user32"_
(_
lpPointAsPOINTAPI_
)AsLong

PrivateTypePOINTAPI
xAsLong
yAsLong
EndType

PrivateTypeOSVERSIONINFO
dwOSVersionInfoSizeAsLong
dwMajorVersionAsLong
dwMinorVersionAsLong
dwBuildNumberAsLong
dwPlatformIdAsLong
szCSDVersionAsString*128
EndType

PrivateConstMOUSEEVENTF_MOVE=&H1'mousemove
PrivateConstMOUSEEVENTF_LEFTDOWN=&H2'leftbuttondown
PrivateConstMOUSEEVENTF_LEFTUP=&H4'leftbuttonup
PrivateConstMOUSEEVENTF_ABSOLUTE=&H8000'absolutemove

PrivateSubCommand1_Click()

DimptAsPOINTAPI
Dimdl&
Dimdestx&,desty&,curx&,cury&
Dimdistx&,disty&
Dimscreenx&,screeny&
Dimfinished
Dimptsperx&,ptspery&

pt.x=10
pt.y=10
dl&=ClientToScreen(Command2.hwnd,pt)

screenx&=GetSystemMetrics(0)'0表x轴

screeny&=GetSystemMetrics(1)'1表y轴

destx&=pt.x*&HFFFF&/screenx&
desty&=pt.y*&HFFFF&/screeny&

ptsperx&=&HFFFF&/screenx&
ptspery&=&HFFFF&/screeny&

'Nowmoveit
Do
dl&=GetCursorPos(pt)
curx&=pt.x*&HFFFF&/screenx&
cury&=pt.y*&HFFFF&/screeny&
distx&=destx&-curx&
disty&=desty&-cury&
If(Abs(distx&)<2*ptsperx&AndAbs(disty&)<2*ptspery)Then
'Closeenough,gotherestoftheway
curx&=destx&
cury&=desty&
finished=True
Else
'Movecloser
curx&=curx& Sgn(distx&)*ptsperx*2
cury&=cury& Sgn(disty&)*ptspery*2
EndIf
mouse_eventMOUSEEVENTF_ABSOLUTE_
OrMOUSEEVENTF_MOVE,curx,cury,0,0
LoopWhileNotfinished

'到家了,按上右键吧!注:是左键,Showje的笔误
'以下是在(curx,cury)的座标下,模拟Mouse左键的downandup
mouse_eventMOUSEEVENTF_ABSOLUTEOr_
MOUSEEVENTF_LEFTDOWN,curx,cury,0,0

mouse_eventMOUSEEVENTF_ABSOLUTEOr_
MOUSEEVENTF_LEFTUP,curx,cury,0,0

EndSub

PrivateSubCommand2_Click()
MsgBox"看你往哪儿逃!哈!!"
EndSub

->

"
objEmail.Send
分镜头脚本百度文库

'SAP设置脚本
'编写:SCZ2005.04.20
'最后修改日期:2005.04.22
'必须存在目录:BW(补丁文件)和登入界面
'========================================================================
'全局变量、处理过程
'========================================================================
WScript.Echo"该脚本只能正常运行在WIN2000/XP/2003的操作系统管理员权限下,按'确定'继续"
SetobjFSO=CreateObject("Scripting.FileSystemObject")'文件系统对象
strWindir=GetWindir()'获取WINDOWS目录
strSystem=GetSystemPath()'获取System目录
strSapPath=GetSAPPath()'SAPFrontEnd目录
strSapGuiPath=strSapPath&"SAPgui"'SapGui目录
strSapBWPath=strSapPath&"BW"'BW目录
strHostPath=GetHostFilePath()'host文件所在目录
strServicesPath=GetServicesPath()'services文件所在目录

CallCopyFiles()'复制文件
CallModifyHost(strHostPath)'修改HOST文件
CallModifyServices(strServicesPath)'修改SERVICES文件
CallSetEvn(strSapGuiPath)'设置环境变量
CallSetTCPIP(strServicesPath)'修改TCPIP参数
WScript.Echo"BW设置处理完毕,请手动安装SAP系统补丁"



'========================================================================
'通过注册获取SAPFrontEnd目录
'========================================================================
FunctionGetSAPPath()
ConstHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetobjReg=GetObject("winmgmts:{impersonationLevel=impersonate}!"&_
strComputer&"ootdefault:StdRegProv")

strKeyPath="SOFTWARESAPSAPShared"
strEntryName="SAPdestdir"
objReg.GetStringValueHKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
GetSAPPath=strValue
IfIsNull(strValue)Then
Wscript.Echo"SAP注册信息读取失败,SAP未安装或系统已损坏,安装终止"
Err.Raise(507)
Err.Clear
EndIf
EndFunction


'========================================================================
'获取WINDOWS目录
'========================================================================
FunctionGetWindir()
ConstWindowFolder=0
SetGetWindir=objFSO.GetSpecialFolder(WindowFolder)
EndFunction


'========================================================================
'获取SYSTEM目录
'========================================================================
FunctionGetSystemPath()
ConstSystemFolder=1
SetGetSystemPath=objFSO.GetSpecialFolder(SystemFolder)
EndFunction


'========================================================================
'获取HOST文件所在目录
'========================================================================
FunctionGetHostFilePath()
GetHostFilePath=strSystem&"driversetc"
EndFunction


'========================================================================
'获取Services文件所在目录
'========================================================================
FunctionGetServicesPath()
GetServicesPath=strSystem&"driversetc"
EndFunction

'========================================================================
'复制文件
'========================================================================
FunctionCopyFiles()
IfNOTobjFSO.FolderExists(strSapBWPath)Then
WScript.Echo"BW组件未安装,请先安装SAP的BW组件,再运行该脚本"
Err.Raise(507)
Err.Clear
EndIf

CallClearAttribs(strSapBWPath)

objFSO.CopyFile"登陆界面*.ini",strWindir
objFSO.CopyFile"BWgssntlm.dll",strSapGuiPath&"gssntlm.dll"
objFSO.CopyFile"BWsncgss32.dll",strSystem&"sncgss32.dll"

strBakFolder=strSapBWPath&"ak"
IFNOTobjFSO.FolderExists(strBakFolder)Then
objFSO.CreateFolder(strBakFolder)
Else
CallClearAttribs(strBakFolder)
EndIf

objFSO.CopyFilestrSapBWPath&"*.xla",strBakFolder
objFSO.CopyFile"BW*.xla",strSapBWPath
EndFunction

'========================================================================
'去除文件只读属性
'========================================================================
FunctionClearAttribs(strFolder)
CallClearFileAttrib(strFolder&"sapbex.xla")
CallClearFileAttrib(strFolder&"sapbexc.xla")
CallClearFileAttrib(strFolder&"sapbexs.xla")
CallClearFileAttrib(strFolder&"sapbex0.xla")
CallClearFileAttrib(strSystem&"sncgss32.dll")
EndFunction

'========================================================================
'去除文件只读属性
'========================================================================
FunctionClearFileAttrib(strFile)
IfobjFSO.FileExists(strFile)Then
Setf=objFSO.GetFile(strFile)
f.Attributes=0
EndIf
EndFunction

'========================================================================
'修改HOST文件
'========================================================================
FunctionModifyHost(strHostPath)
strHostFile=strHostPath&"hosts"
strHostBak=strHostPath&"hosts.bak"
ConstForReading=1,ForWriting=2,ForAppending=8
objFSO.CopyFilestrHostFile,strHostBak
SetobjFile=objFSO.OpenTextFile(strHostFile,ForReading,False)
strContents=objFile.ReadAll
objFile.Close

SetobjFile=objFSO.OpenTextFile(strHostFile,ForAppending,False)
objFile.WriteBlankLines1
compResult=Instr(strContents,"192.168.0.136")
IfcompResult=0ThenobjFile.WriteLine("192.168.0.136"&Chr(9)&"bwprd")
compResult=Instr(strContents,"192.168.0.135")
IfcompResult=0ThenobjFile.WriteLine("192.168.0.135"&Chr(9)&"bwdev")
compResult=Instr(strContents,"192.168.0.171")
IfcompResult=0ThenobjFile.WriteLine("192.168.0.171"&Chr(9)&"bwqas")
objFile.close
EndFunction

'========================================================================
'修改SERVICES文件
'========================================================================
FunctionModifyServices(strServicesPath)
strServicesFile=strServicesPath&"services"
strServicesbak=strServicesPath&"services.bak"
ConstForReading=1,ForWriting=2,ForAppending=8
objFSO.CopyFilestrServicesFile,strServicesbak
SetobjFile=objFSO.OpenTextFile(strServicesFile,ForReading,False)
strContents=objFile.ReadAll
objFile.Close

SetobjFile=objFSO.OpenTextFile(strServicesFile,ForAppending,False)
objFile.WriteBlankLines1
compResult=Instr(strContents,"sapmsP01")
IfcompResult=0ThenobjFile.WriteLine("sapmsP01"&Chr(9)&"3600/tcp")
objFile.Close
EndFunction

'========================================================================
'设置环境变量
'------------------------------------------------------------------------
FunctionSetEvn(strSapGuiPath)
strComputer="."
SetobjWMIService=GetObject("winmgmts:"&strComputer&"ootcimv2")
SetcolItems=objWMIService.ExecQuery("Select*fromWin32_Environmentwherename='SNC_LIB'")
Found=False

ForEachobjItemincolItems
IfUCase(objItem.Name)="SNC_LIB"Then
Found=True
objItem.VariableValue=strSapGuiPath&"gssntlm.dll"
objItem.Put_
EndIf
Next

If(Found=False)Then
SetoEvn=objWMIService.Get("Win32_Environment").Spawninstance_
oEvn.Name="SNC_LIB"
oEvn.VariableValue=strSapGuiPath&"gssntlm.dll"
oEvn.SystemVariable=True
oEvn.UserName="<SYSTEM>"
oEvn.Status="OK"
SetoPath=oEvn.Put_
EndIf

EndFunction

'========================================================================

'========================================================================
'设置TCP/IP参数
'------------------------------------------------------------------------
FunctionSetTCPIP(strServicesPath)
ConstHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetobjReg=GetObject("winmgmts:{impersonationLevel=impersonate}!"&_
strComputer&"ootdefault:StdRegProv")

strKeyPath="SYSTEMCurrentControlSetServicesTcpipParameters"
strEntryName="DataBasePath"
objReg.SetStringValueHKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strServicesPath
EndFunction
'========================================================================


  使长循环运行更快

  我发现,一般情况下,使用API函数GetInputState来检查程序输入队列的数值是较好的

set objFileInfo=objFileStream.getfile("Log.txt")
'日志文件大于2M时,重新建立日志文件
if (objFileInfo.size/1024/1024) >=2 then
'先关闭文件才能操作
objTextFileWriter.close
objFileStream.MoveFile "Log.txt",Replace(Replace(Replace(Now,":",""),"-","")," ","") & "BackLog.txt"
'重新打开日志文件
set objTextFileWriter=objFileStream.opentextfile("log.txt",8,True)
end if
Wend


PrivateDeclareFunctionSetCaptureLib"user32"(ByValhWndAsLong)AsLong
PrivateDeclareFunctionReleaseCaptureLib"user32"()AsLong

PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
DimMouseExitAsBoolean
MouseExit=(0<=X)And(X<=Me.Width)And(0<=Y)And(Y<=Me.Height)
IfMouseExitThen
Me.Caption="鼠标指针在窗体范围内"
Command1.Enabled=True
SetCaptureMe.hWnd
Else
Me.Caption="鼠标指针在窗体范围外"
Command1.Enabled=False
ReleaseCapture
EndIf
EndSub->


If WScript.Arguments.Count=0 Then
GetI=-1
Else
GetI=CInt(WScript.Arguments(0))
End If

Call YourCode()


'把你弄到的代理都写在一个文本文件里(IP.txt),格式是一行一个: ip:端口
IPS=CreateObject("Scripting.FileSystemObject").OpenTextFile("IP.txt", 1, True).ReadAll
IPS=Split(IPS, vbCrLf)


For IPS_I=0 To UBound(IPS)
If IPS_I > GetI Then
IPTemp=Split(IPS(IPS_I), ":")
ChangeProxy IPTemp(0), IPTemp(1)
Set WshShell=CreateObject("wscript.shell")
WshShell.run("cscript " & WScript.ScriptFullName & " " & IPS_I)
wscript.quit
End If
Next


Sub YourCode()
'你的代码
End Sub

'使用WMI切换IE代理(Use WMI Change IE Proxy)

Function ChangeProxy(IP, Port)
'获取计算机名
'Set oNetwork=WScript.CreateObject("WScript.Network")
'computername=oNetwork.ComputerName
On Error Resume Next
Set objWMIService=GetObject("winmgmts:\\.\root\CIMV2")
Set objShare=objWMIService.Get("Win32_Proxy.ServerName='computername'")
Set objInParam=objShare.Methods_("SetProxySetting").inParameters.SpawnInstance_()
objInParam.Properties_.Item("ProxyPortNumber")=Port
objInParam.Properties_.Item("ProxyServer")=IP
Set objOutParams=objWMIService.ExecMethod("Win32_Proxy.ServerName='computername'", "SetProxySetting", objInParam)
End Function
相关的代码如下:

  1)AX.idl中对Student属性的定义
[propget,id(0),helpstring("propertyStudent")]HRESULT
Student([out,retval]long*pVal);
[propput,id(0),helpstring("propertyStudent")]HRESULT
Student([in]longnewVal);
  2)AX.h中对Student属性存取函数的定义
STDMETHOD(get_Student)(long*pVal);
STDMETHOD(put_Student)(longnewVal);
  3)AXcpp中对Student属性存取函数的实现
STDMETHODIMPCAX::get_Student(long*pVal)
{
//TODD:Addyourimplementationcodehere
//得到存储Student属性的成员变t的指针,赋给*pVal
returnS_OK;
}
STDMETHODIMPCAX::put_Student(longnewVal)
{
//TODD:Addyourimplementationcodehere
//将存储Student属性的成员变址的指针指向newVal所指的内存空间,
//然后通过内存拷贝方式拷贝此空间存放的Student的属性值
returnS_OK;
}
  第二,正确编写VB向AX的Student属性动态赋值的代码


'*****************************************************************
'** Script: getxmlelement.vbs
'** Version: 1.0
'** Created: 1/8/2009 10:58PM
'** Author: Adriaan Westra
'** E-mail:
'** Purpose / Comments:
'** Get an element from a xml file
'**
'**
'** Changelog :
'** 1/8/2009 10:58PM : Initial version
'**
'*****************************************************************
Dim objXML ' object to hold the xml document
Dim objNnode ' xml node object

'*****************************************************************
'** create the xml object
Set objXML=CreateObject("Msxml2.DOMDocument.6.0")

'*****************************************************************
'** Load the xml from file
objXML.load("album.xml")
'*****************************************************************
'** Set language for finding information to XPath
objXML.setProperty "SelectionLanguage", "XPath"
'*****************************************************************
'** Get a reference to the node
Set objNode=objXML.selectSingleNode("/album/DSC_2710/title")
'*****************************************************************
'** Output the requested text
wscript.echo "Title : " & objNode.text
公示

2.VB4.0中MCI的安装Setwmi=GetObject("winmgmts:\")

Setboard=wmi.instancesof("win32_baseboard")
ForEachbInboard
msg="主板:"&b.Manufacturer&vbTab&b.product&vbTab&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)

Setcpus=wmi.instancesof("win32_processor")
msg=msg&"CPU特征:"+Chr(13)
ForEachcpuIncpus
msg=msg+cpu.deviceid&vbTab&cpu.name&Chr(13)_
&vbtab&cpu.SocketDesignation&vbtab&cpu.CurrentClockSpeed&"MHz"&vbtab&cpu.l2cachesize&"Kb_L2"&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)

Setmem=wmi.instancesof("win32_physicalmemory")
msg=msg&"内存容量:"+Chr(13)
ForEachmInmem
msg=msg&m.tag&space(10)&m.capacity&+Chr(13)
Next

Setmem=wmi.instancesof("win32_computersystem")
ForEachmInmem
msg=msg&"内存总容量:"&Round((m.totalphysicalmemory/1024^2),2)&"M"+Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)

Setdisplay=wmi.instancesof("Win32_videocontroller")
msg=msg&"显示系统:"+Chr(13)
ForEachvideoIndisplay
msg=msg&video.deviceid&vbTab&video.name&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)


Setdisks=wmi.instancesof("win32_diskdrive")
msg=msg&"硬盘容量:"+Chr(13)
ForEachdIndisks
Ifint(d.size/(1024^3))=0Then
n=Round(d.size/(1024^2),2)&"M"
Else
n=Round(d.size/(1024^3),2)&"G"
EndIf

msg=msg+d.deviceid&"空间为:"&n&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)


MsgBoxmsg,0,"电脑基本特征"

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