Jump to content

How to kill a running process?VB 8

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
19 replies to this topic

#1
networkmancer

networkmancer

    Newbie

  • Members
  • Pip
  • 8 posts
How to kill a process?
I tried this and gives me an error

Dim RunningProcess As System.Diagnostics.Process = Process.GetProcessesByName("explorer.exe")(0)

RunningProcess.Kill()


and also Any code for enabling Task Manager, Regedit and Folder Option in VB 8? :rolleyes:

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
What error do you get?
sudo rm -rf /

#3
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
Not sure why you would want to do such a thing.

That being said, your code looks OK, but I don't
think you need ("explorer.exe") try ("explorer").

In addition, I think explorer will reinstate itself,
so you have to find the registry setting to disable that.

Good Luck

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
I think explorer.exe was just an example. Not to long ago someone else on the VB forum was creating a taskkiller app for a school to prevent games and such from running.
sudo rm -rf /

#5
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts

dargueta said:

I think explorer.exe was just an example. Not to long ago someone else on the VB forum was creating a taskkiller app for a school to prevent games and such from running.
I understand dargueta,
Don't you hate it when they prevent games from running :cursing:

I revise my post, there is no way to kill a process :closedeyes:

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
I completely disagree. Give me twenty minutes and I'll show you how.
sudo rm -rf /

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
Ok, so I think I know what your problem is - your program doesn't have the SeDebugPrivilege enabled. VB is unfortunately ill-suited for the task of enabling privileges; I can show you how to do it, but I really don't think it's worth it. This is the code in C:

#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "cmcfg32.lib")

BOOL SetPrivilege(
    HANDLE hToken,          // access token handle
    LPCTSTR lpszPrivilege,  // name of privilege to enable/disable
    BOOL bEnablePrivilege   // to enable or disable privilege
    ) 
{
	TOKEN_PRIVILEGES tp;
	LUID luid;

	if ( !LookupPrivilegeValue( 
			NULL,            // lookup privilege on local system
			lpszPrivilege,   // privilege to lookup 
			&luid ) )        // receives LUID of privilege
	{
		printf("LookupPrivilegeValue error: %u\n", GetLastError() ); 
		return FALSE; 
	}

	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	if (bEnablePrivilege)
		tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	else
		tp.Privileges[0].Attributes = 0;

	// Enable the privilege or disable all privileges.

	if ( !AdjustTokenPrivileges(
		   hToken, 
		   FALSE, 
		   &tp, 
		   sizeof(TOKEN_PRIVILEGES), 
		   (PTOKEN_PRIVILEGES) NULL, 
		   (PDWORD) NULL) )
	{ 
		  printf("AdjustTokenPrivileges error: %u\n", GetLastError() ); 
		  return FALSE; 
	} 

	if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)

	{
		  printf("The token does not have the specified privilege. \n");
		  return FALSE;
	} 

	return TRUE;
}

It'd take even more in VB.
sudo rm -rf /

#8
-Steve-

-Steve-

    Newbie

  • Members
  • Pip
  • 4 posts
For Each ObjPro As Process In Process.GetProcessesByName("msnmsgr")
ObjPro.Kill()
Do Until ObjPro.HasExited = True
Application.DoEvents()
Loop
Next

this code will kill any process you want, add it to a timer to make the process obsolete. Hope this helped.

LeetCoders.org

#9
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
Networkmancer,
here is yout original post:

networkmancer said:

How to kill a process?
I tried this and gives me an error

Dim RunningProcess As System.Diagnostics.Process = Process.GetProcessesByName("explorer.exe")(0)

RunningProcess.Kill()


and also Any code for enabling Task Manager, Regedit and Folder Option in VB 8? :rolleyes:

Here is my first reply to your post:

debtboy said:

Not sure why you would want to do such a thing.

That being said, your code looks OK, but I don't
think you need ("explorer.exe") try ("explorer").

In addition, I think explorer will reinstate itself,
so you have to find the registry setting to disable that.

Good Luck

So there was no misunderstanding, I created and ran an example
which shows what I was saying...

Posted Image

Notice the taskbar
Now I run the program:

Posted Image

Notice the info in the textbox and more importantly
Notice the missing taskbar
Now after about 15 seconds it reinstates itself

Posted Image

I believe a setting in the registry will disable the auto-reload,
I could find it, but it's better that you do.

Everything worked without error in VB.
I ran it as a normal user.

Good Luck ;)

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
What the hell?! I keep getting "Access Denied" on my own laptop. Actually it's a company laptop running XP Enterprise - that's probably why.
sudo rm -rf /

#11
-Steve-

-Steve-

    Newbie

  • Members
  • Pip
  • 4 posts
have u tried my method?

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
No, though I will later. VB6 was my first programming language, so I never really got used to .NET before I switched to C/C++.
sudo rm -rf /