Results 1 to 3 of 3

Thread: Disable Ctrl-Alt-Delete in .net

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Durham, NC
    Posts
    28

    Disable Ctrl-Alt-Delete in .net

    I am writing a program for my school that restricts access to various areas. This has been asked before for regular VB but I would like to know if it's possible to disable Ctrl-Alt-Delete for both Windows 9x and NT/2000. I've seen various samples of code for disabling it in 9x and NT/2000 for regular Visual Basic but I wouldn't know how to get that to work in .net.

    Is it possible to do this? If not what's a good way to prevent people from closing my program down using the task manager?

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Most of the ways to disable the CTRL-ALT-DELETE is done through the API in VB6 if I remember. You can still use those API calls in .Net, you will just have to change a few things here and there.

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    but there is no way to disable that in windows nt/xp/2k, that is, as far as I know. I have a code in vb6 which disables the task manager though, you can easily write it in .NET, because the code is just changing a simple registery value: (dunno who gave me the code).

    VB Code:
    1. '**************************************
    2. 'Windows API/Global Declarations for i
    3. '     sable Ctrl-Alt-Del in NT,2000,XP
    4. '**************************************
    5. Public Const HKEY_CLASSES_ROOT = &H80000000
    6. Public Const HKEY_CURRENT_USER = &H80000001
    7. Public Const HKEY_LOCAL_MACHINE = &H80000002
    8. Public Const HKEY_USERS = &H80000003
    9. Public Const HKEY_PERFORMANCE_DATA = &H80000004
    10. Public Const ERROR_SUCCESS = 0&
    11.  
    12.  
    13. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
    14.  
    15.  
    16. Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    17.  
    18.  
    19. Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
    20.  
    21.  
    22. Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
    23.  
    24.  
    25. Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    26.  
    27.  
    28. Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    29.  
    30.  
    31. Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    32.     Public Const REG_SZ = 1 ' Unicode nul terminated String
    33.     Public Const REG_DWORD = 4 ' 32-bit number
    34.  
    35.  
    36. Public Sub savekey(Hkey As Long, strPath As String)
    37.     Dim keyhand&
    38.     r = RegCreateKey(Hkey, strPath, keyhand&)
    39.     r = RegCloseKey(keyhand&)
    40. End Sub
    41.  
    42.  
    43. Public Function getstring(Hkey As Long, strPath As String, strValue As String)
    44.     'EXAMPLE:
    45.     '
    46.     'text1.text = getstring(HKEY_CURRENT_USE
    47.     '
    48.     ' R, "Software\VBW\Registry", "String")
    49.     '
    50.     Dim keyhand As Long
    51.     Dim datatype As Long
    52.     Dim lResult As Long
    53.     Dim strBuf As String
    54.     Dim lDataBufSize As Long
    55.     Dim intZeroPos As Integer
    56.     r = RegOpenKey(Hkey, strPath, keyhand)
    57.     lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
    58.  
    59.  
    60.     If lValueType = REG_SZ Then
    61.         strBuf = String(lDataBufSize, " ")
    62.         lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
    63.  
    64.  
    65.         If lResult = ERROR_SUCCESS Then
    66.             intZeroPos = InStr(strBuf, Chr$(0))
    67.  
    68.  
    69.             If intZeroPos > 0 Then
    70.                 getstring = Left$(strBuf, intZeroPos - 1)
    71.             Else
    72.                 getstring = strBuf
    73.             End If
    74.         End If
    75.     End If
    76. End Function
    77.  
    78.  
    79. Public Sub savestring(Hkey As Long, strPath As String, strValue As String, strData As String)
    80.     'EXAMPLE:
    81.     '
    82.     'Call savestring(HKEY_CURRENT_USER, "Sof
    83.     '
    84.     ' tware\VBW\Registry", "String", text1.t
    85.     '     ex
    86.     ' t)
    87.     '
    88.     Dim keyhand As Long
    89.     Dim r As Long
    90.     r = RegCreateKey(Hkey, strPath, keyhand)
    91.     r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    92.     r = RegCloseKey(keyhand)
    93. End Sub
    94.  
    95.  
    96. Function getdword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
    97.     'EXAMPLE:
    98.     '
    99.     'text1.text = getdword(HKEY_CURRENT_USER
    100.     '
    101.     ' , "Software\VBW\Registry", "Dword")
    102.     '
    103.     Dim lResult As Long
    104.     Dim lValueType As Long
    105.     Dim lBuf As Long
    106.     Dim lDataBufSize As Long
    107.     Dim r As Long
    108.     Dim keyhand As Long
    109.     r = RegOpenKey(Hkey, strPath, keyhand)
    110.     ' Get length/data type
    111.     lDataBufSize = 4
    112.     lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
    113.  
    114.  
    115.     If lResult = ERROR_SUCCESS Then
    116.  
    117.  
    118.         If lValueType = REG_DWORD Then
    119.             getdword = lBuf
    120.         End If
    121.         'Else
    122.         'Call errlog("GetDWORD-" & strPath, Fals
    123.         '
    124.         ' e)
    125.     End If
    126.     r = RegCloseKey(keyhand)
    127. End Function
    128.  
    129.  
    130. Function SaveDword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
    131.     'EXAMPLE"
    132.     '
    133.     'Call SaveDword(HKEY_CURRENT_USER, "Soft
    134.     '     ware\VBW\Registry", "Dword", text1.text)
    135.     '
    136.     '
    137.     '
    138.     Dim lResult As Long
    139.     Dim keyhand As Long
    140.     Dim r As Long
    141.     r = RegCreateKey(Hkey, strPath, keyhand)
    142.     lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
    143.     'If lResult <> error_success Then
    144.     ' Call errlog("SetDWORD", False)
    145.     r = RegCloseKey(keyhand)
    146. End Function
    147.  
    148.  
    149. Public Function DeleteKey(ByVal Hkey As Long, ByVal strKey As String)
    150.     'EXAMPLE:
    151.     '
    152.     'Call DeleteKey(HKEY_CURRENT_USER, "Soft
    153.     '
    154.     ' ware\VBW")
    155.     '
    156.     Dim r As Long
    157.     r = RegDeleteKey(Hkey, strKey)
    158. End Function
    159.  
    160.  
    161. Public Function DeleteValue(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String)
    162.     'EXAMPLE:
    163.     '
    164.     'Call DeleteValue(HKEY_CURRENT_USER, "So
    165.     '
    166.     ' ftware\VBW\Registry", "Dword")
    167.     '
    168.     Dim keyhand As Long
    169.     r = RegOpenKey(Hkey, strPath, keyhand)
    170.     r = RegDeleteValue(keyhand, strValue)
    171.     r = RegCloseKey(keyhand)
    172. End Function
    173.  
    174.  
    175.  
    176. Public Sub TaskManagerEnabled(ByVal isEnabled As Boolean)
    177.     If Not isEnabled Then
    178.         Call SaveDword(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "1")
    179.     Else
    180.         Call SaveDword(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "0")
    181.     End If
    182. End Sub



    dont be scared by the length of it, you can probably do that in a few lines in .NET. It's just changing a reg value
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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