VB.NET / VB - Passing a variable into Startinfo.Arguments
I'm trying to use a string variable in StartInfo.Arguments of a process, but can't figure out the correct syntax.
Dim pquery As New Process
Dim User As String = "test"
pquery.StartInfo.UseShellExecute = False
pquery.StartInfo.CreateNoWindow = True
pquery.StartInfo.FileName = "cmd"
pquery.StartInfo.Arguments = "/c dsquery.exe * -filter ""(&(objectClass=user)(!(objectClass=computer)(mail=***string variable should go here***)))"" | dsget user -samid"
pquery.StartInfo.RedirectStandard开发者_高级运维Output = True
pquery.StartInfo.RedirectStandardError = True
pquery.Start()
You can use String.Format():
Change your assignment to pquery.StartInfo.Arguments
like so:
pquery.StartInfo.Arguments = String.Format("/c dsquery.exe * -filter ""(&(objectClass=user)(!(objectClass=computer)(mail={0})))"" | dsget user -samid", User)
精彩评论