VBS一些常用函数-持续更新

 

以下原创信息来自http://www.cnblogs.com/zhangbo2012,转载请注明出处

'注册服务,常用于注册第三方dll组件
Function setup()
    dllpath = GetSelfPath & "dll\msxml.dll"
    wsh.run "regsvr32 " & dllpath & " /s"
    Wscript.sleep 1000
End function
 
'获取自身home目录全路径,常用于全路径处理时
Function GetSelfPath()
    SelfPath = fso.GetFile(Wscript.ScriptFullName).ParentFolder.Path
    If Right(SelfPath,1) <> "\" Then SelfPath=SelfPath & "\"
    GetSelfPath=SelfPath
End Function

'格式化输出时间 yyyymmddhh24misss,直接反馈14位的时间,如20130218121500
Function Formattime()
    Formattime = year(date) & string(2-len(month(date)),"0") & month(date) & string(2-len(day(date)),"0") & day(date) & string(2-len(hour(time)),"0") & hour(time) & string(2-len(Minute(time)),"0") & Minute(time) & string(2-len(Second(time)),"0") & Second(time)
End Function

'结束进程
Function EndProcess(processname)
    Set WMI_Obj = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Process", , 48)
    For each obj in WMI_Obj
        if obj.Caption = processname  then 
            obj.Terminate
        end if
    next
End Function


'读取文件行数
Function Readfilelinecnt(filename)
    set fso = CreateObject("Scripting.Filesystemobject")
    cnt = 0
    Set rf=fso.opentextfile(filename,1)  
    do while rf.atendofstream=0
        tempstr=rf.readline
        cnt=cnt+1
    loop
    rf.close
    Readfilelinecnt = cnt
End Function

以上原创信息来自http://www.cnblogs.com/zhangbo2012,转载请注明出处

 

'定时
start_time    = "2014/03/15 02:45" 
call  sleepto(start_time)
Function sleepto (d)
    sleeputil = 10*1000
    do 
        st = datediff("s",now,d)
        if st<20 then sleeputil=1*1000
        if st > 0 then 
            wscript.sleep sleeputil
            else
            exit do
        end if     
    loop
End Function

以上原创信息来自http://www.cnblogs.com/zhangbo2012,转载请注明出处

posted @ 2014-03-10 20:55  zhangbo2012  阅读(353)  评论(0编辑  收藏  举报