PC Review


Reply
Thread Tools Rate Thread

Close a DOS window via VB.NET

 
 
=?Utf-8?B?Q3V0bGFzcw==?=
Guest
Posts: n/a
 
      23rd Mar 2005
Hi,
I'm using the following code to spawn another app from VB.NET..

Dim ShellProcess As New Process
ShellProcess.StartInfo.FileName = "xxxx.exe"
ShellProcess.StartInfo.UseShellExecute = True
ShellProcess.StartInfo.WorkingDirectory = "C:\Windows\System32"
ShellProcess.Start()
ShellProcess.WaitForInputIdle()

xxxx.exe creates a DOS window
I am unable to close it via.... ShellProcess.CloseMainWindow()
or kill it via....ShellProcess.Kill()
I know I can use API FindWindow, PostMessage etc. I'm looking for a true
..NET clean way to do this. Nothing I try works! Anybody run into this?


 
Reply With Quote
 
 
 
 
95isalive
Guest
Posts: n/a
 
      23rd Mar 2005
Check help for GetProcessbyID or GetProcessbyName

I'm not at my VS.Net / MSDN machine right now or I'd post some syntax.


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed..................
...............................with a computer

"Cutlass" <(E-Mail Removed)> wrote in message
news:3C8900D3-6CC7-45A0-8515-(E-Mail Removed)...
> Hi,
> I'm using the following code to spawn another app from VB.NET..
>
> Dim ShellProcess As New Process
> ShellProcess.StartInfo.FileName = "xxxx.exe"
> ShellProcess.StartInfo.UseShellExecute = True
> ShellProcess.StartInfo.WorkingDirectory = "C:\Windows\System32"
> ShellProcess.Start()
> ShellProcess.WaitForInputIdle()
>
> xxxx.exe creates a DOS window
> I am unable to close it via.... ShellProcess.CloseMainWindow()
> or kill it via....ShellProcess.Kill()
> I know I can use API FindWindow, PostMessage etc. I'm looking for a true
> .NET clean way to do this. Nothing I try works! Anybody run into this?
>
>



 
Reply With Quote
 
=?Utf-8?B?Q3V0bGFzcw==?=
Guest
Posts: n/a
 
      23rd Mar 2005
Thanks
I tried all afternoon and can't get it to work, it's as if the DOS window
doesn't exist.
I must be coding something wrong ... when I go into task manager after the
spawn I can see the exe listed and I see it in the taskbar/screen too...I
just can't seem to program a Close for it.....HELP Very Appreciated...I can
use the API method..that works...but I want to code pure .NET if you know
what I mean...

"95isalive" wrote:

> Check help for GetProcessbyID or GetProcessbyName
>
> I'm not at my VS.Net / MSDN machine right now or I'd post some syntax.
>
>
> --
> Steve Easton
> Microsoft MVP FrontPage
> 95isalive
> This site is best viewed..................
> ...............................with a computer
>
> "Cutlass" <(E-Mail Removed)> wrote in message
> news:3C8900D3-6CC7-45A0-8515-(E-Mail Removed)...
> > Hi,
> > I'm using the following code to spawn another app from VB.NET..
> >
> > Dim ShellProcess As New Process
> > ShellProcess.StartInfo.FileName = "xxxx.exe"
> > ShellProcess.StartInfo.UseShellExecute = True
> > ShellProcess.StartInfo.WorkingDirectory = "C:\Windows\System32"
> > ShellProcess.Start()
> > ShellProcess.WaitForInputIdle()
> >
> > xxxx.exe creates a DOS window
> > I am unable to close it via.... ShellProcess.CloseMainWindow()
> > or kill it via....ShellProcess.Kill()
> > I know I can use API FindWindow, PostMessage etc. I'm looking for a true
> > .NET clean way to do this. Nothing I try works! Anybody run into this?
> >
> >

>
>
>

 
Reply With Quote
 
95isalive
Guest
Posts: n/a
 
      24th Mar 2005
If you're using GetProcessbyName use the short or shell name of the process

GetProcessByName("cmd") or GetProcessByName("command") instead of using cmd.exe or
command.com

There's an example script in the MSDN library for closing instances of notepad, but once
again I'm away from that machine.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed..................
...............................with a computer


