Hello all =)
I am working on a Visual Basics (6) project that requires a hidden command prompt window, to which I need to pass commands.

I need to:

  1. Open a hidden command prompt
  2. CD to a directory
  3. pass a command including several file names
  4. Exit the hidden window

I have no idea how to start doing this. I have tried with the following code, but nothing is working for me (I am using Visual Basics Express 2010; VB6). Any help with this will be very much appreciated.

Code I am currently toying with:

Dim WSH
WSH = CreateObject("WScript.Shell")
WSH.Run("cmd", 0)
WSH.Send(cdcommand)
WSH.Send(MencoderCommand)
WSH.Send("exit")
WSH = Nothing

Which doesn't work, and

Dim WSH
WSH = CreateObject("WScript.Shell")
WSH.Run(cdcommand & "/K" & MencoderCommand & "/K" & " exit /K", 0, 1)
WSH = Nothing

No go.

Dim objShell
objShell = CreateObject("WScript.Shell")
WScript.Echo(objShell.CurrentDirectory)
objShell.CurrentDirectory = cdcommand
objShell.Run(MencoderLocation & "/k" & MencoderCommand & " /k exit", 0, 1)

which still doesn't work, and finally

Dim MenCoder
OpenMencoder = Shell("cmd.exe", AppWinStyle.NormalFocus)
SendKeys.Send(cdcommand)
SendKeys.Send(ControlChars.NewLine)
SendKeys.Send(MencoderCommand)
SendKeys.Send(ControlChars.NewLine)
SendKeys.Send("exit")
SendKeys.Send(ControlChars.NewLine)

Which, predictably, did not work well at all.

cdcommand = the the variable containing "cd PATH_TO_CD_TO", and MencoderCommand = the main command I'm trying to pass the command prompt.

Thanks!

You have mentioned that you are using VS 2010 Express (VB6). These are two different versions, completely different code required.

Which version is it, VB6 or 2010 Express (VB.NET)?:)

commented: Thanks for catching that, I would have never figured out why my code wasn't working =) +1

You have mentioned that you are using VS 2010 Express (VB6). These are two different versions, completely different code required.

Which version is it, VB6 or 2010 Express (VB.NET)?:)

Oh that actually explains a lot. I thought VB6 was the code used in Express. In that case, I'm using VB.NET code. Thanks for catching that :)

EDIT: now I also feel completely stupid

EDIT EDIT: this thread should be moved to the VB.NET section then. I wonder how that's done....

EDIT: now I also feel completely stupid

We all stumble once in a while, no worries.:)

EDIT EDIT: this thread should be moved to the VB.NET section then. I wonder how that's done....

I have already asked that this be moved to vb.net.:)

I will see if I can help with a solution. I'm not that clued up on .net, but I'm getting there, coding in both languages at the moment.

I feel I am close with the code below, but it's not working.... Any help with this will be very much appreciated. Thanks!

Dim OpenMencoder As Process = New Process()
OpenMencoder.StartInfo.FileName() = "cmd.exe"
OpenMencoder.StartInfo.WindowStyle() = ProcessWindowStyle.Hidden
OpenMencoder.StartInfo.UseShellExecute() = False
OpenMencoder.StartInfo.RedirectStandardInput() = True
OpenMencoder.StartInfo.RedirectStandardOutput() = False
OpenMencoder.Start()
Dim sIn As System.IO.StreamWriter = OpenMencoder.StandardInput()
sIn.AutoFlush = True
sIn.Write(cdcommand & System.Environment.NewLine)
sIn.Write(MencoderCommand & System.Environment.NewLine)
sIn.Write("exit" & System.Environment.NewLine)
If Not OpenMencoder.HasExited Then
    OpenMencoder.Kill()
End If
sIn.Close()
OpenMencoder.CloseMainWindow()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.