2009-06-05 3 views
7

का उपयोग कर फ़ाइल को कैसे चलाएं I VisualBasicScript (.vbs) के साथ फ़ाइल कैसे चला सकता हूं?VisualBasicScript (.vbs)

फ़ाइल 'file.bat' है और यह उसी डीआईआर में .vbs के रूप में स्थित है।

+0

@YourComputerHelpZ - तुम महान जवाब में से एक हो रही बहुत हैं। शायद आपको समझाया जाना चाहिए कि आपका उद्देश्य क्या है। 'File.bat' खोलें और फिर क्या करें? एक संदेश बॉक्स में अपनी सामग्री प्रदर्शित करें, कुछ पाठ संपादित करें, बैच फ़ाइल चलाएं, आदि? – ichiban

+2

"खुला" कहकर, क्या आपका मतलब है "लॉन्च"/"निष्पादित करें"? – Helen

+0

हाँ मैं इसे चलाने के लिए चाहता हूँ। –

उत्तर

18

हाँ मैं इसे चलाने के लिए चाहते हैं।

फिर इस कोशिश:

CreateObject("WScript.Shell").Run "file.bat" 
+0

अच्छा शो हेलेन + 1 – cmsjr

+0

उत्कृष्ट उत्तर। सरल और सटीक। +1 – ichiban

+0

धन्यवाद बहुत बहुत धन्यवाद! –

0

तकनीकी Script Center Script Repository पर कई उदाहरण देखें।

एक साधारण उदाहरण Select and Ping Computers Using a Text File है:

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

हम्म .. वास्तव में आसानी से नहीं मिल सकता है जो मैं ढूंढ रहा हूं। –

+0

मुझे बैच खोलने की आवश्यकता है –

+0

पहला उत्तर सबसे अच्छा – RookieTEC9

0

फ़ाइल खोलने के लिए FileSystemObject

प्रयोग का उपयोग करें:

Const ForReading = 1 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile(".\File.bat", ForReading) 
+0

है, मुझे पता है कि यह मूर्खतापूर्ण है, लेकिन इसका उपयोग कैसे करें ...? –

+0

ऊपर देखें, जो आपको फ़ाइल खोलने के रूप में फ़ाइल के रूप में प्राप्त करेगा, इस मामले में इसे पढ़ने के लिए खोला जा रहा है, आप लेखन या संलग्न करने के लिए भी निर्दिष्ट कर सकते हैं। – cmsjr

+0

नोट ForWriting किसी भी मौजूदा सामग्री को ओवरराइट करेगा। – cmsjr

0
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

उहम्मम्म ... मैं बस इसे खोलना चाहता हूं, और कुछ नहीं। –

-3

चौखट कोड:

jamb(run) "%PWD%\File.bat" & display box(small) with $OUTPUT 

VBS कोड:

set runFile (".\file.bat") 
mode console 
msgbox (runFile) 
+0

हमें आशा है कि इस टिप्पणी ने आपकी मदद की है! – Microsoft

+0

मुझे यकीन नहीं है कि यह प्रश्न का उत्तर देता है –

संबंधित मुद्दे