none
Process Kill :) RRS feed

Answers

  • I told you not to play with truncation :). In that line procedure tries to get out of the string boundaries. Did you ever see syntax of Substring command? This error is an example of typical RTFM. However, just change that line to:
    selProcess = selProcess->SubString(0, selProcess->Length - 4);
    Regards.
    Festina lente
    • Marked as answer by Cha0sBG® Wednesday, October 22, 2008 8:51 AM
    Tuesday, October 21, 2008 11:36 PM

All replies

  • Hi Friend, It depends on how you are getting a reference to the process.
    If you have a managed object (an object of the Process class), its as easy as just calling processObj.Kill();

    You can Get the list of running processes by calling System.Diagnostics.process.GetProcesses(), it will return a process array. You can populate the listBox using the processObj[x].WindowTitle or ModuleName. Then get the index of the selected process, call processObj[index].Kill();

    Hope this will help...

    Aldo John, Nexgen Technology Services, Bangalore
    Sunday, October 19, 2008 6:20 PM
  • for each (System::Diagnostics::Process^ iterator in System::Diagnostics::Process::GetProcesses()) 
                        {                        
                            listBox1->Items->Add(iterator->ProcessName +".exe"); 
                                }  
    here is how i get it :)
    and set it to a list :) hope u can make an example how to terminate it :p
    Sunday, October 19, 2008 7:25 PM
  • Ok... I had given the c# equivalent of this. I am not good in c++ still i can help you with this prob.
    Here you are getting an iterator directly to the process list. Instead load the process references into an array first so that you will have the list in memory (List box has only the text, its not a reference no...).

    System::Diagnostics::Process[] p = System::Diagnostics::Process::GetProcesses();

    Then load the list box as you have done, but from the array. Then to kill you can use...
    p[get the index of selected item in listbox]->Kill();

    I am not sure with the syntax.. Pls check it out yourself...

    If you dont want to hold an array of references, ok, When deleting, get the processlist again, search for the processName which is selected and call Kill on that process.... But this is a very bad logic. Better keep the array....


    Aldo John, Nexgen Technology Services, Bangalore
    Sunday, October 19, 2008 7:44 PM
  • Not sure i will try to make something of this leater :D
    but if someone comes and does something that will be good too :P
    Sunday, October 19, 2008 7:49 PM
  • Hi again. Are you trying to do some kind of CLR Task Manager :)? At first here is a link about terminating processes. And in your case code will be something like this: 
    for each (System::Diagnostics::Process^ iterator in 
    System::Diagnostics::Process::GetProcessesByName(listBox1->SelectedItem->ToString()))
    {
    iterator->Kill();
    } 
    Problem is that several processes can share same name. So if you want to terminate only one of them, you should store their IDs, not names in your listBox.

    Festina lente
    Monday, October 20, 2008 9:36 AM
  • Well yes it's some kind of process manager but with more functions when i learn more :D
    But well i'm gonna explain what's happening here hope u will know how to help :)

    Here is the Full Code of my program :) and may i remind :P i'm using .Net .... CLR app type :)
    So Here is the full code :P
    1#include "windows.h" 
    2#include "Winbase.h" 
    3
    4#pragma once 
    5 
    6 
    7namespace ProcessManager { 
    8 
    9    using namespace System; 
    10    using namespace System::ComponentModel; 
    11    using namespace System::Collections; 
    12    using namespace System::Windows::Forms; 
    13    using namespace System::Data; 
    14    using namespace System::Drawing; 
    15 
    16    /// <summary> 
    17    /// Summary for Form1 
    18    /// 
    19    /// WARNING: If you change the name of this class, you will need to change the 
    20    ///          'Resource File Name' property for the managed resource compiler tool 
    21    ///          associated with all .resx files this class depends on.  Otherwise, 
    22    ///          the designers will not be able to interact properly with localized 
    23    ///          resources associated with this form. 
    24    /// </summary> 
    25    public ref class Form1 : public System::Windows::Forms::Form 
    26    { 
    27    public
    28        Form1(void
    29        { 
    30            InitializeComponent(); 
    31            // 
    32            //TODO: Add the constructor code here 
    33            // 
    34        } 
    35 
    36    protected
    37        /// <summary> 
    38        /// Clean up any resources being used. 
    39        /// </summary> 
    40        ~Form1() 
    41        { 
    42            if (components) 
    43            { 
    44                delete components; 
    45            } 
    46        } 
    47    private: System::Windows::Forms::Button^  button1; 
    48    protected:  
    49    private: System::Windows::Forms::ListBox^  listBox1; 
    50    private: System::Windows::Forms::Button^  button2; 
    51 
    52    private
    53        /// <summary> 
    54        /// Required designer variable. 
    55        /// </summary> 
    56        System::ComponentModel::Container ^components; 
    57
    58#pragma region Windows Form Designer generated code 
    59        /// <summary> 
    60        /// Required method for Designer support - do not modify 
    61        /// the contents of this method with the code editor. 
    62        /// </summary> 
    63        void InitializeComponent(void
    64        { 
    65            this->button1 = (gcnew System::Windows::Forms::Button()); 
    66            this->listBox1 = (gcnew System::Windows::Forms::ListBox()); 
    67            this->button2 = (gcnew System::Windows::Forms::Button()); 
    68            this->SuspendLayout(); 
    69            //  
    70            // button1 
    71            //  
    72            this->button1->Location = System::Drawing::Point(12, 8); 
    73            this->button1->Name = L"button1"
    74            this->button1->Size = System::Drawing::Size(100, 28); 
    75            this->button1->TabIndex = 0; 
    76            this->button1->Text = L"Refresh List"
    77            this->button1->UseVisualStyleBackColor = true
    78            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); 
    79            //  
    80            // listBox1 
    81            //  
    82            this->listBox1->BackColor = System::Drawing::SystemColors::MenuText; 
    83            this->listBox1->ForeColor = System::Drawing::Color::Red; 
    84            this->listBox1->FormattingEnabled = true
    85            this->listBox1->Location = System::Drawing::Point(12, 42); 
    86            this->listBox1->Name = L"listBox1"
    87            this->listBox1->Size = System::Drawing::Size(274, 108); 
    88            this->listBox1->TabIndex = 1; 
    89            //  
    90            // button2 
    91            //  
    92            this->button2->Location = System::Drawing::Point(185, 8); 
    93            this->button2->Name = L"button2"
    94            this->button2->Size = System::Drawing::Size(101, 27); 
    95            this->button2->TabIndex = 2; 
    96            this->button2->Text = L"End Process"
    97            this->button2->UseVisualStyleBackColor = true
    98            this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); 
    99            //  
    100            // Form1 
    101            //  
    102            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 
    103            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
    104            this->BackColor = System::Drawing::SystemColors::ActiveCaptionText; 
    105            this->ClientSize = System::Drawing::Size(298, 267); 
    106            this->Controls->Add(this->button2); 
    107            this->Controls->Add(this->listBox1); 
    108            this->Controls->Add(this->button1); 
    109            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D; 
    110            this->Name = L"Form1"
    111            this->Text = L"Process Manager Deluxe"
    112            this->ResumeLayout(false); 
    113 
    114        } 
    115#pragma endregion 
    116    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)  
    117             { 
    118                  listBox1->Items->Clear(); 
    119             
    120        for each (System::Diagnostics::Process^ iterator in System::Diagnostics::Process::GetProcesses()) 
    121                    {                        
    122                        listBox1->Items->Add(iterator->ProcessName +".exe"); 
    123                            }  
    124             } 
    125    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e)  
    126             { 
    127                 for each (System::Diagnostics::Process^ iterator in  
    128    System::Diagnostics::Process::GetProcessesByName(listBox1->SelectedItem->ToString())) 
    129    { 
    130iterator->Kill(); 
    131    }  
    132             } 
    133    }; 
    134
    So there is it :)
    My Problem is when i press the second button the end proccess one it does nothing :S hope u can help
    Monday, October 20, 2008 11:17 AM
  • When you call GetProcessesByName() the argument you are passing will also contain the '.exe' extention. Remove the extention from the Listbox selected item and try...

    Like what you are trying now is : GetProcessesByName("notepad.exe")
    But it should be GetProcessesByName("notepad")
    Aldo John, Nexgen Technology Services, Bangalore
    • Marked as answer by Cha0sBG® Monday, October 20, 2008 11:58 AM
    • Unmarked as answer by Cha0sBG® Monday, October 20, 2008 1:13 PM
    Monday, October 20, 2008 11:30 AM
  • yeah removing the extention .exe worked but is there a way to have that extention and the program will close the process??

    Monday, October 20, 2008 12:00 PM
  • Of course. Seems like you removed the extention even from the listBox. Keep the extention in the listBox and when you press the Kill/Remove Button... Do the following...

    string selProcess = listbox->selectedItem->ToString();
    selProcess = selProcess->SubString(selProcess->Length-4,selProcess->Length);

    This will remove the '.exe' and then pass this to GetProcessesByName(selProcess);

    Pls check with the syntax and operators...Not sure if its the -> operator or . operator..hehe

    Aldo John, Nexgen Technology Services, Bangalore
    Monday, October 20, 2008 12:09 PM
  • string selProcess = listbox->selectedItem->ToString(); 
                     selProcess = selProcess->SubString(selProcess->Length-4,selProcess->Length); 
                     for each (System::Diagnostics::Process^ iterator in  
        System::Diagnostics::Process::GetProcessesByName(selProcess)) 

    Is this the way ? cuz it gives error >.< or am i such a newb i can't even add code in the right place :S
    Monday, October 20, 2008 12:17 PM
  • No, you have put the code in the right place...
    Can you tell me what is the error you are getting??

    Aldo John, Nexgen Technology Services, Bangalore
    Monday, October 20, 2008 12:34 PM
  • well bro when i start the program it's all good but then when i execute it at visual studio and when i press the end process button on a process i have started for the reason of testing the project bugs and the good visual studio error with "Continue" and "break" buttons comes up :)

    Now the damn 30 errors saying undeclared indentafier :D (sorry for my bad spelling)

    i will post my full code again cuz i may have mixed something up again cuz i redone it :)
    #include "windows.h" 
    #include "Winbase.h" 
    #pragma once 
     
     
    namespace ProcessManager { 
     
        using namespace System; 
        using namespace System::ComponentModel; 
        using namespace System::Collections; 
        using namespace System::Windows::Forms; 
        using namespace System::Data; 
        using namespace System::Drawing; 
     
        /// <summary> 
        /// Summary for Form1 
        /// 
        /// WARNING: If you change the name of this class, you will need to change the 
        ///          'Resource File Name' property for the managed resource compiler tool 
        ///          associated with all .resx files this class depends on.  Otherwise, 
        ///          the designers will not be able to interact properly with localized 
        ///          resources associated with this form. 
        /// </summary> 
        public ref class Form1 : public System::Windows::Forms::Form 
        { 
        public
            Form1(void
            { 
                InitializeComponent(); 
                // 
                //TODO: Add the constructor code here 
                // 
            } 
     
        protected
            /// <summary> 
            /// Clean up any resources being used. 
            /// </summary> 
            ~Form1() 
            { 
                if (components) 
                { 
                    delete components; 
                } 
            } 
        private: System::Windows::Forms::Button^  button1; 
        protected:  
        private: System::Windows::Forms::ListBox^  listBox1; 
        private: System::Windows::Forms::Button^  button2; 
     
        private
            /// <summary> 
            /// Required designer variable. 
            /// </summary> 
            System::ComponentModel::Container ^components; 
    #pragma region Windows Form Designer generated code 
            /// <summary> 
            /// Required method for Designer support - do not modify 
            /// the contents of this method with the code editor. 
            /// </summary> 
            void InitializeComponent(void
            { 
                this->button1 = (gcnew System::Windows::Forms::Button()); 
                this->listBox1 = (gcnew System::Windows::Forms::ListBox()); 
                this->button2 = (gcnew System::Windows::Forms::Button()); 
                this->SuspendLayout(); 
                //  
                // button1 
                //  
                this->button1->Location = System::Drawing::Point(12, 8); 
                this->button1->Name = L"button1"
                this->button1->Size = System::Drawing::Size(100, 28); 
                this->button1->TabIndex = 0; 
                this->button1->Text = L"Refresh List"
                this->button1->UseVisualStyleBackColor = true
                this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); 
                //  
                // listBox1 
                //  
                this->listBox1->BackColor = System::Drawing::SystemColors::MenuText; 
                this->listBox1->ForeColor = System::Drawing::Color::Red; 
                this->listBox1->FormattingEnabled = true
                this->listBox1->Location = System::Drawing::Point(12, 42); 
                this->listBox1->Name = L"listBox1"
                this->listBox1->Size = System::Drawing::Size(274, 108); 
                this->listBox1->TabIndex = 1; 
                //  
                // button2 
                //  
                this->button2->Location = System::Drawing::Point(185, 8); 
                this->button2->Name = L"button2"
                this->button2->Size = System::Drawing::Size(101, 27); 
                this->button2->TabIndex = 2; 
                this->button2->Text = L"End Process"
                this->button2->UseVisualStyleBackColor = true
                this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); 
                //  
                // Form1 
                //  
                this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
                this->BackColor = System::Drawing::SystemColors::ActiveCaptionText; 
                this->ClientSize = System::Drawing::Size(298, 267); 
                this->Controls->Add(this->button2); 
                this->Controls->Add(this->listBox1); 
                this->Controls->Add(this->button1); 
                this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D; 
                this->Name = L"Form1"
                this->Text = L"Process Manager Deluxe"
                this->ResumeLayout(false); 
     
            } 
    #pragma endregion 
        private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)  
                 { 
                      listBox1->Items->Clear(); 
                 
            for each (System::Diagnostics::Process^ iterator in System::Diagnostics::Process::GetProcesses()) 
                        {                        
                            listBox1->Items->Add(iterator->ProcessName + ".exe"); 
                                }  
                 } 
        private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e)  
                 { 
     
            string selProcess = listbox->selectedItem->ToString();  
            selProcess = selProcess->SubString(selProcess->Length-4,selProcess->Length);  
          for each (System::Diagnostics::Process^ iterator in System::Diagnostics::Process::GetProcessesByName(selProcess))  
        { 
            iterator->Kill(); 
        }  
                 } 
        }; 
     

    • Edited by Cha0sBG® Monday, October 20, 2008 12:49 PM
    Monday, October 20, 2008 12:44 PM
  • Did you use the variable name as 'listBox'??? That was just for illustration only... you have to use the name of your listbox... i hope it is 'listBox1'...Pls try this... And if this solves the issue... you can call yourself a newbie hehe...just kidding...
    Aldo John, Nexgen Technology Services, Bangalore
    Monday, October 20, 2008 12:54 PM
  • yes i'm a total noob oO guess learning delphi , autoit, visual basic dousn't help lol :D

    Here is the build log:

    ----- Build started: Project: Process Manager, Configuration: Debug Win32 ------ 
    Compiling... 
    Process Manager.cpp 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(128) : error C2065: 'string' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(128) : error C2146: syntax error : missing ';' before identifier 'selProcess' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(128) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(128) : error C2039: 'selectedItem' : is not a member of 'System::Windows::Forms::ListBox' 
            c:\windows\microsoft.net\framework\v2.0.50727\system.windows.forms.dll : see declaration of 'System::Windows::Forms::ListBox' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(128) : error C2227: left of '->ToString' must point to class/struct/union/generic type 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2227: left of '->SubString' must point to class/struct/union/generic type 
            type is ''unknown-type'' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2227: left of '->Length' must point to class/struct/union/generic type 
            type is ''unknown-type'' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2227: left of '->Length' must point to class/struct/union/generic type 
            type is ''unknown-type'' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : fatal error C1903: unable to recover from previous error(s); stopping compilation 
    Build log was saved at "file://c:\Documents and Settings\Cha0sBG\My Documents\Visual Studio 2008\Projects\Process Manager\Process Manager\Debug\BuildLog.htm" 
    Process Manager - 14 error(s), 0 warning(s) 
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 




    And yes i have edited my code and my listbox is called listBox1 as default .
    And the code matches but don't know what's wrong

    And btw do u have skype or msn ? if u do and will be good enoth to add me so we don't have to spam the forum :) if u have and don't wanna give it to me that's ok too :)
    • Edited by Cha0sBG® Monday, October 20, 2008 1:11 PM
    Monday, October 20, 2008 1:02 PM
  • OK.. the issue is with the syntax... i am a c# guy..so not sure about the C++ syntax...
    seems like 'string' is not the keyword to create a string in C++
    also the spelling of 'SelectedItem' is wrong... 'S' is capital.
    And to call ToString() and SubString() use the dot  operator instead of '->' operator.

    Aldo John, Nexgen Technology Services, Bangalore
    Monday, October 20, 2008 1:14 PM
  • ok so here is my code:

    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e)  
                 { 
     
            string selProcess = listBox1->SelectedItem.ToString();  
            selProcess = selProcess.SubString(selProcess->Length-4,selProcess->Length);  
          for each (System::Diagnostics::Process^ iterator in System::Diagnostics::Process::GetProcessesByName(selProcess))  
        { 
            iterator->Kill(); 
        }  
                 } 


    Here is the build log:

    ------ Build started: Project: Process Manager, Configuration: Debug Win32 ------ 
    Compiling... 
    Process Manager.cpp 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2065: 'string' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2146: syntax error : missing ';' before identifier 'selProcess' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(129) : error C2228: left of '.ToString' must have class/struct/union 
            type is 'System::Object ^' 
            did you intend to use '->' instead? 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2228: left of '.SubString' must have class/struct/union 
            type is ''unknown-type'' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2227: left of '->Length' must point to class/struct/union/generic type 
            type is ''unknown-type'' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(130) : error C2227: left of '->Length' must point to class/struct/union/generic type 
            type is ''unknown-type'' 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(131) : error C2065: 'selProcess' : undeclared identifier 
    c:\documents and settings\cha0sbg\my documents\visual studio 2008\projects\process manager\process manager\Form1.h(131) : fatal error C1903: unable to recover from previous error(s); stopping compilation 
    Build log was saved at "file://c:\Documents and Settings\Cha0sBG\My Documents\Visual Studio 2008\Projects\Process Manager\Process Manager\Debug\BuildLog.htm" 
    Process Manager - 13 error(s), 0 warning(s) 
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 
     


    And here is what the allmighty online help file says about the string :)   :
    The [string] attribute indicates that the one-dimensional char, wchar_t, byte (or equivalent) array or the pointer to such an array must be treated as a string. The string can also be an array (or a pointer to an array) of constructs whose fields are all of the type byte
     
      
    typedef [ string [[ , type-attribute-list ]] ] type-specifier declarator-list;  
     
    typedef [ struct | union ]  
        [ string [[ , field-attribute-list ]] ] type-specifier declarator-list; 
        ... 
    }; 
     
    string [[ , function-attribute-list ]] ] type-specifier ptr-decl function-name( 
      [[ [ parameter-attribute-list ] ]] type-specifier [[standard-declarator]] 
      , ...); 
     
    [[ [ function-attribute-list ] ]] type-specifier [[ptr-decl]] function-name( 
        [ string [[ , parameter-attribute-list ]] ] type-specifier [[standard-declarator]] 
      , ...);  
     
    Parameters 
    type-attribute-list  
    Specifies one or more attributes that apply to a type. Valid type attributes include [handle], [switch_type], [transmit_as]; the pointer attribute [ref], [unique], or [ptr]; and the usage attributes [context_handle], [string], and [ignore]. Separate multiple attributes with commas. 
     
    type-specifier  
    Specifies a base type, struct type, or type identifier. An optional storage specification can precede type-specifier. 
     
    standard-declarator  
    Specifies a standard C declarator, such as an identifier, a pointer declarator, or an array declarator. For more information, see Array and Sized-Pointer Attributes, arrays., and Arrays and Pointers. 
     
    declarator-list  
    Specifies standard C declarators, such as identifiers, pointer declarators, and array declarators. For more information, see Array and Sized-Pointer Attributes, arrays., and Arrays and Pointers. The declarator-list consists of one or more declarators separated by commas. The parameter-name identifier in the function declarator is optional. 
     
    field-attribute-list  
    Specifies zero or more field attributes that apply to the structure, union member, or function parameter. The two valid field attributes are [max_is] and [size_is]; the usage attributes [string], [ignore], and [context_handle], the pointer attribute [ref], [unique], or [ptr], and the union attribute [switch_type]. Separate multiple field attributes with commas. 
     
    function-attribute-list  
    Specifies zero or more attributes that apply to the function. Valid function attributes are [callback], [local]; the pointer attribute [ref], [unique], or [ptr]; and the usage attributes [string], [ignore], and [context_handle]. 
     
    ptr-decl  
    Specifies an optional pointer declarator to which the [string] attribute applies. A pointer declarator is the same as the pointer declarator used in C; it is constructed from the * designator, modifiers such as far, and the qualifier const
     
    function-name  
    Specifies the name of the remote procedure. 
     
    parameter-attribute-list  
    Consists of zero or more attributes appropriate for the specified parameter type. Parameter attributes can take the directional attributes [in] and [out]; the field attributes [max_is] and [size_is]; the pointer attribute [ref], [unique], or [ptr]; and the usage attributes [context_handle] and [string]. The usage attribute [ignore] cannot be used as a parameter attribute. Separate multiple attributes with commas. 
     
    Return Value 
    This attribute does not return a value.  
    Remarks 
    If the [string] attribute is used with an array whose bounds are determined at run time, you must also specify a [size_is] or [max_is] attribute, as in the following example: 
     
     
     Copy Code  
    /* a string that can hold up to MAX_STRING_LENGTH characters */ 
    typedef [string, max_is(MAX_STRING_LENGTH)] char line[]; 
      
     
    The [string] attribute cannot be used with attributes that specify the range of transmitted elements, such as [first_is], [last_is], and [length_is]. 
     
    When used on multidimensional arrays, the [string] attribute applies to the rightmost array. 
     
    To define a counted stringdo not use the [string] attribute. Use a character array or character-based pointer such as the following: 
     
     
     Copy Code  
    typedef struct  
    {  
        unsigned short size;  
        unsigned short length;  
        [size_is(size), length_is(length)] char string[*];  
    } counted_string;  
     
    The [string] attribute specifies that the stub should use a language-supplied method to determine the length of strings. 
     
    When declaring strings in C, you must allocate space for an extra character that marks the end of the string
     
    Examples  
     Copy Code  
    /* a string type that can hold up to 80 characters */  
    typedef [stringchar line[81];  
      
    HRESULT Proc1([instringchar * pszName);  
     




    Monday, October 20, 2008 1:20 PM
  • OMG, what are you doing %)!? Why such a complications to make an easy program. At first, process can have extensions with different quantities of letters in extension, not only 3. It also can have no extension at all. In these cases your truncation script will be wrong. I told you, the better way is to store process IDs with their names together, listBox allows you to do it. Whatever, you have already decided. Error is due to wrong syntax. It should by "System::String^" instead of "string", you messed C++/CLI with Basic. 
    Festina lente
    • Marked as answer by Cha0sBG® Monday, October 20, 2008 5:02 PM
    • Marked as answer by Cha0sBG® Monday, October 20, 2008 5:02 PM
    • Unmarked as answer by Cha0sBG® Monday, October 20, 2008 8:26 PM
    • Marked as answer by Cha0sBG® Monday, October 20, 2008 8:26 PM
    • Unmarked as answer by Cha0sBG® Tuesday, October 21, 2008 1:08 PM
    Monday, October 20, 2008 4:57 PM
  • Thanks that fixed it + some othere syntax errors ;)

    damn now othere error when i end a process "An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll" with the break and continue buttons :S

    Beginner in C++ Coding /\/\ (^_^ )
    • Edited by Cha0sBG® Monday, October 20, 2008 5:04 PM
    Monday, October 20, 2008 5:02 PM
  • Anyways... The truncating of extention will work perfectly in any scenario as you are not getting the extention form the process actually...You are just adding the '.exe' manually... Anyway that is not a good practice... And i am vry sorry for the syntax issues, and as i told u i am a c# guy... ok... bye...
    Aldo John, Nexgen Technology Services, Bangalore
    Monday, October 20, 2008 5:20 PM
  • Mozok said:

    OMG, what are you doing %)!? Why such a complications to make an easy program. At first, process can have extensions with different quantities of letters in extension, not only 3. It also can have no extension at all. In these cases your truncation script will be wrong. I told you, the better way is to store process IDs with their names together, listBox allows you to do it. Whatever, you have already decided. Error is due to wrong syntax. It should by "System::String^" instead of "string", you messed C++/CLI with Basic. 


    Festina lente


    My dear fried, i think you didnt notice that our friend was simply adding a '.exe. extention to every process. So the truncating also works...

    Aldo John, Nexgen Technology Services, Bangalore
    Monday, October 20, 2008 5:23 PM
  • The problem dousn't come when i execute the application it comes when i press the end process button and it's your code Aldo John ... with his help i fixed the syntax :) that problem occurs when i press the button :S
    Beginner in C++ Coding /\/\ (^_^ )
    Monday, October 20, 2008 5:38 PM
  • ~Bumb~
    So anyone got a solution about the problem ? :D :D :D
    that error is making me sooooo mad

    Beginner in C++ Coding /\/\ (^_^ )
    Tuesday, October 21, 2008 1:09 PM
  • Insert a breakpoint into button2_click procedure and find out what exactly line causes this exception.
    Festina lente
    Tuesday, October 21, 2008 6:40 PM
  • the line with the Length-4 :)
    Beginner in C++ Coding /\/\ (^_^ )
    Tuesday, October 21, 2008 7:12 PM
  • I told you not to play with truncation :). In that line procedure tries to get out of the string boundaries. Did you ever see syntax of Substring command? This error is an example of typical RTFM. However, just change that line to:
    selProcess = selProcess->SubString(0, selProcess->Length - 4);
    Regards.
    Festina lente
    • Marked as answer by Cha0sBG® Wednesday, October 22, 2008 8:51 AM
    Tuesday, October 21, 2008 11:36 PM
  • LOL works great.
    THANKS FOR ALL YOUR HELP
    Beginner in C++ Coding /\/\ (^_^ )
    Wednesday, October 22, 2008 8:51 AM
  • You should not kill a process as a normal way to terminate it. You should kill a process only if there is a problem and the process cannot be terminated in any other manner. See KB article 178893 ("HOWTO: Terminate an Application "Cleanly" in Win32") for a Windows SDK explanation.
    Sam Hobbs; see my SimpleSamples.Info
    Sunday, November 9, 2008 10:24 AM