473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to send a message to a hidden cmd shell

IronRazer
83 64KB
I am running a process in my GUI program that starts ffmpeg in a hidden cmd shell. I need to make it so when i press the STOP button on my GUI it sends a key stroke message to the cmd shell as if i pressed the "q" key which would tell ffmpeg to stop. I can`t use the Process.Kill() command because it messes up the file that ffmpeg is making.

I found some examples of sending messages to other windows made with VB6 :

Expand|Select|Wrap|Line Numbers
  1.         Dim lNotepadHwnd As Long
  2.         Dim lNotepadEdit As Long
  3.         Dim sMsg As String = "q"
  4.         lNotepadHwnd = FindWindow("Notepad", vbNullString)
  5.         lNotepadEdit = FindWindowEx(lNotepadHwnd, 0&, "Edit", vbNullString)
  6.         SendMessageSTRING(lNotepadEdit, WM_SETTEXT, 256, sMsg)
I get the SendMessage and FindWindow is not declared error in my VB 2008 program. It looks more like C++ to me but, can someone tell me why I get this error or can someone show an example of how to send a message to a hidden cmd shell in VB 2008 ?

I can get as far as getting the handle of the process but i cant find what i need to send the message.

This is my Stop button code :

Expand|Select|Wrap|Line Numbers
  1.     Private Sub Btn_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Stop.Click
  2.         Dim processHandle As Long = Process1.Handle
  3.  
  4.         'What type of command do i need hear to send "q" key to hidden cmd shell ?
  5.  
  6.         Btn_Stop.Enabled = False
  7.         Btn_Record.Enabled = True
  8.         UD_Minutes.Enabled = True
  9.     End Sub
  10.  
Jan 17 '13 #1
2 3948
PsychoCoder
465 Expert Mod 256MB
Check out the SendKeys Class, it may help you accomplish what you're looking for.

Also, moving to VB.NET forum so more VB.NET experts can see your question :)
Jan 18 '13 #2
IronRazer
83 64KB
First i would like to say Thanks For helping me. After checking out the link you gave, i stumbled onto a lot of stuff from there that helped me get a lot farther than i was. I now have the following that works if i have the Process running in a normal or minimized window state.

This is what i have added to get it to work so far:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Runtime.InteropServices
  2.  
  3.     Dim hWnd As IntPtr
  4.  
  5.     <DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
  6.     Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
  7.     End Function
  8.  
  9.     <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As Long
  10.     End Function
  11.  
  12.     Private Sub Btn_Record_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesBtn_Record.Click
  13.         Process1.Start()
  14.     End Sub
  15.  
  16.     Private Sub Btn_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Stop.Click
  17.         hWnd = FindWindow(Nothing, Process1.MainWindowTitle)
  18.         SetForegroundWindow(hWnd)
  19.         SendKeys.Send("q")
  20.     End Sub
I would really like to have the Process running in a hidden window state. Is it possible to use SendMessage, PostMessage, or maybe SendInput to send a KeyDown and KeyUp to the Process if it is running in a hidden window state or is it just not possible?

PS. I realized yesterday that it was in the wrong VB Forum and tried re-posting it in VB.NET and it got removed. I will see if i can figure out how to move it.
Jan 19 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: crowl | last post by:
Hi all, I'm looking for a simple c source sample which I can send message to ICQ and MSN Messenger. I have search with google, but without luck on my side. Do you know any doc for programming...
3
by: Eka Gautama | last post by:
Hi all, Is it possible to intercept net send message? I don't want windows show the message to screen directly, but i want process first, then display to the screen... Thanks
0
by: Jerry | last post by:
Hi, I send a message WM_HELP, but it return false. The code is: Point point = new Point(e.X, e.Y); Control child = GetChildAtPoint(point); if (child != null) { point = PointToScreen(point); ...
1
by: Raj | last post by:
Hi, I am trying to send message (WM_CLICK) to a button control in a PowerBuilder application using a C# spy program. This works for all other windows applications but in case of PB application...
7
by: Ahmad Jalil Qarshi | last post by:
Hi! I want to develop two applications one a Windows Service and the other a GUI based application. I want some sort of communication between Service and GUI. I have decided to use Remoting for...
2
by: ad | last post by:
How can I send message to cellular phone by program?
5
by: napster | last post by:
hi, I am working on a project to control some pc activities from mobile but am not able to send a message from mobile to pc.I have tried the AT commands but its not working for me.Can anybody help...
1
by: sauravpn | last post by:
I am new to perl and I cant figure out how to write a perl script to send message to syslog wih facilty user
1
by: Balabhadra Kar | last post by:
Hello how can i send message to all mobile set using asp code .Please Help me. thnak.s
0
by: anbu | last post by:
there in one database and one table that have three field one is name and another one is date and last is email address data are stored in following ways name date email...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.