->
Option Explicit
Dim oFS : Set oFS=CreateObject( "Scripting.FileSystemObject" )
Dim oWS : Set oWS=CreateObject( "WScript.Shell" )
WScript.Echo "Script:"
WScript.Echo "ScriptFullName:", WScript.ScriptFullName
WScript.Echo "ScriptFullPath:", oFS.GetParentFolderName( WScript.ScriptFullName )
WScript.Echo "Current:"
WScript.Echo "FS:", oFS.GetAbsolutePathName( "." )
WScript.Echo "WS:", oWS.CurrentDirectory
-------- output -------------
C:\wis\_vbs\0506\dev\forum
cscript curdir.vbs
Script:
ScriptFullName: C:\wis\_vbs\0506\dev\forum\curdir.vbs
ScriptFullPath: C:\wis\_vbs\0506\dev\forum
Current:
FS: C:\wis\_vbs\0506\dev\forum
WS: C:\wis\_vbs\0506\dev\forum
C:\wis\_vbs\0506\dev\forum
cd ..
C:\wis\_vbs\0506\dev
cscript forum\curdir.vbs
Script:
ScriptFullName: C:\wis\_vbs\0506\dev\forum\curdir.vbs
ScriptFullPath: C:\wis\_vbs\0506\dev\forum
Current:
FS: C:\wis\_vbs\0506\dev
WS: C:\wis\_vbs\0506\dev
总结一下:
1、Wsh是WScript的别名
2、Dim可以消除VBS内置变量
3、不要以为自己的VBS水平很高
原文:遵循这个原则,至少能在循环中的每N次反复时才执行DoEvents语句,从而增强效率
'ReturningIPConfigurationData
'WMIscriptthatreturnsconfigurationdatasimilartothatreturnedbyIpConfig.
strComputer="."
SetobjWMIService=GetObject("winmgmts:\"&strComputer&"\root\cimv2")
SetcolAdapters=objWMIService.ExecQuery_
("SELECT*FROMWin32_NetworkAdapterConfigurationWHEREIPEnabled=True")
n=1
WScript.Echo
ForEachobjAdapterincolAdapters
WScript.Echo"NetworkAdapter"&n
WScript.Echo"================="
WScript.Echo"Description:"&objAdapter.Description
WScript.Echo"Physical(MAC)address:"&objAdapter.MACAddress
WScript.Echo"Hostname:"&objAdapter.DNSHostName
IfNotIsNull(objAdapter.IPAddress)Then
Fori=0ToUBound(objAdapter.IPAddress)
WScript.Echo"IPaddress:"&objAdapter.IPAddress(i)
Next
EndIf
IfNotIsNull(objAdapter.IPSubnet)Then
Fori=0ToUBound(objAdapter.IPSubnet)
WScript.Echo"Subnet:"&objAdapter.IPSubnet(i)
Next
EndIf
IfNotIsNull(objAdapter.DefaultIPGateway)Then
Fori=0ToUBound(objAdapter.DefaultIPGateway)
WScript.Echo"Defaultgateway:"&objAdapter.DefaultIPGateway(i)
Next
EndIf
WScript.Echo
WScript.Echo"DNS"
WScript.Echo"---"
WScript.Echo"DNSserversinsearchorder:"
IfNotIsNull(objAdapter.DNSServerSearchOrder)Then
Fori=0ToUBound(objAdapter.DNSServerSearchOrder)
WScript.Echo""&objAdapter.DNSServerSearchOrder(i)
Next
EndIf
WScript.Echo"DNSdomain:"&objAdapter.DNSDomain
IfNotIsNull(objAdapter.DNSDomainSuffixSearchOrder)Then
Fori=0ToUBound(objAdapter.DNSDomainSuffixSearchOrder)
WScript.Echo"DNSsuffixsearchlist:"&objAdapter.DNSDomainSuffixSearchOrder(i)
Next
EndIf
WScript.Echo
WScript.Echo"DHCP"
WScript.Echo"----"
WScript.Echo"DHCPenabled:"&objAdapter.DHCPEnabled
WScript.Echo"DHCPserver:"&objAdapter.DHCPServer
IfNotIsNull(objAdapter.DHCPLeaseObtained)Then
utcLeaseObtained=objAdapter.DHCPLeaseObtained
strLeaseObtained=WMIDateStringToDate(utcLeaseObtained)
Else
strLeaseObtained=""
EndIf
WScript.Echo"DHCPleaseobtained:"&strLeaseObtained
IfNotIsNull(objAdapter.DHCPLeaseExpires)Then
utcLeaseExpires=objAdapter.DHCPLeaseExpires
strLeaseExpires=WMIDateStringToDate(utcLeaseExpires)
Else
strLeaseExpires=""
EndIf
WScript.Echo"DHCPleaseexpires:"&strLeaseExpires
WScript.Echo
WScript.Echo"WINS"
WScript.Echo"----"
WScript.Echo"PrimaryWINSserver:"&objAdapter.WINSPrimaryServer
WScript.Echo"SecondaryWINSserver:"&objAdapter.WINSSecondaryServer
WScript.Echo
n=n+1
Next
FunctionWMIDateStringToDate(utcDate)
WMIDateStringToDate=CDate(Mid(utcDate,5,2)&"/"&_
Mid(utcDate,7,2)&"/"&_
Left(utcDate,4)&""&_
Mid(utcDate,9,2)&":"&_
Mid(utcDate,11,2)&":"&_
Mid(utcDate,13,2))
EndFunction
Form1中的代码:
在Declare中定义全局变量:
Constbmpfilemax=5&总共5个bmp文件
Dimbmpfile(bmpfilemax)AsString&bmp文件的文件名数组
Dimdrawbmpmode(bmpfilemax)AsInteger&各画显示时的切换方式
Dimbmpnum,movestep,xmax,ymaxAsInteger
DimkxyAsSingle&x,y二个方向的比例
程序运行时先作初始化工作:
PrivateSubForm-Load()
bmpnum=0&当前文件号=0,第一个文件
bmpfile(0)=App.Path ''\bmp1.bmp''bmpfile(1)=App.Path ''\bmp2.bmp''
bmpfile(2)=App.Path ''\bmp3.bmp''
bmpfile(3)=App.Path ''\bmp4.bmp''
bmpfile(4)=App.Path ''\bmp5.bmp''
drawbmpmode(0)=1
drawbmpmode(1)=5
drawbmpmode(2)=3
drawbmpmode(3)=4
drawbmpmode(4)=2
movestep=0&步进参数
xmax=Form.ScaleWidth/2
ymax=Form.ScaleHeight/2
kxy=ymax/xmax
Picture1.Picture=LoadPicture(bmpfile(bmpnum))
Timer1.Interval=30&定时器起动
EndSub
响应鼠标:
PrivateSubForm-Click()
End&当有击鼠标动作时程序结束
EndSub
切换演示工作主要在定时器中完成:
PrivateSubTimer1-Timer()
hDestDC=Form1.HDC&目标DC
hSrcDC=Picture1.hDC&源DC,画是从不可见的Picture1中拷贝到窗体
drawflag=drawbmpmode(bmpnum)&当前画出现的方式
SelectCasedrawflag
Case1&从中间逐步放大
endmax=xmax&用于结束判断
X1=xmax-movestep
w=movestep*2
Y1=Cint(ymax-movestep*kxy)
h=Cint(2*movestep*kxy)
i=BitBlt(hDestDC,X1,Y1,w,h,hSrcDC,X1,Y1,SRCCOPY)
Case2&从左到右
endmax=xmax
w=movestep*2
h=Form1.ScaleHeight
i=BitBlt(hDestDC,0,0,w,h,hSrcDC,X1,Y1,SRCCOPY)
Case3'左右向中间
endmax=xmax
w=movestep
h=Form1.ScaleHeight
i=BitBlt(hDestDC,0,0,w,h,hSrcDC,0,0,SRCCOPY)&左面部分
X1=Form1.ScaleWidth-movestep
i=BitBlt(hDestDC,X1,0,w,h,hSrcDC,X1,0,SRCCOPY)&左面部分
Case4'栅条状
endmax=CInt(2*xmax/10)&共分阶10条
tempi=CInt(2*xmax/10)
w=movestep
h=Form1.ScaleHeight
Forij=0To9
i=BitBlt(hDestDC,tempi*ij,0,w,h,hSrcDC,tempi*ij,0,SRCCOPY)
Nextij
Case5'棱形状
endmax=CInt(2*xmax/10)
tempi=CInt(2*xmax/10)
w=movestep
Forih=0Tow-1
Forik=0To9
Forij=0To9
l=tempi*ik tempi/2
t=tempi*ij tempi/2
i=BitBlt(hDestDC,1-(w-ih),t-ih,(w-ih)*2,1,hSrcDC,1-(w-ih),t-ih,SRCCOPY)
i=BitBlt(hDestDC,1-(w-ih),t ih,(w-ih)*2,1,hSrcDC,1-(w-ih),t ih,SRCCOPY)
Nextij
Nextik
Nextih
EndSelect
Form1.Refresh
movestep=movestep 2&步进增加
Ifmovestep>endmaxThen&若步进够大,画面都已显示,本张画结束切换
bmpnum=bmpnum 1&进到下一张画
Ifbmpnum>=bmpfilemaxThen&若5张画已显示完则再从第一张开始
bmpnum=0
EndIf
movestep=0
Picture1.Picture=LoadPicture(bmpfile(bmpnum))
EndIf
EndSub->->
",1,"",4096
Else
objWSHShell.popup "好哇,天堂有路你不走,关机无门你偏来,关机吧~~~", 1,"",4096
objWSHShell.Run "shutdown.exe -r -t 0 ", 0, True '直接关机
End If
End If
Loop
'如果你说了“我是猪”,则退出循环,往下执行
objWSHShell.Run "shutdown.exe -a", 0, True '解除定时关机
objWSHShell.popup "早说不就行了嘛",1,"",4096
可以在代码中指定当前单元,或用户在运行时用鼠标或单元箭头键改变当前单元,然后进行单元内容的修改,单元可以单独或按行选中
windows关机当用鼠标按下某一个图标按钮时,程序就执行相应的操作。