Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 13th, 2005, 10:30 AM
firdouseqasim firdouseqasim is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 71 firdouseqasim User rank is Corporal (100 - 500 Reputation Level)firdouseqasim User rank is Corporal (100 - 500 Reputation Level)firdouseqasim User rank is Corporal (100 - 500 Reputation Level)firdouseqasim User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 16 h 6 m 11 sec
Reputation Power: 6
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.

Reply With Quote
  #2  
Old October 13th, 2005, 05:09 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
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

Reply With Quote
  #3  
Old October 13th, 2005, 05:12 PM
firdouseqasim firdouseqasim is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 71 firdouseqasim User rank is Corporal (100 - 500 Reputation Level)firdouseqasim User rank is Corporal (100 - 500 Reputation Level)firdouseqasim User rank is Corporal (100 - 500 Reputation Level)firdouseqasim User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 16 h 6 m 11 sec
Reputation Power: 6
Quote:
Originally Posted by Doug G
You might consider using the VB Shell command, or the ShellExecute api function as another way to go.


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.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Invoking the Command Prompt via Code -- Very urgent


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT