I'm developing a service in VB.net. The problem is if more than 1 IE windows are running, whenever i end a iexplorer process it doesn't close the corresponding IE window. i.e. if 4 windows are running i try to end 3 processes(That arrived after first process) one by one none of them closes but when i end that particular process(That arrived first) that is somehow holding all processes all Internet Explorers close down.
What i'm trying to do is i want commandline args of IE processes and i get args of first IE but after that i get this:
"C:\Program Files (x86)\Internet Explorer\iexplore.exe" "http://ksnap.bpweb.com/webtop/drl/versionLabel/CURRENT"
Thats what i want but when second IE process arrives i get this:
"C:\Program Files (x86)\Internet Explorer\iexplore.exe" SCODEF:424 CREDAT:79874"
and for all next arriving IE processes i get args :i.e. SCODEF:xxxx CREDAT:xxxx (xxxx represent digits)
I don't think you should be doing this by killing processes. You should be use internet explorer automation.
In c#:
using SHDocVw;
using mshtml;
private static IEnumerable<InternetExplorer> GetInternetExplorers()
{
ShellWindows shellWindows = new ShellWindowsClass();
List<InternetExplorer> allExplorers = shellWindows.Cast<InternetExplorer>().ToList();
IEnumerable<InternetExplorer> internetExplorers = allExplorers.Where( ie => Path.GetFileNameWithoutExtension( ie.FullName ).ToLower() == "iexplore" );
return internetExplorers;
}
References:
MSHTML - Microsoft HTML Object Library
Interop.SHDocVw.dll - Microsoft Internet Controls
Look into this a bit more, you should be able to find and close open tabs.
Related
in order to kill a process, I usually use
Process.GetProcessesByName("process name")(0).Kill()
This does not work if I want to close Chrome, using "Chrome" as the process name.
I know that Google Chrome runs with more than one process, at least that's what my task manager shows, so I guess this is the problem: because there are several processes called "Chrome", vb.net is unable to close them all or just closes one which doesn't lead to Chrome closing.
What code could I use instead, to close ALL processes called "Chrome"?
Try using this
Dim i As Integer = Ubound(Process.GetProcessesByName("Chrome.exe"))
For x As Integer = i To 0 Step -1
Process.GetProcessesByName("Chrome.exe")(x) .Kill()
Next
I am running a dos command from my app, however the dos window just hangs without returning any output. It does work under Windows 8, but not Windows 7.
This is my code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim process As New Process()
process.StartInfo.FileName = "C:\Program Files (x86)\Pico Technology\PicoScope6\picoscope.com"
process.StartInfo.UseShellExecute = False
process.StartInfo.Arguments = "/a Measurements.CSV?"
process.StartInfo.RedirectStandardInput = True
process.StartInfo.RedirectStandardOutput = True
process.Start()
Dim reader As StreamReader = process.StandardOutput
Dim output As String = reader.ReadToEnd()
RichTextBox1.Text = output
End Sub
picoscope.com is a 'wrapper' supplied by the PicoScope vendor - it appears to be a very small .net app, which calls the main PicoScope.exe program with some commands (unknown). The PicoScope.exe app needs to be running for this to work.
I wrote a small console app, and this works just fine - however I can't even call my console app from a forms based application.
Code for console app:
Sub Main()
Dim process As New Process()
process.StartInfo.FileName = "C:\Program Files (x86)\Pico Technology\PicoScope6\picoscope.com"
process.StartInfo.Arguments = "/a Measurements.CSV?"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.Start()
' Synchronously read the standard output of the spawned process.
Dim reader As StreamReader = process.StandardOutput
Dim output As String = reader.ReadToEnd()
process.WaitForExit()
process.Close()
End Sub
This seems to be some strange issue with Windows 7.
I can open cmd.exe without any issue, as well as spawn other applications.
It's almost as if there is some conflict between the running picoscope programs and my application.
Attempting to debug doesn't seem to help at all, with the exception of this:
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
I have tried several different approaches, disabling shell redirection, even trying to redirect the output to a file. But it would appear that anything to do with this Picoscope app just prevents it working.
I even tried writing another console app to redirect text output to the console and to a file and they worked (because the picoscope app wasn't involved!).
Likewise, a simple dos batch file with "echo Hello World" in it is successfully redirected to my forms app - so I'm sure my code is correct.
I am now at a loss as to what the issue could be here.
I'm using Visual Studio 2013, Windows 7 on SP1.
Can anyone offer any suggestions?
Apologies for the long post, I was trying to give as much detail as possible.
EDIT: Even more curious is that I tried my working app on another Windows 7 PC and it works...
I suspect this must be related to my specific Windows 7 PC (a fresh build).
I compared UAC settings with the other PC - they are the same.
Thanks.
I am trying to kill all open powerpoint processes but the code I wrote kills only one open process.
'-- get a collection of processes running
Dim foo() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
'-- go through each one looking for the internet explorer name
For Each temp As Diagnostics.Process In foo
'For Word Files opened in Office
If temp.ProcessName = "POWERPNT" Then
temp.Kill() '-- if I find it, kill it.
' Exit For '-- exit the for loop
End If
Try
Dim foo() as process = Process.GetProcessByName("POWERPNT")
For Each temp As Process In foo
temp.Kill()
Next
You are only going to find the single instance of the POWERPNT.exe, because
Multiple instances of Word (Winword.exe), Excel (Excel.exe), and Microsoft Access (MSAccess.exe) can run simultaneously. Therefore, these servers are defined as Single Use (Multiple Instances) servers. Only one instance of PowerPoint (Powerpnt.exe) can run at any given time. Therefore, PowerPoint is a Multiuse (Single Instance) server.
Read How to use Visual C# to automate a running instance of an Office program for complete documentation.
Team,
I would appreciate your help on this,
Background of my project: I have a executable file e.g. abcd.exe which is actually a kind of server which opens itself in a MS DOS window and once launch, it keeps running. As mentioned since it is a server, it keeps logging some log traces and keeps adding new lines in DOS window one by one. This server needs some parameter to start so here the parameter is path of configuration file wherein all the config details are saved. So, to start this server, I need to provide in command prompt,
*Start > Run > CMD
abdc.exe -lookup "C:\MyServer\Bin\designConfig.properties"
To avoid manual steps, I have created batch file e.g. abcd.bat with below lines
"TITLE: MY SERVER - NODE 1234 (SERVER)"
abdc.exe -lookup "C:\MyServer\Bin\designConfig.properties"
My Machine and specification
Above mentioned abdc.exe file is a 64 bit server. My OS: Windows 7 64
Bit Platform: VB Visual Studio 2012 or MS Access VBA
My Requirement
Now I have created a VB Form, multiple line textbox & button. I want,
Once I click on that button, it should lookup the executable file or batch file and launch the abcd.exe server program by accepting the parameter. (I am done with this using below code)
=======================
Dim abc As New Process
Dim abcinfo As New System.Diagnostics.ProcessStartInfo
abcinfo.FileName = "C:\ABCD\abdc.bat""
abcinfo.RedirectStandardOutput = True
abcinfo.RedirectStandardError = True
abcinfo.UseShellExecute = False
abcinfo.ErrorDialog = False
abc.StartInfo = abcinfo
abc.Start()
Dim abclog As System.IO.StreamReader = abc.StandardError
abc.BeginOutputReadLine()
TextBox1.Text = abclog.ReadToEnd()
abc.WaitForExit()
=======================
This opens up the executable file i.e. server but CMD screen appears as blank and I have close it to check the details in textbox. Once I close it, textbox displays the contents of the ABC server which is just closed. I can have the contents but my server is not running now!!
So I want that once I click the 'Start Server' button, (a) it should launch the exe program i.e. server, (b) keep the window invisible (the dos window it uses should not be visible to user nor should minimized on taskbar.) (c) Captures the contents of that DOS window and display them in the textbox on my form (d) Most important, update the contents of the abc server whenever new traces are logged in the server screen i.e. new line added on DOS screen.
Basically, I will be having multiple instaces of this server intance and I dont want users to see at every instance to check the logs. Once they select perticular abc server instance from listbox, textbox should display the live contents from associated DOS executable window.
I have searched lots of thread but did not find the answer. Any help would be greatly appreciated!!!
P.S: This server is developed in C and I believe is not a console application.
Thanks, Prashant
Sorry, but I couldn't quite figure out what you are trying to do, but if you want to redirect output in DOS-window (=cmd.exe), here's how to do it:
your.exe yourparameter1 yourparameter2 >redirect_here.log 2>&1
The first > redirects the sysout to redirect_here.log -file and the 2>&1 redirects the syserr to the same file.
If you want to track what is written to the redirect_here.log -file in another DOS-window, you need to use tail.exe. If I remember correctly, you can find the tail.exe in Windows Resource Kit, but I use one bundled with UnxUtils. It's a zip -package, the tail.exe is found in \usr\local\wbin\ -folder along with other useful tools. Here's how use tail.exe:
tail -f redirect_here.log
The -f -switch means that you want the tail.exe to show the new lines as they appear in the redirect_here.log.
I have a 32 bit application that shells a second application that can be 32 or 64-bit depending upon the computer it's running on.
I only want one instance of the second application to run at a time, and I need the first application to prevent the second from being launched more than once.
I want to be able to use GetProcessesByName to obtain the running processes. This seems to work fine. It's when I attempt to obtain the module data to find out what folder the second application was run from that things fall apart.
Does anyone have a suggestion for identifying 64-bit processes and their folder of origin from a 32-bit application?
Thank you,
SH
You can use the WMI API (System.Management namespace) for this, specifically the ManagementObjectSearcher. The example below shows to get the process id and full command line from all running notepad instances.
Imports System.Management
Module Module1
Sub Main()
Dim wmi = New ManagementObjectSearcher("SELECT ProcessId, CommandLine FROM Win32_Process WHERE CommandLine LIKE ""%notepad%""")
Dim result = wmi.Get().OfType(Of ManagementObject)()
For Each r In result
Console.WriteLine("Process ID: {0}, Command Line: {1}" r("ProcessId"), r("CommandLine"))
Next
End Sub
End Module
I think it could be easier if you set a Mutex when launching second app.
In main app you could do this: if Mutex doesn't exist you run second app (which creates Mutex when run and release it when closing), otherwise you skip...
EDITED:
You can't edit second app to insert the creation of a mutex, ok.
But you can do this in main app:
Create a background worker BackgroudWorker wrk
Set a private bool to true: bool running = false
Execute wrk when you want the new app run: if (running) return; running = true;
wrk creates a Process and waits for its end
when wrk ends running = false
Just an idea...
EDITED AGAIN:
If you close first app and reopen it, user is able to run second app again.
So you could do this:
Create a background worker BackgroudWorker wrk
Write a tmp file (on NTFS it can be empty)
Execute wrk when you want the new app run:
if your tmp file exists then exit;
wrk creates a Process and waits for its end
when wrk ends deletes tmp file
With this method, even if user quits your first app, tmp file remains on hdd; so when user runs first app again, second app will not be executed.
Remeber that if user is smart enough to undestand this, he could manully delete file and the trick is done.
Finally: are you sure user cannot run directly second app?