Results 1 to 15 of 15

Thread: [RESOLVED] [2005] Process questions

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Resolved [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?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Process questions

    Start a process with command arguments like this:
    VB Code:
    1. Process.Start("C:\test.exe","-command1 -command2")

    I know you can get the number of processor cores with the performancecounter, one second..
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim coreCount As Integer = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE\DESCRIPTION\System\CentralProcessor").GetSubKeyNames.Length
    2.         MessageBox.Show(CStr(coreCount))
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Process questions

    How would I terminate that specific process that I started?

  6. #6
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Process questions

    Quote 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

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim p As Process = Process.Start("C:\test.exe", "-command1 -command2")
    2.         'Calling CloseMainWindow is like pressing the X on the window, it will prompt the user to save his/her work if needed.
    3.         p.CloseMainWindow()
    4.         'Wait 5 seconds for the process to close
    5.         p.WaitForExit(5000)
    6.         'If it still hasnt closed, kill it.
    7.         If Not p.HasExited Then
    8.             p.Kill()
    9.         End If
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Process questions

    Good stuff Atheist. I should probably try to be more gentle with my Processes.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    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.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    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:
    1. Dim cpu0 As Int16 = "0x0001"
    2.         srcIN.ProcessorAffinity = cpu0

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Process questions

    Anyone?

  14. #14
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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:
    1. p.ProcessorAffinity = New IntPtr(1)
    perhaps?

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    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
  •  



Click Here to Expand Forum to Full Width