|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Invoking the Command Prompt via Code -- Very urgent
Hello everyone. Is there a way to invoke the command prompt via code(VB) I want to open the command prompt, browse it to a particular directory, execute a couple of commands and then right the output(text on the screen or any errors to a file). I have found some code but couldnt get that to work. This is what I have so far:
Dim proc As New Process Dim psi As New ProcessStartInfo Dim sOut As StreamReader, sIn As StreamWriter Dim sErr As StreamReader, cmdOut As String psi.FileName = "cmd.exe" psi.UseShellExecute = False psi.CreateNoWindow = True psi.RedirectStandardInput = True psi.RedirectStandardOutput = True psi.RedirectStandardError = True proc.StartInfo = psi sOut = proc.StandardOutput sIn = proc.StandardInput sErr = proc.StandardError sIn.AutoFlush = True sIn.Write("NET SHARE" + System.Environment.NewLine) sIn.Write("EXIT" + System.Environment.NewLine) sIn.Close() cmdOut = sOut.ReadToEnd() Response.Write(cmdOut) Please help. Thank you. |
|
#2
|
|||
|
|||
|
You might consider using the VB Shell command, or the ShellExecute api function as another way to go.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
|||
|
|||
|
Quote:
Thanks for the reply. I am actually trying to use the VB Shell Script and I am stuck there also. This is my code: Function CmdRun(Cmd) 'Clear the info from any previous invocations of CmdRun() CmdRun = vbNullString Dim oShell, oExec, strCmd Dim strInput, intPassPhrasePos, intOverwritePos strCmd = "%COMSPEC%" 'Create a Shell object Set oShell = CreateObject("Wscript.Shell") wscript.echo Cmd 'Set oExec = oShell.Exec("%COMSPEC% /c " & Cmd) Set oExec = oShell.Exec("%COMSPEC% /c " & Cmd) 'Do 'WScript.Sleep 100 'Loop While Not oExec.Stdout.AtEndOfStream 'Do While oExec.Status <> 1 'WScript.Sleep 100000000 'Loop Set oExec = nothing Set oShell = nothing End Function In this line Set oExec = oShell.Exec("%COMSPEC% /c " & Cmd) if i use Set oExec = oShell.Exec("%COMSPEC% /c notepad.exe") it works but it doesnt execute my command. Any ideas why its doing that? Infact nothing is happening. Please help. Thank you. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Invoking the Command Prompt via Code -- Very urgent |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|