"Cutlass" <(E-Mail Removed)> wrote in message
newsBD65DA4-A943-439C-A099-(E-Mail Removed)...
> Thanks
> I tried all afternoon and can't get it to work, it's as if the DOS window
> doesn't exist.
> I must be coding something wrong ... when I go into task manager after the
> spawn I can see the exe listed and I see it in the taskbar/screen too...I
> just can't seem to program a Close for it.....HELP Very Appreciated...I can
> use the API method..that works...but I want to code pure .NET if you know
> what I mean...
>
> "95isalive" wrote:
>
> > Check help for GetProcessbyID or GetProcessbyName
> >
> > I'm not at my VS.Net / MSDN machine right now or I'd post some syntax.
> >
> >
> > --
> > Steve Easton
> > Microsoft MVP FrontPage
> > 95isalive
> > This site is best viewed..................
> > ...............................with a computer
> >
> > "Cutlass" <(E-Mail Removed)> wrote in message
> > news:3C8900D3-6CC7-45A0-8515-(E-Mail Removed)...
> > > Hi,
> > > I'm using the following code to spawn another app from VB.NET..
> > >
> > > Dim ShellProcess As New Process
> > > ShellProcess.StartInfo.FileName = "xxxx.exe"
> > > ShellProcess.StartInfo.UseShellExecute = True
> > > ShellProcess.StartInfo.WorkingDirectory = "C:\Windows\System32"
> > > ShellProcess.Start()
> > > ShellProcess.WaitForInputIdle()
> > >
> > > xxxx.exe creates a DOS window
> > > I am unable to close it via.... ShellProcess.CloseMainWindow()
> > > or kill it via....ShellProcess.Kill()
> > > I know I can use API FindWindow, PostMessage etc. I'm looking for a true
> > > .NET clean way to do this. Nothing I try works! Anybody run into this?
> > >
> > >

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?Q3V0bGFzcw==?=
Guest
Posts: n/a
 
      24th Mar 2005
The code works when I spawn notepad, it doesn't when I use my exe.

What is the proper VB.NET way to declare these VB6 dlls?
Public Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Declare Function IsWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, _
lpdwProcessId As Long) As Long

"95isalive" wrote:

> If you're using GetProcessbyName use the short or shell name of the process
>
> GetProcessByName("cmd") or GetProcessByName("command") instead of using cmd.exe or
> command.com
>
> There's an example script in the MSDN library for closing instances of notepad, but once
> again I'm away from that machine.
>
> --
> Steve Easton
> Microsoft MVP FrontPage
> 95isalive
> This site is best viewed..................
> ...............................with a computer
>
>
> "Cutlass" <(E-Mail Removed)> wrote in message
> newsBD65DA4-A943-439C-A099-(E-Mail Removed)...
> > Thanks
> > I tried all afternoon and can't get it to work, it's as if the DOS window
> > doesn't exist.
> > I must be coding something wrong ... when I go into task manager after the
> > spawn I can see the exe listed and I see it in the taskbar/screen too...I
> > just can't seem to program a Close for it.....HELP Very Appreciated...I can
> > use the API method..that works...but I want to code pure .NET if you know
> > what I mean...
> >
> > "95isalive" wrote:
> >
> > > Check help for GetProcessbyID or GetProcessbyName
> > >
> > > I'm not at my VS.Net / MSDN machine right now or I'd post some syntax.
> > >
> > >
> > > --
> > > Steve Easton
> > > Microsoft MVP FrontPage
> > > 95isalive
> > > This site is best viewed..................
> > > ...............................with a computer
> > >
> > > "Cutlass" <(E-Mail Removed)> wrote in message
> > > news:3C8900D3-6CC7-45A0-8515-(E-Mail Removed)...
> > > > Hi,
> > > > I'm using the following code to spawn another app from VB.NET..
> > > >
> > > > Dim ShellProcess As New Process
> > > > ShellProcess.StartInfo.FileName = "xxxx.exe"
> > > > ShellProcess.StartInfo.UseShellExecute = True
> > > > ShellProcess.StartInfo.WorkingDirectory = "C:\Windows\System32"
> > > > ShellProcess.Start()
> > > > ShellProcess.WaitForInputIdle()
> > > >
> > > > xxxx.exe creates a DOS window
> > > > I am unable to close it via.... ShellProcess.CloseMainWindow()
> > > > or kill it via....ShellProcess.Kill()
> > > > I know I can use API FindWindow, PostMessage etc. I'm looking for a true
> > > > .NET clean way to do this. Nothing I try works! Anybody run into this?
> > > >
> > > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?Q3V0bGFzcw==?=
Guest
Posts: n/a
 
      24th Mar 2005
Never mind, figured the declares out, but my VB6 calls to these functions
fail. Would you know how to properly convert them?
I'm getting messsages like:
Value of type 'Integer' cannot be converted to 'System.IntPtr'. yada yada

Dim hWindow As Long
Dim hThread As Long
Dim hProcess As Long
Dim lProcessId As Long
Dim lngResult As Long
Dim lngReturnValue As Long
Dim iLoopCnt As Integer

hWindow = FindWindow(vbNullString, "(Inactive " & sDir & "\EDIAPIS.EXE)")
hThread = GetWindowThreadProcessId(hWindow, lProcessId)
hProcess = OpenProcess(SYNCHRONIZE, 0&, lProcessId)
lngReturnValue = PostMessage(hWindow, WM_CLOSE, 0&, 0&)
lngResult = WaitForSingleObject(hProcess, 20000)

