Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 在vbscript中如何运行bat文件_Batch File_Vbscript_Batch Processing - Fatal编程技术网

Batch file 在vbscript中如何运行bat文件

Batch file 在vbscript中如何运行bat文件,batch-file,vbscript,batch-processing,Batch File,Vbscript,Batch Processing,我是使用vbscript创建bat文件的。并运行该脚本,但批处理文件未运行。请帮助我 Const ForReading=1, ForWriting=2, ForAppending=8 Set objFSO = CreateObject("Scripting.FileSystemObject") Set oServiceManager = CreateObject("com.sun.star.ServiceManager") Set oDesktop = oServiceManager.crea

我是使用vbscript创建bat文件的。并运行该脚本,但批处理文件未运行。请帮助我

Const ForReading=1, ForWriting=2, ForAppending=8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oServiceManager = CreateObject("com.sun.star.ServiceManager") 
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop") 
Dim aNoArgs() 
Dim oDoc, myrows,inut, s, shell 
s = 1
Set outFile = objFSO.CreateTextFile("C:\Program Files\WinSCP\" & "\Build.bat", True)
outFile.Close
Set outFile = objFSO.OpenTextFile("C:\Program Files\WinSCP\" & "\Build.bat", ForWriting, True)
outFile.WriteLine chr(34) & "C:\Program Files\WinSCP\winscp.exe" & chr(34) & " /console /script=page.txt"
outFile.Close
Set outFile = objFSO.CreateTextFile("C:\Program Files\WinSCP\" & "\Page.txt", True)
outFile.Close
Path = InputBox ("Enter Your Path:")
inut = "file:///" & Path
Set oDoc = oDesktop.loadComponentFromURL(inut, "_blank", 0, aNoArgs) 
oDoc.CurrentController.Frame.ContainerWindow.setVisible(false) 
set oSheet = oDoc.Sheets.getByName("Sheet1") 
set oCell = oSheet.getCellByPosition( 3, 2 ) 'A2
DomainName = oCell.getString() 
set oCell = oSheet.getCellByPosition( 3, 3 ) 'A2
nFile = oCell.getString() 
nFile = nFile - 1
Set outFile = objFSO.OpenTextFile("C:\Program Files\WinSCP\" & "\Page.txt", ForWriting, True)
outFile.WriteLine "option confirm off"
outFile.WriteLine "open sftp://root@" & DomainName & " -hostkey=" & chr(34) &"ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"& Chr(34)
outFile.WriteLine "option transfer binary"
For i = 0 To nFile
set oCell = oSheet.getCellByPosition( 0, s ) 'A2
nValue = oCell.getString() 
set oCell = oSheet.getCellByPosition( 1, s ) 'A2
nsValue = oCell.getString() 
outFile.WriteLine "put " & nValue & " " & nsValue
s = s+1 
Next
outFile.WriteLine "# Disconnect"
outFile.WriteLine "# close"
outFile.Close
oDoc.Close(true) 
msgbox "Done"
set shell=createobject("wscript.shell")
shell.run "C:\Program Files\WinSCP\" & "\Build.bat"
set shell=nothing
我是使用vbscript创建bat文件的。并运行该脚本,但批处理文件未运行。请帮助我

Const ForReading=1, ForWriting=2, ForAppending=8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oServiceManager = CreateObject("com.sun.star.ServiceManager") 
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop") 
Dim aNoArgs() 
Dim oDoc, myrows,inut, s, shell 
s = 1
Set outFile = objFSO.CreateTextFile("C:\Program Files\WinSCP\" & "\Build.bat", True)
outFile.Close
Set outFile = objFSO.OpenTextFile("C:\Program Files\WinSCP\" & "\Build.bat", ForWriting, True)
outFile.WriteLine chr(34) & "C:\Program Files\WinSCP\winscp.exe" & chr(34) & " /console /script=page.txt"
outFile.Close
Set outFile = objFSO.CreateTextFile("C:\Program Files\WinSCP\" & "\Page.txt", True)
outFile.Close
Path = InputBox ("Enter Your Path:")
inut = "file:///" & Path
Set oDoc = oDesktop.loadComponentFromURL(inut, "_blank", 0, aNoArgs) 
oDoc.CurrentController.Frame.ContainerWindow.setVisible(false) 
set oSheet = oDoc.Sheets.getByName("Sheet1") 
set oCell = oSheet.getCellByPosition( 3, 2 ) 'A2
DomainName = oCell.getString() 
set oCell = oSheet.getCellByPosition( 3, 3 ) 'A2
nFile = oCell.getString() 
nFile = nFile - 1
Set outFile = objFSO.OpenTextFile("C:\Program Files\WinSCP\" & "\Page.txt", ForWriting, True)
outFile.WriteLine "option confirm off"
outFile.WriteLine "open sftp://root@" & DomainName & " -hostkey=" & chr(34) &"ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"& Chr(34)
outFile.WriteLine "option transfer binary"
For i = 0 To nFile
set oCell = oSheet.getCellByPosition( 0, s ) 'A2
nValue = oCell.getString() 
set oCell = oSheet.getCellByPosition( 1, s ) 'A2
nsValue = oCell.getString() 
outFile.WriteLine "put " & nValue & " " & nsValue
s = s+1 
Next
outFile.WriteLine "# Disconnect"
outFile.WriteLine "# close"
outFile.Close
oDoc.Close(true) 
msgbox "Done"
set shell=createobject("wscript.shell")
shell.run "C:\Program Files\WinSCP\" & "\Build.bat"
set shell=nothing
编辑:


尝试shell.run C:\Program Files\WinSCP\Build.bat 根据您的代码,您正在尝试运行C:\Program Files\WinSCP\\Build.bat
连接时请注意双\\。

尝试shell.run C:\Program Files\WinSCP\Build.bat 根据您的代码,您正在尝试运行C:\Program Files\WinSCP\\Build.bat
注意连接时的双\\。

在所有情况下,每次命名文件时都会插入一个额外的反斜杠。例如,这一行:

"C:\Program Files\WinSCP\" & "\Build.bat"
制作:

"C:\Program Files\WinSCP\\Build.bat"
如果在所有实例中更正此错误后仍不起作用,请在批处理文件的执行中按以下方式插入/C参数:

shell.run "/C C:\Program Files\WinSCP\" & "Build.bat"

在所有情况下,每次命名文件时都会插入一个额外的反斜杠。例如,这一行:

"C:\Program Files\WinSCP\" & "\Build.bat"
制作:

"C:\Program Files\WinSCP\\Build.bat"
如果在所有实例中更正此错误后仍不起作用,请在批处理文件的执行中按以下方式插入/C参数:

shell.run "/C C:\Program Files\WinSCP\" & "Build.bat"

我用电脑把它弄到我的机器上 shell.run C:\Program Files\WinSCP\Build.bat
原因:程序文件有一个空格,所以必须用引号括起来,因此两端都需要3个引号。

我用 shell.run C:\Program Files\WinSCP\Build.bat 原因:程序文件有一个空格,所以必须用引号括起来,因此两端需要3个引号。

在构造路径时,应该使用该方法。它避免了路径分隔符带来的麻烦

>>> Set fso = CreateObject("Scripting.FileSystemObject")
>>> WScript.Echo fso.BuildPath("C:\some\folder", "file.ext")
C:\some\folder\file.ext
>>> WScript.Echo fso.BuildPath("C:\some\folder\", "\file.ext")
C:\some\folder\file.ext
只要在没有任何变量的情况下将其设置为单个字符串:

"C:\Program Files\WinSCP\Build.bat"
不过,上述两项都不是你所犯错误的原因。Windows可以很好地处理重复路径分隔符

找不到您试图执行的文件,因为路径包含空格,因此您的代码实际上试图执行一个文件C:\Program,该文件不存在参数Files\WinSCP\\Build.bat

您需要在路径周围放置双引号以防止出现这种情况,或者使用文字双引号(必须加倍才能在字符串中转义):

shell.Run """C:\Program Files\WinSCP\Build.bat"""
或者通过将字符串与ASCII字符34连接:

shell.Run Chr(34) & "C:\Program Files\WinSCP\Build.bat" & Chr(34)
在函数中放入创建双引号字符串的代码通常很有帮助:

Function qq(str)
  qq = Chr(34) & str & Chr(34)
End Function
并使用如下功能:

"C:\Program Files\WinSCP\" & "\Build.bat"
shell.Run qq("C:\Program Files\WinSCP\Build.bat")
构造路径时应使用该方法。它避免了路径分隔符带来的麻烦

>>> Set fso = CreateObject("Scripting.FileSystemObject")
>>> WScript.Echo fso.BuildPath("C:\some\folder", "file.ext")
C:\some\folder\file.ext
>>> WScript.Echo fso.BuildPath("C:\some\folder\", "\file.ext")
C:\some\folder\file.ext
只要在没有任何变量的情况下将其设置为单个字符串:

"C:\Program Files\WinSCP\Build.bat"
不过,上述两项都不是你所犯错误的原因。Windows可以很好地处理重复路径分隔符

找不到您试图执行的文件,因为路径包含空格,因此您的代码实际上试图执行一个文件C:\Program,该文件不存在参数Files\WinSCP\\Build.bat

您需要在路径周围放置双引号以防止出现这种情况,或者使用文字双引号(必须加倍才能在字符串中转义):

shell.Run """C:\Program Files\WinSCP\Build.bat"""
或者通过将字符串与ASCII字符34连接:

shell.Run Chr(34) & "C:\Program Files\WinSCP\Build.bat" & Chr(34)
在函数中放入创建双引号字符串的代码通常很有帮助:

Function qq(str)
  qq = Chr(34) & str & Chr(34)
End Function
并使用如下功能:

"C:\Program Files\WinSCP\" & "\Build.bat"
shell.Run qq("C:\Program Files\WinSCP\Build.bat")

我最近这样做是为了从vbscript for winscp创建一个批处理文件!我就是这样做的

strProcessToKill = "winscp.exe"

'Sets "shell" to run a shell command
sub shell(cmd)
'Run a command as if you were running from the command line
dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(cmd)
Set objShell = Nothing
end sub

'Creates Sync.bat, which is called at the end of the script.(This is what passes the      FTP parameters to the WinSCP Program)
SET objFSO = CreateObject("Scripting.FileSystemObject")

'Open write stream
SET outFile = objFSO.CreateTextFile("C:\RDSync\sync.bat", True)

'Write to Batch File
outFile.WriteLine "@echo off"
outFile.WriteLine "cd %programfiles%\winscp\"
outFile.WriteLine "start /b winscp.exe /log=""C:\RDSync\logs\!M-!D-!Y@!T.xml""     /xmlgroups /command ""open ftp://username:password@ftp.foo.com"" ""synchronize local -delete -criteria=size" & + " " + """""" + RDfolder + """""" + " " + "/"
outFile.WriteLine "exit"

'Close Write Stream
outFile.Close

'Allows script to access Running Processes"
SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

'set variable to Winscp Process Instance
SET colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

'Checks to see if an instance of WinSCP.exe is running, and if it is, it closes it.   This will loop to close multiple processes
count = 0
FOR EACH objProcess in colProcess
objProcess.Terminate()
count = count + 1

Next

'Runs the batch file from a silent shell command
shell "C:\RDSync\sync.bat"
在上面的示例中,变量RDfolder是c:\users\username\documents\synced files


我希望这对你有帮助

我最近这样做是为了从vbscript for winscp创建一个批处理文件!我就是这样做的

strProcessToKill = "winscp.exe"

'Sets "shell" to run a shell command
sub shell(cmd)
'Run a command as if you were running from the command line
dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(cmd)
Set objShell = Nothing
end sub

'Creates Sync.bat, which is called at the end of the script.(This is what passes the      FTP parameters to the WinSCP Program)
SET objFSO = CreateObject("Scripting.FileSystemObject")

'Open write stream
SET outFile = objFSO.CreateTextFile("C:\RDSync\sync.bat", True)

'Write to Batch File
outFile.WriteLine "@echo off"
outFile.WriteLine "cd %programfiles%\winscp\"
outFile.WriteLine "start /b winscp.exe /log=""C:\RDSync\logs\!M-!D-!Y@!T.xml""     /xmlgroups /command ""open ftp://username:password@ftp.foo.com"" ""synchronize local -delete -criteria=size" & + " " + """""" + RDfolder + """""" + " " + "/"
outFile.WriteLine "exit"

'Close Write Stream
outFile.Close

'Allows script to access Running Processes"
SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

'set variable to Winscp Process Instance
SET colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

'Checks to see if an instance of WinSCP.exe is running, and if it is, it closes it.   This will loop to close multiple processes
count = 0
FOR EACH objProcess in colProcess
objProcess.Terminate()
count = count + 1

Next

'Runs the batch file from a silent shell command
shell "C:\RDSync\sync.bat"
在上面的示例中,变量RDfolder是c:\users\username\documents\synced files


我希望这对你有帮助

@Mani Kandan请指定您遇到的错误…?您看到我的错误了吗?>>>>>>行:49字符:1错误:系统找不到指定的代码:80070002来源:NULTH您发布的代码甚至没有49行。我被删除为空行海报区。最后三行error@ManiKandan请指定您遇到的错误…?您看到我的错误>>>>>>行:49字符:1错误:系统找不到指定的代码:80070002来源:NULTH您发布的代码甚至没有49行。我被删除为空行海报区。最后三行错误确认在vbs程序结束后在正确的位置正确创建Build.bat文件…检查我是使用vbs创建的bat文件。在正确的位置击球。手动运行该bat文件。并保存vbscript命令中最后三行的工作。请帮助紧急情况请帮助我双路径分隔符不会导致任何问题。Windows可以很好地处理这个问题。尝试运行/c something将引发错误,因为该选项不适用于任何内容。您需要%COMSPEC%/c。。。或cmd/c。。。确认Build.bat文件在vbs程序运行后正确创建在正确的位置
ds…检查我是使用vbs创建bat文件的。在正确的位置击球。手动运行该bat文件。并保存vbscript命令中最后三行的工作。请帮助紧急情况请帮助我双路径分隔符不会导致任何问题。Windows可以很好地处理这个问题。尝试运行/c something将引发错误,因为该选项不适用于任何内容。您需要%COMSPEC%/c。。。或cmd/c。。。为了让它发挥作用。