Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Declare Function ExitWindowsEx Lib "user32" (ByVal _
uFlags As Long, ByVal dwReserved As Long) As Long
Public Const HKEY_CLASSES_ROOT = &H80000000
Declare Function RegCreateKey Lib "advapi32.dll" _
Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal _
lpSubKey As String, phkResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal Hkey As Long) As Long
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
Public Const REG_SZ = 1
Public Const REG_DWORD = 4
Public Sub savestring(Hkey As Long, strPath As _
String, strValue As String, strdata As String)
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, _
REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub
Form Code
On the form put 1 command button and add the following code to the click event:
Private Sub Command1_Click()
'prompts for new name
strString$ = InputBox("Please type in a string to save to the Registry.", "Recycle Bin")
If strString$ = Empty Then
'string is empty or cancel is pressed
MsgBox "Empty String", vbCritical, "Error"
Exit Sub
End If
'API call to store new name
Call savestring(HKEY_CLASSES_ROOT, _
"CLSID\{645FF040-5081-101B-9F08-00AA002F954E}", _
(pre), strString$)
MsgBox "Reset your PC", , "Changes are made"
'resets your PC
t& = ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
End Sub