发布新日志

  • asp语言运行服务器上的cmd命令

    2010-07-15 13:41:33

    代码:

    <html>
    <body>

    <%
    response.write("Hello World!")
    %>
    <%
    Set WshShell = CreateObject("Wscript.Shell")
    IsSuccess = WshShell.Run ("C:\WINDOWS\system32\cmd.exe /c copy d:\hosts d:\temp" ,1, True)
    'copy d:\hosts d:\temp根据需要修改

    If IsSuccess = 0 Then
    Response.write "命令成功执行" & IsSuccess
    else
    Response.write "命令执行失败!" & IsSuccess
    end if
    %>

    </body>
    </html>

    注意:IIS访问帐号要有cmd.exe的控制权。
  • Making PC's speak with SAPI.SoVice(转载)

    2009-10-25 11:18:15

    让PC读指定的文本

    Set bjTTS=CreateObject("SAPI.SpVoice")
    with objtts
    .volume=100
    .speak "Making PC's Speak with SAPI.SpVoice. Not a useful script, but a little fun never the less."
    end with

    'bat下可以调用
    'mshta vbscript.:createobject("sapi.spvoice").speak("I LOVE YOU.")

    URL:http://www.visualbasicscript.com/m63061.aspx

    备注:
    like all objects to be created in VBS there are more than just the 3 properties i actually use here.

    SAPI.SpVoice Properties:

    '.Pause = pause speaking
    '.resume = resume after pause
    '.Rate = speed at which voice speaks
    '.Voice = you can use set and a voice value to change the voice (if multiple exist on machine)
    '.Volume = volume of voice (not system volume, just voice)
    '.WaitUntilDone = wait until done - dont know how else to say that ;)


    how to set the 3 useful voice Properties

     'create object and then setup the properties
     Set VObj = CreateObject("SAPI.SpVoice")
       with VObj
           Set .voice = .getvoices.item(0)
           .Volume = 100
           .Rate = 3
       end with
     


    Please notice that the '.getvoices.item(0)' has refrenced item 0, the getvoices is in an array (if multiple are present)

    to retrive the names of the values you could do a simple call like:

     'create object and then loop for the index and name
     Set VObj = CreateObject("SAPI.SpVoice")
       For Each Voice In VObj.getvoices
           I = I + 1
           msgbox "" & (I - 1) & " - " & Voice.GetDescription
       Next
     

    i dont know, its just one of those toy codes any ways
  • Use a VBScript script to ping a machine(转载)

    2009-10-20 14:44:27

    The Windows Management Instrumentation (WMI) classes in Windows XP and later provide a Win32_PingStatus object that you can use to ping a machine. The following script, which you can download at http://www.windowsitpro.com/articles/download/vbpinging.zip uses this object to ping a passed hostname or IP address. Because of space constraints, some lines wrap to two lines.

    Option Explicit

    Dim strHost

    ' Check that all arguments required have been passed.
    If Wscript.Arguments.Count < 1 Then
    Wscript.Echo "Arguments <Host> required. For example:" & vbCrLf _
    & "cscript. vbping.vbs savdaldc01"
    Wscript.Quit(0)
    End If

    strHost = Wscript.Arguments(0)

    if Ping(strHost) = True then
    Wscript.Echo "Host " & strHost & " contacted"
    Else
    Wscript.Echo "Host " & strHost & " could not be contacted"
    end if

    Function Ping(strHost)

    dim objPing, objRetStatus

    set bjPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
    ("select * from Win32_PingStatus where address = '" & strHost & "'")

    for each objRetStatus in objPing
    if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
    Ping = False
    'WScript.Echo "Status code is " & objRetStatus.StatusCode
    else
    Ping = True
    'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
    'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
    'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
    end if
    next
    End Function

    You can modify this script. to do whatever you need. Notice that I've commented out some lines (') that give more information about the ping attempt, but you can leave the lines in if the information would be useful to you. Run the script. by using the following command:

    D:\projects\VBScripts>cscript. vbping.vbs savdalex01
    which will give the following sample output:

    Host savdalex01 contacted

    You can find more information about Win32_PingStatus at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_pingstatus.asp .

    URL:http://windowsitpro.com/article/articleid/48449/how-can-i-use-a-vbscript-script-to-ping-a-machine.html

    国内实例

    要添加计算机的话按照第二行的格式添加即可
    还有就是把strOutputFilePath改成你自己的路径

    1. arrComputers = Array(_
    2. "127.0.0.1",_
    3. "172.16.100.4",_
    4. "172.16.100.6")
    5. strDate = Year(Date) & Month(Date) & Day(Date)
    6. strOutputFilePath = "e:\CheckResult - " & strDate & ".txt"

    7. Set bjFSO = CreateObject("Scripting.FileSystemObject")
    8. Set bjFile = objFSO.CreateTextFile(strOutputFilePath)
    9. For Each objComputer In arrComputers
    10.         If Ping(objComputer) = True Then
    11.                 objFile.WriteLine objComputer & " : UP"
    12.         Else
    13.                 objFile.WriteLine objComputer & " : DOWN"
    14.         End If
    15. Next
    16. objFile.Close

    17. Function Ping(strComputer)
    18.         Set bjWMIService = GetObject("winmgmts:\\.\root\cimv2")
    19.         Set colItems = objWMIService.ExecQuery("Select * From Win32_PingStatus Where Address='" & strComputer & "'")
    20.         For Each objItem In colItems
    21.                         Select case objItem.StatusCode
    22.                                 Case 0
    23.                                         Ping = True
    24.                                 Case Else
    25.                                         Ping = False
    26.                         End select
    27.                 Exit For
    28.         Next
    29. End Function

    URL:http://bbs.winos.cn/thread-79977-1-1.html

  • 获取纯文本中的指定信息(VBS)

    2009-09-04 20:35:17

    Const MyFile = "D:\1\MyFTPthroughputvalue.txt"
    Const ResourceFile = "D:\1\ftpthroughput20090827.txt"
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    FindString()

    Sub FindString()
    Dim fs,f,ts,t,st,st2,st3,st4,st5,st6
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(ResourceFile)
    Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
    Do While ts.AtEndOfStream <> True
        t = ts.ReadLine()
        st3 = InStr(t,"====")
        st = InStr(t,"D:\Temp\bigfile")
        st2 = InStr(t,"ftp:")
        If st3 <> 0 then  MyData(t)
        If st <> 0 then   MyData("#################################") :MyData(t)
        If st2 <> 0 Then MyData(t) :st4 = Split(t):st5 =Split(st4(5),"S") :st6 = st4(1)/st5(0)/1024/1024*8:MyData(st6)
    Loop
    End Sub

    Sub MyData(t)
    Dim fs,f
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile(MyFile,ForAppending,TristateUseDefault)
    f.WriteLine(t)
    f.Close
    End Sub
  • 文件拷贝和记录传输值和运行时错误代码

    2009-09-03 14:11:12

    On Error Resume Next
    Const verwriteExisting = True    
    Const logpath = "Sambathroughput.txt"    '定义Log文件位置和名字
    Const Times = 2    '定义循环次数
    Log()
    writeLine("Title" & Now)    '在Log中写注释性文字
    TextStreamText()
    'set ws=wscript.createobject("wscript.shell")
    'ws.run ".\call.bat"

    '########################################################################
    Sub TextStreamText
        Const ForReading =1
        Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse =0
        Dim fs,f,ts,s,a
        Set fs=CreateObject("Scripting.FileSystemObject")
        Set f=fs.GetFile("copypath.txt")    '定义读取信息的文件位置和名字
        Set ts=f.OpenAsTextStream(ForReading,TristateUseDefault)
        '获取文件中的Copy信息,执行copy任务
        Do While ts.AtEndOfLine <> True        
            s= ts.Readline()
            WriteLine(s)
            a=Split(s)
            copyfile a(0), a(1)
        Loop
        
        ts.close
    End Sub

    Function copyfile(resource,destination)        '执行文件拷贝函数
        On Error Resume Next
        Dim runstatus,i
        i=0
        Set bjcopy=CreateObject("scripting.FileSystemobject")
        Dim startime,endtime,totaltime,throughput_result,sum,file_size
        sum=0
       
        Do While i<times
            startime=Now
            fscopy=objcopy.CopyFile(resource,destination,OverwriteExisting)
            endtime=Now
            runstatus = Err        '获取VBS运行错误的代码
            If runstatus = 0 Then        '如果运行正常,计算Throughput,反之,把错误代码写入Log文件
                totaltime=DateDiff("S",startime,endtime)
                Set bjsize=objcopy.GetFile(resource)        '获取源文件Size
                file_size=objsize.Size
                throughput_result=file_size*8/1024/1024/totaltime
                writeLine(throughput_result & " Mb/s")
                writeLine("Success")
                sum=sum+throughput_result
                i=i+1
            Else
                writeLine("Fail" & " error code " & runstatus)    '把错误代码写入Log文件
                Exit Do
            End If
        Loop
       
        Dime average
        average=sum/i
        writeLine("average value:" & average)        '计算Throughput平均值
        writeLine("###########################################")
    End Function

    Sub writeLine(Content)        '执行写Log信息
        Set bjFSO=CreateObject("Scripting.filesystemobject")
        Set fs=objFSO.OpenTextFile(logpath,8,False)
        fs.WriteLine(content)
        fs.Close
        Set fs=Nothing
        Set bjFSO=nothing
    End Sub

    Sub createplaintxt()        '执行创建Log文件
        Set bjtxt=CreateObject("scripting.Filesystemobject")
        Set createtxt=objtxt.CreateTextFile(logpath,OverwriteExisting)
        createtxt.Close
        Set createtxt=Nothing
        Set bjtxt=Nothing
    End Sub

    Sub fileExist()            '判断Log文件是否存在
        Set fs=CreateObject("Scripting.FileSystemObject")
        If fs.FileExists(logpath) Then
            Exit Sub
        Else
            createplaintxt()
        End If
        Set fs=Nothing
    End Sub

    Sub Log()    '准备Log文件
        fileExist()
    End Sub


    附文本文件:
    档名:copypath.txt
    内容:
    D:\x\x.exe Z:\x\  X文件上传到Z盘的速度
    Z:\x\x.exe D:\temp\ X文件下载到本地PC的速度
  • VBScript中有关字符串处理的函数

    2009-08-30 21:25:57

    Chr(charcode)
    返回与指定的 ANSI 字符代码相对应的字符。

    InStr 函数
    描述
    返回某字符串在另一字符串中第一次出现的位置。

    InstrRev 函数
    描述
    返回某字符串在另一个字符串中出现的从结尾计起的位置。

    Join 函数
    描述
    返回一个字符串,此字符串由包含在数组中的许多子字符串联接创建。

    Left 函数
    描述
    返回指定数目的从字符串的左边算起的字符。

    Len 函数
    描述
    返回字符串内字符的数目,或是存储一变量所需的字节数。

    LTrim、RTrim 和 Trim 函数
    描述
    返回不带前导空格 (LTrim)、后续空格 (RTrim) 或前导与后续空格 (Trim) 的字符串副本。

    Mid 函数
    描述
    从字符串中返回指定数目的字符。

    Replace 函数
    描述
    返回字符串,其中指定数目的某子字符串被替换为另一个子字符串。

    Right 函数
    描述
    从字符串右边返回指定数目的字符。

    Space 函数
    描述
    返回由指定数目的空格组成的字符串。

    Split 函数
    描述
    返回基于 0 的一维数组,其中包含指定数目的子字符串。

    StrComp 函数
    描述
    返回指示字符串比较结果的值。

    StrReverse 函数
    描述
    返回字符串,此字符串与指定字符串顺序相反。

    TypeName 函数
    描述
    返回一个字符串,提供有关变量的 Variant 子类型信息。

    参考网站:
    http://msdn.microsoft.com/en-us/library/3ca8tfek(VS.85).aspx
    http://www.w3school.com.cn/vbscript/vbscript_ref_functions.asp

  • VB动态数组的定义方法——ReDim语句

    2009-08-30 20:46:00

    描述
    用于过程级声明动态数组变量并分配或重新分配存储空间。
    语法
    ReDim [Preserve] varname(subscripts) [, varname(subscripts)] . . .

    ReDim 语句语法有以下部分:

    部分 描述
    Preserve 当更改现有数组最后一维的大小时保留数据。
    varname 变量名,遵循标准变量命名约定。
    subscripts 数组变量的维数,最多可以声明 60 维数组。subscripts 参数语法格式如下:

    upper [,upper] . . .

    数组的下界总是零。

    说明
    ReDim 语句通常用于指定或修改动态数组的大小,这些数组已用带有空括号的 PrivatePublicDim 语句(没有维数下标)正式声明过。可以重复使用 ReDim 语句更改数组维数和元素数目。

    如果使用了 Preserve 关键字,就只能调整数组最后维的大小,并且不能改变数组的维数。例如,如果数组只有一维,就可以修改该数组的大小,因为该维是最后的也是仅有的一维。但是,如果数组有两个或更多维,就只能改变末维的大小并保留数组内容。下面的样例示范了如何不删除动态数组的原有内容而又增加末维的大小。

    ReDim X(10, 10, 10)
    . . .
    ReDim Preserve X(10, 10, 15)

    小心 如果减小数组的大小,则将丢失被排除的元素中的数据。

    变量初始化时,数值变量初始化为 0,字符串变量初始化为零长度字符串 ("")。在使用引用对象的变量前,必须使用 Set 语句将某个现有对象赋予该变量。在进行对象赋值以前,已声明的对象变量有特定值 Nothing

    注意:
    ReDim语句只能用于动态数组,它可以改变每一维的大小,但不能改变维数。
    在同一程序中,ReDim语句还可以多次使用。在用:ReDim语句重新定义数组之前,可以使用:Erase语句将原来的数组删除,

    练习一:
    ReDim x(0)
    Dim i

    For i=0 To 2
    ReDim x(i)
    x(i) = i
    MsgBox x(i)
    i=i+1
    Next

Open Toolbar