Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using some code that LPlates provid 2

Status
Not open for further replies.

Bubbler

IS-IT--Management
Dec 14, 2003
135
US
Using some code that LPlates provided (and it works great by the way!) I am trying to figure out how to remove a registry entry during a reboot with a boot disk.

LPlates code sets the app so that if it is terminated by windows, for example pressing reset on the box , then the app restarts with windows. However the problem I am trying to solve is that the app requires a password to shut it down, let's say the user forgets their password, I want to be able to give them a 3.5 inch floppy, tell them to insert it and then reboot, when the system reboots, the "boot disk" resets the registry entry so that the app won't auto start, in other words remove the registry startup entry. Is this possible? Here is the code that creates the entry:

Const REG_SZ = 1
Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private 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

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Dim hKey As Long
Dim strRunCmd As String

If UnloadMode = vbAppWindows Then
strRunCmd = App.Path & "\" & App.EXEName & ".EXE"
Call RegCreateKey(HKEY_CURRENT_USER, _
"Software\Microsoft\Windows\CurrentVersion\RunOnce", hKey)
Call RegSetValueEx(hKey, "CCL.exe", 0&, REG_SZ, ByVal strRunCmd, _
Len(strRunCmd) + 1)
Call RegCloseKey(hKey)
End If
 
Sorry for the subject, got so involved with the submission, forgot to put in a subject for the post!
 
Hi Bubbler, Use the RegDeleteKey or SHDeleteKey API

Private Declare Function SHDeleteKey Lib "shlwapi.dll" Alias "SHDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

Dim lResult As Long

lResult = SHDeleteKey ("Key", "SubKey")

You should check for existence of the Key, you can do so by opening the Key with RegOpenKey
 
do you now have windows wait for thethe user to enter the password during shutdown?



------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Not really following but I think I have a way that will work, just not sure how to impliment it.

The password of the app is stored in a dll (encrypted) although nopt the greatest security, it is fine for the level it is used at. so when the app starts, it looks to see if snpw.dll contains an entry, if it does then the app simply starts, the password is used to exit the app and to also enter admin function, so like I said, if on startup the app sees an entry in snpw.dll, then it opens, if it does see anything in the dll (in other words the dll is empty, the app then prompts the user to choose a password. Soooooooo, if I have a boot disk that contains an empty snpw.dll, can I use a com file or something to basically replace the file on the system before windows starts?
C:\Program Files\CCL\snpw.dll is where the dll is located on the system.
Is this making any sense? I hope so.
So anyone have any thoughts?
 
Perhaps if you explain what the problem is rather than trying to explain a solution, we might be able to come up with a better solution to the problem
 
I want to create a 3.5 inch floppy that when inserted and the pc rebooted, it replaces the file C:\Program Files\CCL\snpw.dll with the snpw.dll located on the floppy
 
I dont know whether you have any option to control the loading of programs in the startup and their order of starting up. But if you are using a single program at the startup (not splitting the application that asks for the password and the one that replaces the dll.)

You can always check for the floppy drive, and use a Dir function to see whether the required file exists in the floppy. Once your check returns true, use file copy to copy the file to the destination.

But without all these hazzle, have you thought of giving the user some means by which he can recover the lost password? like asking a q and check the response etc...

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
That is a good suggestion vbSun, I did not think of that. I will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top