THE COMMAND OF NET
is an executable - net.exe. Thus, it can be invoked as an executable via class Process. Here is a wrapper that returns a string containing the result of the command. Example of use:
retorno = ExecutaComando("net.exe", "start Audiosrv")
Here is the function in Visualbasic.NET:
Private Shared Function ExecutaComando(pComando As String, pParametros As String) As String
Dim _ret As String = ""
Dim procShell As New Process()
'Seu comando vai aqui.
procShell.StartInfo.FileName = pComando
'Os argumentos, aqui.
procShell.StartInfo.Arguments = pParametros
procShell.StartInfo.CreateNoWindow = True
procShell.StartInfo.RedirectStandardOutput = True
procShell.StartInfo.UseShellExecute = False
procShell.StartInfo.RedirectStandardError = True
procShell.Start()
Dim streamReader As New StreamReader(procShell.StandardOutput.BaseStream, procShell.StandardOutput.CurrentEncoding)
Do
Dim _line As String = streamReader.ReadLine()
If (IsNothing(_line)) Then Exit Do
_ret = _ret + _line + vbCrLf
Loop
streamReader.Close()
Return _ret
End Function
For example, the following use:
ExecutaComando("net.exe", "stop w3svc")
Returns the following value on a Windows 8.1 machine with IIS installed:
The World Wide Web Publishing Service service is stopping.
The World Wide Web Publishing Service service was stopped successfully.
You can use the same method with CMD. Example:
Process.Start("cmd", "/c del C:\1.txt")
Looking here I think you don’t understand . Net start is a DOS command , Audiosrv is the audio service as example put .
– Perroni
@Mauricioperroni I understood, yes. Several DOS commands are actually executable as in the case of NET. Feel free to test the above code.
– OnoSendai
Jewel I’ll test now .
– Perroni
Gave error , look at the error that gave ....
– Perroni
Link to error . http://imgur.com/AEJPmtc
– Perroni
It is a function, not a complete class; you need to insert this function into a class/module.
– OnoSendai
That’s exactly what you sent me ... .
– Perroni
I tried to put in a module class it is returning me an error ; I will post to you and to the Administrator. link to the class/module error: http://imgur.com/C9nxphT @Onosendai
– Perroni
Like I settled with SHELL
– Perroni
Private Sub Button1_click(Sender As Object, and As Eventargs) Handles Button1.Click Shell("net stop Teamviewer9") End Sub .
– Perroni
Ready , when runs the solution in my VB it is simple to just run with the right button , administrator permissions and goes smoothly .
– Perroni