Как выполнить использование файла VisualBasicScript (.vbs)

Вы можете использовать функции is_page () и is_single () .

7
задан tshepang 15 February 2014 в 12:05
поделиться

4 ответа

да, я хочу запустить его.

Тогда попробуйте следующее:

CreateObject("WScript.Shell").Run "file.bat"
18
ответ дан 6 December 2019 в 14:09
поделиться

Используйте FileSystemObject

Использование для открытия файла:

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(".\File.bat", ForReading)
0
ответ дан 6 December 2019 в 14:09
поделиться

См. Множество примеров на сайте technet Script Center Script Repository .

Простым примером является Выбор компьютеров и проверка связи с ними с помощью текстового файла :

On Error Resume Next

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt", ForReading)

strComputers = objTextFile.ReadAll
objTextFile.Close

arrComputers = Split(strComputers, vbCrLf)
Set objShell = CreateObject("WScript.Shell")

For Each strComputer In arrComputers

    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer
    Set objExecObject = objShell.Exec(strCommand)
    strText = objExecObject.StdOut.ReadAll
    If Instr(strText, "Reply") > 0 Then

    ' =====================================================================
    ' Insert your code here
    ' =====================================================================

        Set objWMIService = GetObject _
            ("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery _
            ("Select * From Win32_OperatingSystem")
        For Each objItem In ColItems
            Wscript.Echo strComputer & ": " & objItem.Caption
        Next


    Else
        Wscript.Echo strComputer & " could not be reached."
    End If

Next
0
ответ дан 6 December 2019 в 14:09
поделиться
function getFileInfo(filePath)
    dim fso, fileObj, outMsg
    set fso = createobject("Scripting.FileSystemObject")
    set fileObj = fso.getfile(filePath)
    outMsg = ""
    outMsg = outMsg & " Created: " & fileObj.DateCreated & vbcrlf
    outMsg = outMsg & " Last Accessed: " & fileObj.DateLastAccessed & vbcrlf
    outMsg = outMsg & " Last Modified: " & fileObj.DateLastModified & vbcrlf
    outMsg = outMsg & " File Type: " & fileObj.Type & vbcrlf
    if fileObj.attributes and 0 then
        outMsg = outMsg & " File Attributes: Normal File"
    else
        outMsg = outMsg & " File Attributes: "
        if fileObj.attributes and 1 then
            outMsg = outMsg & "Read Only "
        end if
        if fileObj.attributes and 2 then
            outMsg= outMsg & "Hidden "
        end if
        if fileObj.attributes and 4 then
            outMsg= outMsg & "System "
        end if
        if fileObj.attributes and 8 then
            outMsg= outMsg & "Volume "
        end if
        if fileObj.attributes and 16 then
            outMsg= outMsg & "Directory "
        end if
        if fileObj.attributes and 32 then
            outMsg= outMsg & "Archive "
        end if
        if fileObj.attributes and 1024 then
            outMsg= outMsg & "Link "
        end if
        if fileObj.attributes and 2048 then
            outMsg= outMsg & "Compressed "
        end if
    end if
    set fileObj = nothing
    set fso = nothing
    getFileInfo = outMsg
end function
0
ответ дан 6 December 2019 в 14:09
поделиться
Другие вопросы по тегам:

Похожие вопросы: