Disable - Enable Windows Task Manager(Win XP - Vista - 7)

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Disable - Enable Windows Task Manager(Win XP - Vista - 7)

Post by RASHAD »

Run as admin

Code: Select all

Procedure CreateKey(topKey, sKeyName.s, ComputerName.s) 
    If ComputerName = "" 
        GetHandle = RegCreateKeyEx_(topKey, sKeyName, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, @lpSecurityAttributes, @hNewKey, @GetHandle) 
    Else 
        lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
        GetHandle = RegCreateKeyEx_(lhRemoteRegistry, sKeyName, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, @lpSecurityAttributes, @hNewKey, @GetHandle) 
    EndIf 

    If GetHandle = #ERROR_SUCCESS 
        GetHandle = RegCloseKey_(hNewKey) 
        CreateKey = 1 
    Else 
        CreateKey = 0 
    EndIf 
    ProcedureReturn CreateKey 
  EndProcedure
  
  Procedure SetValue(topKey.l, sKeyName.s, sValueName.s, vValue.s, lType.l, ComputerName.s) 
 
  If ComputerName = "" 
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 

   If GetHandle = #ERROR_SUCCESS     
    Select lType 
      Case #REG_SZ 
        GetHandle = RegSetValueEx_(hkey, sValueName, 0, #REG_SZ, @vValue, Len(vValue) + 1) 
      Case #REG_DWORD 
        lValue = Val(vValue) 
        GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_DWORD, @lValue, 4) 
    EndSelect 
      
    RegCloseKey_(hkey) 
    SetValue = 1 
   Else 
    RegCloseKey_(hKey)
    SetValue = 0 
  EndIf
  ProcedureReturn SetValue
EndProcedure

Procedure DeleteKey(topKey.l, sKeyName.s, ComputerName.s) 
   
    If ComputerName = "" 
        GetHandle = RegDeleteKey_(topKey, @sKeyName) 
    Else 
        lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
        GetHandle = RegDeleteKey_(lhRemoteRegistry, @sKeyName) 
    EndIf 

    If GetHandle = #ERROR_SUCCESS 
        DeleteKey = 1 
    Else 
        DeleteKey = 0 
    EndIf 
    ProcedureReturn DeleteKey 
EndProcedure

sTopKey.l = #HKEY_CURRENT_USER 
sKeyName.s = "SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"

;**********************( Disable Task Manager )*****************************
;
CreateKey(sTopKey, sKeyName, "")
SetValue(sTopKey, sKeyName, "DisableTaskMgr", "01", #REG_DWORD, "")

;**********************(Enable Task Manager )*******************************

;DeleteKey(sTopKey, sKeyName, "") 

Egypt my love
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by Mistrel »

This can be done through the group policy editor as well. However, your code may be useful for XP Home which does not support group policies.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by RASHAD »

Hi Mistrel
This code to disable Ctrl-Alt-Del Task switching temporary from your program and enable it back
before exit
A small tip I hope that it will be used legally
And thank you for "XP Home does not support group policies" I did not know that before

Have a good day
Egypt my love
User avatar
Alireza
Enthusiast
Enthusiast
Posts: 143
Joined: Sat Aug 16, 2008 2:02 pm
Location: Iran

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by Alireza »

Thanks, on 7 os was OK :D
PB v 5.6 :D
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by Mistrel »

If you set this in the registry and your program crashes.. you've now just locked the computer out of the task manager. :|
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by RASHAD »

The programmer must be smart enough to handle such cases
I faced at least 2 programs that Win 7 could not handle even with log off/log on
From start why someone want to disable the Task Manger?
Frankly speaking
I do not know.
The problem is you can even disable (log off/log on - User Switching - Change Password...etc.)
and all are designed by Microsoft :mrgreen:
M$ must have a good reason for that
You know ,there is a code to disable Ctrl-Alt-Del for Win XP ,Vista and 7 but I will not post it
because I do not find any good reason for that, though the net is full of that request
Egypt my love
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by PB »

> If you set this in the registry and your program crashes..
> you've now just locked the computer out of the task manager.

Not really. There's a million Task Manager replacements for download.
Locking the Windows one like this is, quite frankly, a useless gesture.
It takes less than a minute to find, download and run another one.
DTaskManager is a good free one: http://dimio.altervista.org/eng/
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Flower
User
User
Posts: 22
Joined: Fri Jan 08, 2010 8:05 am
Location: United States

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by Flower »

PB wrote:> If you set this in the registry and your program crashes..
> you've now just locked the computer out of the task manager.

Not really. There's a million Task Manager replacements for download.
Locking the Windows one like this is, quite frankly, a useless gesture.
It takes less than a minute to find, download and run another one.
DTaskManager is a good free one: http://dimio.altervista.org/eng/
And the most famous Process Explorer. :mrgreen:
Registered PureBasic user since 4.50
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by Kwai chang caine »

Thanks RASHAD , good on XP PRO SP3 8)
ImageThe happiness is a road...
Not a destination
Flower
User
User
Posts: 22
Joined: Fri Jan 08, 2010 8:05 am
Location: United States

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by Flower »

Code: Select all

Define buffer.s
buffer = Space(#MAX_PATH)
GetWindowsDirectory_(@buffer, #MAX_PATH)
buffer + "\System32\Taskmgr.exe"
CreateFile_(@buffer, #GENERIC_READ, #Null, #Null, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, #Null)
Repeat
      Sleep_(10)      
ForEver
How about this one? :mrgreen:
Registered PureBasic user since 4.50
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Re: Disable - Enable Windows Task Manager(Win XP - Vista - 7

Post by Baldrick »

Flower wrote: How about this one? :mrgreen:
Haven't checked any of the other snippets here, but with yours, if you have the taskmanager set to minimize to systray ( which I have mine set to do at computer startup ) then all you do is click on the tray icon & you have a task manager.... :mrgreen: :mrgreen:
Post Reply