i searched google and stackoverflow alot but no solution
i was trying to pass multiple arguments in cmd
they are like in this way
Dim argu1 As String = "netsh wlan set hostednetwork mode = allow ssid=" + TextBox1.Text + " key=" + TextBox2.Text
Dim argu2 As String = "netsh wlan start hostednetwork"
Dim process As System.Diagnostics.Process = Nothing
Dim processStartInfo As System.Diagnostics.ProcessStartInfo
processStartInfo = New System.Diagnostics.ProcessStartInfo
processStartInfo.FileName = "cmd.exe"
processStartInfo.Verb = "runas"
and wrote arguments in this way
processStartInfo.Arguments = argu1 & argu2
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
processStartInfo.UseShellExecute = True
Try
process = System.Diagnostics.Process.Start(processStartInfo)
Catch ex As Exception
MessageBox.Show(ex.Message, "Unknown Error !", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If Not (process Is Nothing) Then
process.Dispose()
End If
End Try
but nothing is happening
so plz tell me how can i pass multiple arguments
What did you expect to happen? You are executing
cmd.exe netsh wlan set hostednetwork mode = allow ssid=... key=...netsh wlan start hostednetwork
which simply starts a new instance of cmd.exe, ignoring all that netsh ... stuff.
Please have a look at the documentation of cmd.exe. In particular, I suspect that the /c command line switch might be what you are looking for. That said, you might want to consider calling netsh.exe directly or (even better) search for a way to do what you are trying to achieve with Windows API or the .NET library.
Related
I thought this would be a simple task but found I was very wrong apparently. We have a working application that resides in a Windows Server 2016 system This app needs to be triggered remotely by a general user who clicks on a shortcut pointed to the .exe on the server. The problem is that the app needs to be able to run using the server's resources so that an email can be sent (only servers are capable of sending emails).
It seems that the app runs with the user's resources so the email never gets sent. I'm not sure if I need to add some type of scripting (VB.Net) or if I need to configure the .exe/server to enable this function. This works when a user with Admin rights runs the app but we need a regular User to be able to do the same. I have tried using PsExec but still had the same problem. (The user is using Windows 10)
Does anyone have any ideas that can make this happen?
This is the code we're using for the mail function:
Dim client As New SmtpClient()
Dim mail As New MailMessage()
mail.From = New MailAddress("email#email.com")
client.Credentials = New Net.NetworkCredential("username", "password")
mail.[To].Add("email#email.com")
mail.[To].Add("email#email.com")
'set the content
mail.Subject = "Subject: " & Date.Now
mail.Body = "Body: " & Date.Now
client.Host = "host.host.host.com"
client.Port = "25"
client.UseDefaultCredentials = True
Try
client.Send(mail)
Catch exc As Exception
Finally
mail = Nothing
client = Nothing
End Try
Catch ex As Exception
' MsgBox("Error, DB Open " & ex.Message)
End Try
Windows Forms application using VB.Net and VS2012. Connecting to an Access database using Access Runtime 2013. The app is compiled to target x86. The problem is intermittent and occurs on multiple different PC's randomly, and accessing a database on a local hard drive.
Using cn As New OleDbConnection
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
If Not OpenDBConnection(cn) Then
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
MsgBox("Unable to make database connection to update screen status.", MsgBoxStyle.OkOnly, "Database Connection Error (MMUN1)")
Exit Sub
End If
'continue processing....
end using
Public Function OpenAccessConnection(ByRef conn As OleDb.OleDbConnection) As Boolean
Dim builder As New OleDbConnectionStringBuilder()
'conn.Provider = "Microsoft.ACE.OLEDB.12.0"
Try
builder.ConnectionString = "Data Source=" & DPATH & DBNAME
builder.Add("Provider", "Microsoft.ACE.OLEDB." & ACCESSVER & ".0") 'ACCESSVER is '12'
conn.ConnectionString = builder.ConnectionString
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
conn.Open()
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
Return True
Catch ex As Exception
MsgBox("Unable to make Access connection. Error# " & Err.Number & " " & ErrorToString() & " " & ex.ToString, MsgBoxStyle.OkOnly, "Database Connection Error (OLEOPN1)")
Return False
Finally
builder.Clear()
builder = Nothing
End Try
End Function
Public Function OpenDBConnection(ByRef conn As OleDbConnection) As Boolean
'I know this is an extraneous function call but it is in transition from multiple prior uses and I thought I had better not exclude it from this post in case it mattered for some reason
OpenDBConnection = OpenAccessConnection(conn)
End Function
Error being returned intermittently:
I have read many of the posts on this topic and have not found a solution, and frankly am not sure where to look. Could this be coming from an earlier application error? Thread/STA issue? If so, what do I do about it? On the development machine, I will on occasion see a DisconnectedContext error, but have not seen the External component error which appears on PC's running the released version. Are these related? Also, there are some ADO (ADODB) connections being made to the database (still trying to replace/upgrade), but these are not open at the time this new connection is being made. But could it be a connection pooling issue? Thanks in advance for any help out there.
in my project i need some changes in my code to give the user choose the name of sql database !
and this is My original code:
Dim DssD As String
DssD = TextBox1.Text
Zsql = "CREATE DATABASE my_db ON PRIMARY" +
"(Name=my_db, filename = 'D:\DB\SQL\my_db.mdf')log on" +
"(name=my_db_log, filename='D:\DB\SQL\my_db_log.ldf')"
Zcmd = New SqlCommand(Zsql, Zsqlcon)
Try
Zsqlcon.Open()
Zcmd.ExecuteNonQuery()
Zsqlcon.Close()
MsgBox("Done", MsgBoxStyle.Information, " ZerAllail")
Catch
MsgBox("Somthing wrong", MsgBoxStyle.Critical, " ZerAllail")
End Try
its working good but its not create the log fail !
You can use a interpolated string (preceded with $) if you are using Visual Studio 2015 or later. You can embed variables directly into the string enclosed in braces. Otherwise see String.Format.
I added a Using...End Using block to your code because connections and commands need to closed and disposed. They use unmanaged resources and need to release them in their .Dispose methods. A Using block will do this for you even if there is an error.
Private Sub CreateDatabase()
Dim DssD = TextBox1.Text 'I would expect you would validata this input
Dim Zsql = $"CREATE DATABASE {DssD} ON PRIMARY (Name=my_db, filename = 'D:\DB\SQL\{DssD}.mdf')log on
(name={DssD}_log, filename='D:\DB\SQL\{DssD}_log.ldf')"
Try
Using Zsqlcon As New SqlConnection("Your connection string"),
Zcmd = New SqlCommand(Zsql, Zsqlcon)
Zsqlcon.Open()
Zcmd.ExecuteNonQuery()
End Using
MsgBox("Done", MsgBoxStyle.Information, " ZerAllail")
Catch
MsgBox("Somthing wrong", MsgBoxStyle.Critical, " ZerAllail")
End Try
End Sub
I've written code in VB to run a CMD command, where the output is stored to a text file. This output is then needed for the program, so the program needs to wait until the CMD command has finished before continuing. I am using
Dim wait As Process = Process.Start(psi)
wait.WaitForExit()
To make sure the process exits before the code continues, but now that I've done that, the "/c" option in the process info is no longer working. The process info is as follows:
Dim psi As New ProcessStartInfo With {
.FileName = "Cmd",
.Arguments = "/c " & completedCom & " > " & oPath
}
I do not understand why the "/c" option would fail all of a sudden.
Spaces would be an example of one problem. Use quotes around your commands to help with that:
Dim psi As New ProcessStartInfo With {
.FileName = "Cmd",
.Arguments = "/c """ & completedCom & """ > """ & oPath & """"
}
The preferred method of calls to process would be to directly call the exec, rather than launching a cmd. In that case, you would have to capture the standard output asynchronously and write it to a file though.
I retrieve it in my mainform:
Try
rs.Connection = con
cmd = "select * from cdcol.currency_rate"
rs.CommandText = cmd
res = rs.ExecuteReader
While res.Read
Dim currency = res.GetString("currency")
ComboBox2.Items.Add(currency)
End While
res.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
and this in my tabcontrol
Try
rs.Connection = con
cmd = "select * from cdcol.currency_rate where currency='" & ComboBox2.Text & "'"
rs.CommandText = cmd
res = rs.ExecuteReader
While res.Read
If sell.Checked = True Then
buy.Text = res.GetDouble("buy_rate")
coderate.Text = res.GetString("code")
End If
If buy.Checked = True Then
sell.Text = res.GetDouble("sell_rate")
coderate.Text = ("PHP")
End If
End While
res.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
when i log in there was an error,
what's wrong with my codes ?
please help me ..
A few things could be going on, hard to tell without all the code but I'll give you some ideas. I'm assuming this is a WinForms app (also assuming this is SQL Server)?
If you've verified that all your DataReader's are being closed properly then it is possible that you have two DataReaders actually trying to read at the same time if they're using a shared connection in your program (you say you're using a tab control and executing a query, if you have one reader running somewhere and then you click on a tab you could run into that scenario). If that is your desired behavior you can allow multiple recordsets by adding the multiple active result sets flag to your connection string:
https://msdn.microsoft.com/en-us/library/h32h3abf(v=vs.110).aspx
Something like this:
Dim connectionString As String = "Data Source=MSSQL1;" & _
"Initial Catalog=AdventureWorks;Integrated Security=SSPI;" & _
"MultipleActiveResultSets=True"
The MSDN article gives you much more info about it. In your scenario this will probably work. MSDN offers this though (which is your other option, use a connection per method you need it and dispose of it when you're done):
"MARS is not designed to remove all requirements for multiple
connections in an application. If an application needs true parallel
execution of commands against a server, multiple connections should be
used."