Check the registry to see if the Control Panel is Enable or Disable

What I want here is to check the registry to see
if the status of the Control Panel is Enable or
Disable.

If it is enable, then the code below can give me the option
to disable it and else, it can allow me to enable it.
 
Please help me out what wrong of these code. Thanks ...

' Disable Control Panel in Windows XP SP3:

' System Key: [HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer]

' Value Name: NoControlPanel

' Data Type:  REG_DWORD (DWORD Value)

' Value Data: (0 = Enable, 1 = Disable)


Option Explicit
 
Dim oShell
 
Private Function KeyExists (keyName)
  Dim bKey
                 
  On Error Resume Next
 
  bKey = oShell.RegRead(keyName)
 
  If TypeName (bKey) = "0" Then

    KeyExists = False

  Else

    KeyExists = True

  End If
End Function
 
Set oShell = CreateObject("Wscript.Shell")
 
If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer") Then

  wscript.echo "The Control Panel in your Windows XP is Disable ..."

Else

Dim WSHShell, RegKey
cunocAsked:
Who is Participating?
 
nffvrxqgrcfqvvcConnect With a Mentor Commented:
You could try something like this assuming you wanted VBScript.
Option Explicit

Dim WshShell
Dim bKey

'// QueryNoControlPanel()
'// Return 0 if (NoControlPanel) doesn't exists OR the (NoControlPanel) value is equal = (0)
'// Return 1 if (NoControlPanel) value exists and is equal = (1)

If QueryNoControlPanel = 0 Then
	
  Call DisableControlPanel

End If

Set WshShell = Nothing


'//
'// Helpers
'//

Public Function QueryNoControlPanel() 

  On Error Resume Next
  Set WshShell = WScript.CreateObject("WScript.Shell")
  bKey = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel")
  If bKey = 0 Then
    QueryNoControlPanel = 0
  Else
    QueryNoControlPanel = 1
  End If

End Function

Public Sub EnableControlPanel()

  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 0, "REG_DWORD"

End Sub

Public Sub DisableControlPanel()

  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 1, "REG_DWORD"

End Sub

Open in new window

0
 
cunocAuthor Commented:
Hi all,
I worked great, but I have to go to HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel
to check whether the NoControlPanel is set as 0 or 1.

Is there a way I can see a message menu that popup when I execute this little program to tell me the Control Panel status (whether it is Disable or Enable) and given me the options to Enable or Disable or exit..

Big thanks for this and
HAPPY NEW YEAR
0
 
cunocAuthor Commented:
Hi all,
I worked great, but I have to go to HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel
to check whether the NoControlPanel is set as 0 or 1.

Is there a way I can see a message menu that popup when I execute this little program to tell me the Control Panel status (whether it is Disable or Enable) and given me the options to Enable or Disable or exit..

Big thanks for this and
HAPPY NEW YEAR
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
nffvrxqgrcfqvvcCommented:
Thanks and Happy New Year to you!

cunoc,

The example already handles this with QueryNoControlPanel() method. When it returns zero(0) the NoControlPanel either hasn't been created or if it does exist is set to 0. If QueryNoControlPanel() returns 1 then it's set to (1).
0
 
cunocAuthor Commented:
Hi egl1044,

This is I just modified, but I can not get to the point how to get it works as if it is disable then I can Enable it and else if it is Enable I can Disable.


Option Explicit
 if Hour(Time()) < 12 then
    MsgBox "Good Morning!"
   
end if

Dim WshShell
Dim bKey
 
'// QueryNoControlPanel()
'// Return 0 if (NoControlPanel) doesn't exists OR the (NoControlPanel) value is equal = (0)
'// Return 1 if (NoControlPanel) value exists and is equal = (1)
 
If QueryNoControlPanel = 0 Then
  ::MsgBox "The Control Panel in your system is currently Disable ..."
   
  WScript.Echo "The Control Panel in your system is currently Disable ..."
  Call DisableControlPanel

else
  MsgBox "The Control Panel in your system is currently Enable ..."
  ::WScript.Echo "The Control Panel in your system is currently Enable ..."
End If
 
Set WshShell = Nothing
 
 
'//
'// Helpers
'//
 
Public Function QueryNoControlPanel()  
 
  On Error Resume Next
  Set WshShell = WScript.CreateObject("WScript.Shell")
  bKey = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel")
  If bKey = 0 Then
    QueryNoControlPanel = 0
  Else
    QueryNoControlPanel = 1
  End If
 
End Function
 
Public Sub EnableControlPanel()
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 0, "REG_DWORD"
 
End Sub
 
Public Sub DisableControlPanel()
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 1, "REG_DWORD"
 
End Sub
0
 
cunocAuthor Commented:
For example, when I run the code, it would give me the option like below:

Your Control Panel is now Disable.
1. Do you want to Enable it..
2. Exit

Your Control Panel is now Enable.
1. Do you want to Disable it..
2. Exit
0
 
nffvrxqgrcfqvvcCommented:
Okay. That makes much more sense cunoc use the following for a replacment.
Option Explicit 
 
Dim WshShell 
Dim bKey 
Dim Result
Dim mb

'// query value
Result = QueryNoControlPanel

Select Case Result

  Case 0 '

    mb = MsgBox("The control panel is enabled would like to disable it now?", VbYesNo,"Option")
	
      If mb = VbYes Then
        '//disable
	Call DisableControlPanel
      End If

  Case 1 '

    mb = MsgBox("The control panel is disabled do you want to enable it now?", VbYesNo,"Option")
	  
    If mb = VbYes Then
      '//enable
	Call EnableControlPanel
    End If

End Select


Set WshShell = Nothing 
 
 
'// 
'// Helpers 
'// 
 
Public Function QueryNoControlPanel()  
 
  On Error Resume Next 
  Set WshShell = WScript.CreateObject("WScript.Shell") 
  bKey = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel") 
  QueryNoControlPanel = bkey
 
End Function 
 
Public Sub EnableControlPanel() 
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 0, "REG_DWORD" 
 
End Sub 
 
Public Sub DisableControlPanel() 
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 1, "REG_DWORD" 
 
End Sub

Open in new window

0
 
cunocAuthor Commented:
Hi egl1044:

Thanks for quick response. It works great and it is the way I wanted.

HAPPY NEW YEAR.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.