'Open New Project and add a module. Put
this Public declaration in module. Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long,_ ByVal lpSubKey As String, phkResult As Long) As Long Public 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 'Note that if you declare the lpData parameter as String, you must pass it By Value. Public 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 'Note that if you declare the lpData parameter as String, you must pass it By Value. Public Const EWX_FORCE = 4 Public Const EWX_REBOOT = 2 Public Const REG_SZ = 1 ' Unicode nul terminated string Public Const REG_DWORD = 4 ' 32-bit number Public Const HKEY_CURRENT_USER = &H80000001 Public Function SaveString(Hkey As Long, strPath As String, strValue As String, strData As String) Dim keyhand Dim r r = RegCreateKey(Hkey, strPath, keyhand) r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData)) r = RegCloseKey(keyhand) End Function 'Put these codes in Form Private Sub Command1_Click() On Error GoTo errorhandle a% = InputBox("Enter a number between 1 upto 1000", "Speed Range") If a% > 0 And a% < 1001 Then b$ = CStr(a%) SaveString HKEY_CURRENT_USER, "Control Panel|Desktop", "MenuShowDelay", b$ MsgBox "Reboot your computer to get new setting", , "Warning" c& = ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0) Else MsgBox "The number you entered is not valid ", , "Warning" End If Exit Sub errorhandle: End Sub |