1. #1
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    VB question...

    Okay... Yesterday, I spent a few hours putting together a program to act as a simple interface that launches a program and 3 shell functions.

    One of the buttons launches "explorer.exe" (Windows Shell GUI)... I want to add the second function of shutting the program down to that button. I am a complete novice.

    Code:
    Private Sub Wshell_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Wshell.Click
            Process.Start(Environ$("SystemRoot") & ":\explorer.exe")
        End Sub
    I am pretty sure I could kill the program by adding something like...

    Code:
    Shell("Taskkill -pid ShellUI.exe")
    Would I just add that line in the sub???

    Please bear with me... As I said, I am a complete noob...

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion


    • Ad Bot

      advertising
      Beep.

        
       

  2. #2
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    Re: VB question...

    Okay... That worked... But I am sure there is a better way of doing it...

    But for now...

    I am using Visual Studio 2010 VB... How can I access the bare code from the form? I want to study what I have done using the design tools.

    The only thing showing on Form1 are the private subroutines for the buttons.

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion

  3. #3
    niemiro's Avatar
    Join Date
    Mar 2012
    Location
    District 12
    Posts
    7,865

    Re: VB question...

    Hello again :)

    I will come back to you on everything else I have yet to answer.

    I think that VB and C# provide access to the designer code in the same way. I will check this evening. If they do, click the small + next to Form1.vb, and double click on Form1.Designer.vb.

    Please note that you should never, ever, manually change code inside that file, as the designer could well just overwrite your changes, and it could even break the designer.

    Richard

  4. #4
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    Re: VB question...

    That is good to know!!! I will just have to find a standalone compiler to test my "changes" lol.

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion

  5. #5
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,725

    Re: VB question...

    Code:
    Shell("Taskkill -pid ShellUI.exe")
    This is actually bad habit, in this case you're almost limited to as much as a batch script. Use Process methods instead of Shell as well too (from the System.Diagnostics namespace).

    There's a few API's you could use as well... Get the handle to that process or just simply it's name, or mediocre way: get the PID when you start the process. Then use the Process.Kill method to kill the process.
    Automation Programmer
    Microsoft MVP [2012 - 2018]

  6. #6
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    Re: VB question...

    I am all too aware of the limitations... I can't rename the file or it fails to quit... Luckily, for this application that code works perfectly, but I am trying to learn, so I want to know every possible way that will accomplish this! (and any other function that I want to perform).

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion

  7. #7
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,725

    Re: VB question...

    This is our placeholder for the PID which is for our started process
    Code:
    Private ProcID As Integer
    To start the process:
    Code:
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    	Dim p As New Process With { _
    					.StartInfo = New ProcessStartInfo With { _
    						.FileName = "notepad.exe", _
    						.Verb = "runas" _
    					}, _
    					.EnableRaisingEvents = True _
    				}
    	p.Start()
    	ProcID = p.Id
    End Sub
    To kill that process:
    Code:
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    	If Process.GetProcesses.Where(Function(p) p.Id = ProcID).Count > 0 Then Process.GetProcessById(ProcID).Kill()
    End Sub
    Last edited by AceInfinity; 06-02-2012 at 11:19 PM.
    Automation Programmer
    Microsoft MVP [2012 - 2018]

  8. #8
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    Re: VB question...

    Okay... That is good to know, but I don't think it will work for this particular application. If I am reading that correctly, launching from button 1 will set the PID as a variable which will be used to kill the operation using button 2.

    In this case... The process is launched at winlogon so there would have to be another way to set the PID variable.

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion

  9. #9
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,725

    Re: VB question...

    If it's launched at WinLogon then you can check to see if the process exists then retrieve the PID. Or kill the process by it's name.
    Automation Programmer
    Microsoft MVP [2012 - 2018]

  10. #10
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    Re: VB question...

    Is there a way to have the program automatically query the system processes, identify and set the PID for later termination?

    I could just use the process name (ShellUI.exe) to kill it as I am doing with Shell...

    It would be...

    Process.Kill("ShellUI.exe")

    No?

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion

  11. #11
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,725

    Re: VB question...

    Quote Originally Posted by gavinzach View Post
    Is there a way to have the program automatically query the system processes, identify and set the PID for later termination?
    Depends on what you mean by "automatically".

    Quote Originally Posted by gavinzach View Post
    I could just use the process name (ShellUI.exe) to kill it as I am doing with Shell...

    It would be...

    Process.Kill("ShellUI.exe")

    No?
    Nope... There could be multiple processes with the same name. And Kill() assumes one process. Unless you want to kill them all by that name?

    Code:
    Array.ForEach(Of Process)(Process.GetProcessesByName("ShellUI.exe"), Sub(x) x.Kill())
    Automation Programmer
    Microsoft MVP [2012 - 2018]

  12. #12
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    Re: VB question...

    Automatically... Like when the program loads, get it's PID.

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion

  13. #13
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,725

    Re: VB question...

    Get the PID of what though? In the context of "it's"?
    Automation Programmer
    Microsoft MVP [2012 - 2018]

  14. #14
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,725

    Re: VB question...

    Here's a way that I came up with to get all the PID's of a certain process name:

    Code:
    Dim PIDs As Integer() = Process.GetProcessesByName("notepad").Select(Function(p) p.Id).ToArray
    If PIDs.Count > 0 Then MessageBox.Show(String.Join(", ", PIDs))
    When the program starts up, depending on whether this is a console app or a windows form app, you'll either have the main form constructor, the form_load event or the main() method as the entrypoint for the actual program code to start, in which you could place this code. It would then check as soon as you start the program.
    Last edited by AceInfinity; 06-03-2012 at 08:24 PM.
    Automation Programmer
    Microsoft MVP [2012 - 2018]

Log in

Log in