Write data to EXE file
#3
(05-14-2023, 05:41 PM)SMcNeill Wrote: A running EXE tends to lock itself from external changes.  You can read from it, or copy from it, but once it's running, you can't just alter it.  The only way you'd be able to do something like you're talking about would be to copy the EXE to a back-up file, write to that back-up EXE, then write a quick script for DOS to execute after you close the EXE (usually a SHELL _DONTWAIT "batch.bat" followed immediately with a SYSTEM will work just fine) which will delete the old EXE, rename the new backup EXE to the old name, and then restart with the changed EXE (if a restart is needed and you're doing the update when the program closes anyway).

Thank you for your quick response.
I was hoping that there would be another way, but that's the way it works.

Here is the revised example (Regtest2.bas)


Code: (Select All)
'====================Declarirung fr die Registrirung==========================================================================================
Declare Dynamic Library "kernel32"
FUNCTION GetVolumeInformationA& (lpRootPathName$, lpVolumeNameBuffer$, BYVAL nVolumeNameSize~&, _
    lpVolumeSerialNumber~&, lpMaximumComponentLength~&, lpFileSystemFlags~&, lpFileSystemNameBuffer$, BYVAL nFileSystemNameSize&)
End Declare

Declare Library: Function GetDriveType& (d$): End Declare
Dim Shared DriveType As String, SERIALFOUND As String
Dim As _Float Regist
Dim As _Float FileSize
'========================Ende der Registrirung=================================================================================================

MyAppName$ = Mid$(Command$(0), _InStrRev(Command$(0), "\") + 1)
'If MyAppName$ <> "Register-3.exe" Then System

'Open ".\Register-3.exe" For Input As #1
'FileSize = LOF(1)
'Close #1
'If FileSize = 592187 Then Else System






'===========================Code fr die Registrirung==========================================================================================
Test% = 0
SERIALSSHOW:
For q = 1 To 26: X = GetFileInfo(q): 'If SERIALFOUND <> "!!!-!!!" Then Print " "; Chr$(64 + q) + ":    "; SERIALFOUND
    If SERIALFOUND <> "!!!-!!!" And Test% = 0 Then
        Temp$ = SERIALFOUND
        Test% = 1
    End If

Next q
'Print Temp$


'file$ = _OpenFileDialog$("Datei Öffnen", "", "*.EXE", "Programdatei", 0)
file$ = ".\Regtest2.exe"
Open file$ For Binary As #1
FileSize = LOF(1)
t$ = "NR"
check$ = "  "
Color 3, 5
'Print FileSize

Get #1, FileSize - 1, check$
'check$ = _MK$(_Float, Regist)
'check$ = Left$(check$, 3)
'check$ = Right$(check$, 2)

'Print check1$

'Print check$
Regist = 0




Select Case UCase$(check$)
    Case "VC" 'verified copy.  All is good
        Get #1, FileSize - 10, Regist
        String1$ = _MK$(_Float, Regist)
        String1$ = Left$(String1$, 9)

        'Print String1$
        'Print Temp$
        If UCase$(String1$) = UCase$(Temp$) Then
            Print "You have a paid copy of this software.  All is good."
        Else
            Print " Illegaler Programm Aufruf !!!!!!!"
            _Delay 5
            Close #1
            System
        End If
    Case "NR" 'already has a timestamp, is a limited time test version.  Toss NAG Screen.

        Print "This is a trial version of the program."
        Registrierung$ = _InputBox$("Regtest Registrierung", "Geben sie bitte den Registrierungs Code ein:", "Demo")
        If Registrierung$ = Chr$(36) + Chr$(82) + Chr$(101) + Chr$(103) + Chr$(105) + Chr$(115) + Chr$(116) + Chr$(101) + Chr$(114) + Chr$(64) Then '$Register@

            Get #1, FileSize - 10, Regist
            String1$ = _MK$(_Float, Regist)
            Color 3, 6
            String1$ = Left$(String1$, 9)
            If UCase$(String1$) = UCase$(Temp$) Then
                Print "Programm wurde manipuliert"
            Else
                Print "Schreibe VC in Datei"
                Sleep 5
                Close #1
                Open "Regtest2.exe" For Binary As #1
                Open "Regtest3.exe" For Binary As #2
                Do Until EOF(1)
                    Get #1, , datei&
                    If Not (EOF(1)) Then Put #2, , datei&
                Loop

                Temp$ = Temp$ + "VC"
                Put #2, FileSize - 1, Temp$
                Print "Programm wurde Registriert "
                _NotifyPopup "Regtest", "Ihre Registrierung war Erfolgreich", "info" ' "info" , "warning" oder "error"
                Close #2
                _Delay .5
                'Open file$ For Binary As #1
                'FileSize = LOF(1)
                'Get #1, FileSize - 10, Regist
                'String1$ = _MK$(_Float, Regist)
                'Color 3, 6
                'String1$ = Left$(String1$, 9)
                'Print "RegTest " + String1$

                Sleep 3
                Close #1
                If _FileExists("rename.bat") Then
                    Shell _DontWait _Hide ".\rename.bat": System
                Else
                    Open "rename.bat" For Output As #3
                    Print #3, "timeout 3"
                    Print #3, "del Regtest2.exe"
                    Print #3, "ren Regtest3.exe Regtest2.exe"
                    Close #3
                End If
                Shell _DontWait _Hide ".\rename.bat": System
            End If
        Else
            Print " Ihr Code ist Falsch "
            _NotifyPopup "Regtest", "Ihre Registrierung ist Fehlgeschlagen", "warning"
        End If

    Case Else 'first run.
        Print "Illegal copy of software!  Terminating Now!"
        Print " Schreibe NR in Datei"
        Close #1
        Open "Regtest2.exe" For Binary As #1
        Open "Regtest3.exe" For Binary As #2
        Do Until EOF(1)
            Get #1, , datei&
            If Not (EOF(1)) Then Put #2, , datei&
        Loop
        Sleep 5

        'Print check$
        Put #2, FileSize + 1, t$
        'Print t$
        'Sleep
        Close #2
        If _FileExists("rename.bat") Then
            Shell _DontWait _Hide ".\rename.bat": System
        Else
            Open "rename.bat" For Output As #3
            Print #3, "timeout 3"
            Print #3, "del Regtest2.exe"
            Print #3, "ren Regtest3.exe Regtest2.exe"
            Close #3
        End If
        Shell _DontWait _Hide ".\rename.bat": System
        End
End Select
Close #1

'=======================================Code ende Registrirung ====================================================================


'==================================Funtionen fr die Registrirung =================================================
Function GetFileInfo (D)
    SERIALFOUND = "!!!-!!!":
    If DRIVEEXISTS(D) <> 1 Then GetFileInfo = 0: Exit Function
    Dname$ = Chr$(D + 64) + ":\": Sname$ = Space$(260)
    R = GetVolumeInformationA(Dname$ + Chr$(0), Vname$, 260, serial~&, empty1~&, empty2~&, Sname$, 260)
    If R = 0 Then Exit Function
    Sname$ = Left$(Hex$(serial~&), 4) + "-" + Right$(Hex$(serial~&), 4)
    SERIALFOUND = "" + Sname$ + ""
    GetFileInfo = -1
End Function
'---
Function DRIVEEXISTS (V)
    DRIVEEXISTS = 0: varX$ = Chr$(V + 64) + ":\" + Chr$(0): VarX = GetDriveType(varX$): If VarX > 1 Then DRIVEEXISTS = 1
End Function
'===========================================Ende der Registrirung==========================
Reply


Messages In This Thread
Write data to EXE file - by Steffan-68 - 05-14-2023, 05:18 PM
RE: Write data to EXE file - by SMcNeill - 05-14-2023, 05:41 PM
RE: Write data to EXE file - by Steffan-68 - 05-14-2023, 08:37 PM
RE: Write data to EXE file - by mnrvovrfc - 05-14-2023, 10:31 PM
RE: Write data to EXE file - by Steffan-68 - 05-15-2023, 09:58 AM
RE: Write data to EXE file - by euklides - 05-15-2023, 03:00 PM
RE: Write data to EXE file - by Steffan-68 - 05-15-2023, 04:23 PM
RE: Write data to EXE file - by Kernelpanic - 05-15-2023, 05:21 PM
RE: Write data to EXE file - by Steffan-68 - 05-15-2023, 06:41 PM



Users browsing this thread: 7 Guest(s)