2015-07-21 44 views
-2

我需要项目帮助。我的目标是打开一个打开CMD的批处理程序,然后自动运行一些命令。我尝试了一些我在网上找到的脚本。会发生什么是CMD打开,显示一些错误,如“End不是内部或外部命令”,然后关闭。如果你们中的一个给了我一个批处理脚本,我可以输入我的命令,然后将其制作成批处理程序,这将非常有帮助。我需要使用批处理文件在CMD中自动运行命令

此外,我不认为这会很重要,但我在64位计算机上运行Windows 8.1。

P.S.这里是我以前使用的脚本:

Private Sub CMDAutomate() 
    Dim sipdomain As TextBox = txtCommand 
    Dim myprocess As New Process 
    Dim StartInfo As New System.Diagnostics.ProcessStartInfo 
    StartInfo.FileName = "cmd" 
    StartInfo.RedirectStandardInput = True 
    StartInfo.RedirectStandardOutput = True 
    StartInfo.UseShellExecute = False 
    StartInfo.CreateNoWindow = True 
    myprocess.StartInfo = StartInfo 
    myprocess.Start() 
    Dim SR As System.IO.StreamReader = myprocess.StandardOutput 
    Dim SW As System.IO.StreamWriter = myprocess.StandardInput 
    SW.WriteLine(**Command I want to enter**) 
    SW.WriteLine(**Command I want to enter**) 
    SW.WriteLine(**Command I want to enter**) 
    SW.WriteLine(**Command I want to enter**) 
    SW.WriteLine(**Command I want to enter**) 
    SW.WriteLine("exit") 
    Results = SR.ReadToEnd 
    SW.Close() 
    SR.Close() 
    Invoke(Finished) 
End Sub 
+0

您看到该错误是因为'end' _isn't_一个批处理命令。您应该编辑您的问题以包含您尝试过的代码。 – SomethingDark

+0

好吧,我添加了它 –

+0

这是vbscript ...或者至少是某些Visual Basic方言。 – SomethingDark

回答

1

首先,请提高你的英语水平。

这听起来像你想与

SW.WriteLine(**Command I want to enter**) 
SW.WriteLine(**Command I want to enter**) 
SW.WriteLine(**Command I want to enter**) 
SW.WriteLine(**Command I want to enter**) 
SW.WriteLine(**Command I want to enter**) 

在这种情况下运行命令,有.NET中Sendkeys.Send()类,您可以使用。 尝试Sendkeys.Send()

我做C#,而不是VB。但我认为这将起作用

+0

运行的全新脚本,那么整个脚本会是什么样的呢? –

+0

,这将在批处理文件中工作 –

相关问题