का उपयोग कर फ़ाइल को कैसे चलाएं I VisualBasicScript (.vbs) के साथ फ़ाइल कैसे चला सकता हूं?VisualBasicScript (.vbs)
फ़ाइल 'file.bat' है और यह उसी डीआईआर में .vbs के रूप में स्थित है।
का उपयोग कर फ़ाइल को कैसे चलाएं I VisualBasicScript (.vbs) के साथ फ़ाइल कैसे चला सकता हूं?VisualBasicScript (.vbs)
फ़ाइल 'file.bat' है और यह उसी डीआईआर में .vbs के रूप में स्थित है।
तकनीकी 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
हम्म .. वास्तव में आसानी से नहीं मिल सकता है जो मैं ढूंढ रहा हूं। –
मुझे बैच खोलने की आवश्यकता है –
पहला उत्तर सबसे अच्छा – RookieTEC9
फ़ाइल खोलने के लिए FileSystemObject
प्रयोग का उपयोग करें:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(".\File.bat", ForReading)
है, मुझे पता है कि यह मूर्खतापूर्ण है, लेकिन इसका उपयोग कैसे करें ...? –
ऊपर देखें, जो आपको फ़ाइल खोलने के रूप में फ़ाइल के रूप में प्राप्त करेगा, इस मामले में इसे पढ़ने के लिए खोला जा रहा है, आप लेखन या संलग्न करने के लिए भी निर्दिष्ट कर सकते हैं। – cmsjr
नोट ForWriting किसी भी मौजूदा सामग्री को ओवरराइट करेगा। – cmsjr
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
उहम्मम्म ... मैं बस इसे खोलना चाहता हूं, और कुछ नहीं। –
चौखट कोड:
jamb(run) "%PWD%\File.bat" & display box(small) with $OUTPUT
VBS कोड:
set runFile (".\file.bat")
mode console
msgbox (runFile)
हमें आशा है कि इस टिप्पणी ने आपकी मदद की है! – Microsoft
मुझे यकीन नहीं है कि यह प्रश्न का उत्तर देता है –
@YourComputerHelpZ - तुम महान जवाब में से एक हो रही बहुत हैं। शायद आपको समझाया जाना चाहिए कि आपका उद्देश्य क्या है। 'File.bat' खोलें और फिर क्या करें? एक संदेश बॉक्स में अपनी सामग्री प्रदर्शित करें, कुछ पाठ संपादित करें, बैच फ़ाइल चलाएं, आदि? – ichiban
"खुला" कहकर, क्या आपका मतलब है "लॉन्च"/"निष्पादित करें"? – Helen
हाँ मैं इसे चलाने के लिए चाहता हूँ। –