【发布时间】:2015-04-20 14:35:47
【问题描述】:
我正在从批处理文件中启动我的 vb.net 控制台应用程序 .exe,例如:(用于测试目的的超时)
@Echo off
echo Starting Script
start C:\Users\user\Desktop\ConsoleApplication2
timeout /t 8 /nobreak
start C:\Users\user\Desktop\ConsoleApplication2
当 vb.net 控制台应用程序运行时,进程名称、描述、日期/时间和计算机名称被传入并插入到 sql 数据库中。 然而,目前只有日期/时间(在 sql 中完成)和计算机名称是正确的,因为它们是自动完成的,而名称和描述将是用户输入。我尝试至少对名称使用命令行参数,但是看到 vb 应用程序是从批处理文件运行的,它不起作用。所以现在我想知道是否有任何其他方式可以获得名称和描述输入(不改变时间/等待输入,因为时间戳很重要)或者是否有人有任何建议?
VB.net 代码:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Console = System.Console
Module Module1
Sub Main()
'Connection to server
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString = ("Server Connection Info...;")
conn.Open()
'Calling Stored Procedure
Dim objCommand As New SqlClient.SqlCommand
objCommand.Connection = conn
objCommand.CommandText = "ProcessLog_Insert"
objCommand.CommandType = CommandType.StoredProcedure
'Pass in each of the required parameters
objCommand.Parameters.Add("ProcessName", SqlDbType.NVarChar).Value = "Test3"
'Pass in a description of the process being run
objCommand.Parameters.Add("ProcessDescription", SqlDbType.NVarChar).Value = "Desc"
'Pass in the Computer name used by current machine
objCommand.Parameters.Add("ComputerName", SqlDbType.NVarChar).Value = Environment.MachineName
'Execute the Query
objCommand.ExecuteNonQuery()
'Closes the Connection
conn.Close()
conn = Nothing
objCommand = Nothing
End Sub
End Module
【问题讨论】:
-
那么,您是说用户将输入所需的信息,但是由于批处理文件执行了您的应用程序,您不能将这些内容保存到数据库并使用它吗?跨度>
-
嗯,我想为应用程序放在批处理文件中的任何位置收集此信息,因为它将在许多脚本中使用。计算机名称和日期/时间很好,但我目前无法获得名称或描述,因为你不能让 vb 神奇地知道哪个 bat 文件正在运行它(这会给我名字) .所以是的,我目前无法获得这两个字段。
-
根据所提供的信息,我们无法判断您使用什么数据进行描述,因此我们不确定如何提供帮助。描述来自哪里?如果用户在运行批处理文件时可以输入这些信息,那么就可以将其作为参数传递给批处理文件,然后批处理文件可以将其作为参数传递给vb应用程序。
标签: sql vb.net batch-file command-line-arguments