|
-
Jul 5th, 2007, 04:10 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Process questions
Okay, I have a few questions about processes.
First question, how would I start a process like text.exe and run commands to it like:
C:\test.exe -command1 -command2
Second question, how can I set a process's affinity using code. For now the app is just running on a dual core, so Core 0 and Core 1.
Third question, I know my application will end up on machines with more than 2 cores, so how can I list all processor cores?
-
Jul 5th, 2007, 04:15 PM
#2
Re: [2005] Process questions
Start a process with command arguments like this:
VB Code:
Process.Start("C:\test.exe","-command1 -command2")
I know you can get the number of processor cores with the performancecounter, one second..
-
Jul 5th, 2007, 04:22 PM
#3
Re: [2005] Process questions
Never mind the performancecounter, i found a key in the registry that was more useful. This code will give you the number of cores:
VB Code:
Dim coreCount As Integer = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE\DESCRIPTION\System\CentralProcessor").GetSubKeyNames.Length
MessageBox.Show(CStr(coreCount))
-
Jul 5th, 2007, 04:26 PM
#4
Re: [2005] Process questions
But then your app would need permissions to the registry key outside of the HKCU.
You could just use WMI to get the processor information.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 6th, 2007, 11:58 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Process questions
How would I terminate that specific process that I started?
-
Jul 6th, 2007, 12:10 PM
#6
Re: [2005] Process questions
 Originally Posted by tylerm
How would I terminate that specific process that I started?
You can use the Kill method.
http://msdn2.microsoft.com/en-us/lib...cess.kill.aspx
-
Jul 6th, 2007, 12:17 PM
#7
Re: [2005] Process questions
Yeah like nmadd said, the Kill method is the way to kill your process. If you however, would like to try to close it more "gently" this would be another option:
VB Code:
Dim p As Process = Process.Start("C:\test.exe", "-command1 -command2")
'Calling CloseMainWindow is like pressing the X on the window, it will prompt the user to save his/her work if needed.
p.CloseMainWindow()
'Wait 5 seconds for the process to close
p.WaitForExit(5000)
'If it still hasnt closed, kill it.
If Not p.HasExited Then
p.Kill()
End If
-
Jul 6th, 2007, 12:22 PM
#8
Re: [2005] Process questions
Good stuff Atheist. I should probably try to be more gentle with my Processes.
-
Jul 6th, 2007, 12:26 PM
#9
Re: [2005] Process questions
Yes, kill it abrupt in its process termination (is like clicking "Terminate Process" on the task manager) so anything you can do to allow the process to end properly and dispose of its own resources is best.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 6th, 2007, 12:44 PM
#10
Thread Starter
Hyperactive Member
Re: [2005] Process questions
Would the procedures still be the same in this scenario:
The application will start multiple instnaces of test.exe, each with different command attirbutes. I have a listview control that lists each setup, ie: C:\test.exe -command SETTING1 -variable SETTING1
And for setup 2:
C:\test.exe -command SETTING2 - variable SETTING2
How could I make it so they select an item in the listview and click a button, and they instance of test.exe is killed?
I'm a little confused since the method Im trying is like this:
2 buttons and a listview.
buttonStart:
Dim pTestExe As Process
pTestExe.Start(ListView1.FocusedItem.Text, "-command -command -command")
buttonStop:
?
Since the pTestExe process is not the same exact process everytime, I think there might be problems.
-
Jul 6th, 2007, 12:53 PM
#11
Re: [2005] Process questions
You will probably have multiple instances of the test.exe program in the running task list. Each will have a separate process ID number. When starting the process you may want to store it in the listitems tag property or create a hidden column for it in the listview. Thi swill help when you go to terminate the process you will be able to verify its the desired instance of test.exe by matching the process ids
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 10th, 2007, 02:47 PM
#12
Thread Starter
Hyperactive Member
Re: [2005] Process questions
Okay, so now I'm stuck on setting affinity.
I tried defining an Int16, didn't work, I've tried binary (Couldn't find a property for it).
Here was my last try:
VB Code:
Dim cpu0 As Int16 = "0x0001"
srcIN.ProcessorAffinity = cpu0
-
Jul 13th, 2007, 12:32 PM
#13
Thread Starter
Hyperactive Member
Re: [2005] Process questions
-
Jul 13th, 2007, 01:05 PM
#14
Re: [2005] Process questions
I have no experience with this but the documentation says that this property wants an IntPtr.
http://msdn2.microsoft.com/en-us/lib...ty(vs.80).aspx
Something like
vb.net Code:
p.ProcessorAffinity = New IntPtr(1)
perhaps?
-
Jul 13th, 2007, 01:09 PM
#15
Thread Starter
Hyperactive Member
Re: [2005] Process questions
Perfect. I can't believe I didn't see that.
Also for future reference. Core 0 = 1 and Core 1 = 2
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|