|
-
Aug 16th, 2000, 11:16 PM
#1
Thread Starter
Addicted Member
Okay, I've got a complicated qustion. Could anyone give/make me a code so that when you open an application, it copy's itself to C:\Windows and then starts on bootup from the registry. All this must be done when you first open it and from then after (because it was copied and runs at startup) will not copy and add itself to the registry again. Please help me, I've been trying to solve it myself but it dosen't help.
-
Aug 16th, 2000, 11:24 PM
#2
Hyperactive Member
Me thinks that sounds very much like the kind of thing a virus would do.....
Your not playing with matches are you little boy?
-
Aug 16th, 2000, 11:30 PM
#3
Thread Starter
Addicted Member
Virus!?!
I don't make viurses. This is a password protection program for my mother so her nosey admin can't get in her comp. Shes computer illeterate so I need the file to copy to the windows instead of her moving it there. A Virus?!?! Man thats low.
-
Aug 16th, 2000, 11:33 PM
#4
yeah viruses suck....
especially trojans which allow the person to get all your passwords and personal files and crap.
-
Aug 17th, 2000, 12:24 AM
#5
Heh, Dennis, don't mention trojans :).
Copying to C:\Windows:
Code:
ffile = Dir("C:\Windows" & App.EXEName & ".exe")
If ffile <> "" Then
'Copied already
Exit Sub
Else
FileCopy App.Path & "\" & App.EXEName & ".exe", "C:\Windows\" & App.EXEName & ".exe"
End If
I am not sure about checking the registry, but here's how to add your application on Startup:
Code:
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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
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
Function RegQueryStringValue(ByVal hkey As Long, ByVal strValueName As String)
Dim lResult As Long
Dim lValueType As Long
Dim strBuf As String
Dim lDataBufSize As Long
On Error GoTo 0
lResult = RegQueryValueEx(hkey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(hkey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
RegQueryStringValue = StripTerminator(strBuf)
End If
End If
End If
End Function
Public Function GetString(hkey As Long, strpath As String, strvalue As String)
Dim keyhand&
Dim datatype&
r = RegOpenKey(hkey, strpath, keyhand&)
GetString = RegQueryStringValue(keyhand&, strvalue)
r = RegCloseKey(keyhand&)
End Function
Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Integer
intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Public Sub savestring(hkey As Long, strpath As String, strvalue As String, strdata As String)
Dim keyhand&
r = RegCreateKey(hkey, strpath, keyhand&)
r = RegSetValueEx(keyhand&, strvalue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand&)
End Sub
'Into the form
Private Sub Command1_Click()
'Save a Value to the Registry
savestring HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "App", "C:\App.exe"
End Sub
[Edited by Matthew Gates on 08-17-2000 at 01:29 AM]
-
Aug 17th, 2000, 12:30 AM
#6
Thread Starter
Addicted Member
Thanx
Thank you for the code, I think I've got the registry figured out. Also, Trojans and viruses do suck, so if you want to make one, don't realese it. Viruses are the last thing I would ever make with my knowledge unless paid by the government to make it for some odd reason.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|