"Cutlass" wrote:

> The code works when I spawn notepad, it doesn't when I use my exe.
>
> What is the proper VB.NET way to declare these VB6 dlls?
> Public Declare Function WaitForSingleObject Lib "kernel32" _
> (ByVal hHandle As Long, _
> ByVal dwMilliseconds As Long) As Long
> Private Declare Function CloseHandle Lib "kernel32" _
> (ByVal hObject As Long) As Long
> Public Declare Function FindWindow Lib "user32" _
> Alias "FindWindowA" _
> (ByVal lpClassName As String, _
> ByVal lpWindowName As String) As Long
> Public Declare Function PostMessage Lib "user32" _
> Alias "PostMessageA" _
> (ByVal hwnd As Long, _
> ByVal wMsg As Long, _
> ByVal wParam As Long, _
> ByVal lParam As Long) As Long
> Public Declare Function IsWindow Lib "user32" _
> (ByVal hwnd As Long) As Long
> Public Declare Function OpenProcess Lib "kernel32" _
> (ByVal dwDesiredAccess As Long, _
> ByVal bInheritHandle As Long, _
> ByVal dwProcessId As Long) As Long
> Public Declare Function GetWindowThreadProcessId Lib "user32" _
> (ByVal hwnd As Long, _
> lpdwProcessId As Long) As Long
>
> "95isalive" wrote:
>
> > If you're using GetProcessbyName use the short or shell name of the process
> >
> > GetProcessByName("cmd") or GetProcessByName("command") instead of using cmd.exe or
> > command.com
> >
> > There's an example script in the MSDN library for closing instances of notepad, but once
> > again I'm away from that machine.
> >
> > --
> > Steve Easton
> > Microsoft MVP FrontPage
> > 95isalive
> > This site is best viewed..................
> > ...............................with a computer
> >
> >
> > "Cutlass" <(E-Mail Removed)> wrote in message
> > newsBD65DA4-A943-439C-A099-(E-Mail Removed)...
> > > Thanks
> > > I tried all afternoon and can't get it to work, it's as if the DOS window
> > > doesn't exist.
> > > I must be coding something wrong ... when I go into task manager after the
> > > spawn I can see the exe listed and I see it in the taskbar/screen too...I
> > > just can't seem to program a Close for it.....HELP Very Appreciated...I can
> > > use the API method..that works...but I want to code pure .NET if you know
> > > what I mean...
> > >
> > > "95isalive" wrote:
> > >
> > > > Check help for GetProcessbyID or GetProcessbyName
> > > >
> > > > I'm not at my VS.Net / MSDN machine right now or I'd post some syntax.
> > > >
> > > >
> > > > --
> > > > Steve Easton
> > > > Microsoft MVP FrontPage
> > > > 95isalive
> > > > This site is best viewed..................
> > > > ...............................with a computer
> > > >
> > > > "Cutlass" <(E-Mail Removed)> wrote in message
> > > > news:3C8900D3-6CC7-45A0-8515-(E-Mail Removed)...
> > > > > Hi,
> > > > > I'm using the following code to spawn another app from VB.NET..
> > > > >
> > > > > Dim ShellProcess As New Process
> > > > > ShellProcess.StartInfo.FileName = "xxxx.exe"
> > > > > ShellProcess.StartInfo.UseShellExecute = True
> > > > > ShellProcess.StartInfo.WorkingDirectory = "C:\Windows\System32"
> > > > > ShellProcess.Start()
> > > > > ShellProcess.WaitForInputIdle()
> > > > >
> > > > > xxxx.exe creates a DOS window
> > > > > I am unable to close it via.... ShellProcess.CloseMainWindow()
> > > > > or kill it via....ShellProcess.Kill()
> > > > > I know I can use API FindWindow, PostMessage etc. I'm looking for a true
> > > > > .NET clean way to do this. Nothing I try works! Anybody run into this?
> > > > >
> > > > >
> > > >
> > > >
> > > >

> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close a New Window in Word; original window remains open M I K E Microsoft Word Document Management 2 7th Mar 2008 02:16 PM
popup window close to submit opener window without 'causes validation' happening Matt Jensen Microsoft ASP .NET 1 16th Dec 2005 03:16 PM
Pop Up windows close automatically and close all ie browser window =?Utf-8?B?Q3JhenlTaGl0?= Windows XP Internet Explorer 1 22nd Feb 2005 01:08 AM
Smart Client - Want to close the stub window when child window is closed Stone Microsoft Dot NET Framework Forms 0 28th Apr 2004 09:12 PM
Can Not window.close() to Close a New Window After Submitting to It Chan Windows XP Internet Explorer 0 8th Oct 2003 08:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:29 PM.