0

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!

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by VulcanDesign
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)?:)

Votes + Comments
Thanks for catching that, I would have never figured out why my code wasn't working =)
0

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....

Edited by VulcanDesign: n/a

0

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.

0

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()

Edited by VulcanDesign: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.