473,749 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send a message to a hidden cmd shell

IronRazer
83 New Member
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 3977
PsychoCoder
465 Recognized Expert Moderator Contributor
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 New Member
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
6087
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 icq or msn messenger? Many thanks for your assistance.
3
5663
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
1673
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); HELPINFO helpInfo = new HELPINFO(); helpInfo.iContextType = HELPINFO_WINDOW;
1
4525
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 it does not work. Would appreciate any help on this. Thanks in advance
7
13977
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 this purpose. For this I registered an object on Service side for Remoting purposes. Remote Object exposes a function named ReloadFiles() that should internally send a message to service class to Reload some files. Now I don't know how to send...
2
1993
by: ad | last post by:
How can I send message to cellular phone by program?
5
2254
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 and tell how to send message from mobile to PC.My paltform is VC++.NET
1
3207
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
3716
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
1138
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 address anbu 2008-03-26 something@gmail.com
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6800
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.