Exe die sich selbst löscht

Für allgemeine Fragen zur Programmierung mit PureBasic.
Benutzeravatar
NicTheQuick
Ein Admin
Beiträge: 8838
Registriert: 29.08.2004 20:20
Computerausstattung: Ryzen 7 5800X, 64 GB DDR4-3200
Ubuntu 24.04.2 LTS
GeForce RTX 3080 Ti
Wohnort: Saarbrücken

Re: Exe die sich selbst löscht

Beitrag von NicTheQuick »

Oder man nutzt einfach das Temporäre Verzeichnis um von dort ein Programm zu starten, was alles gewünschte löscht. Die Datei im Temp-Ordner kann ja einfach bestehen bleiben. Irgendwann wird der eh gelöscht.
pyromane
Beiträge: 276
Registriert: 09.09.2010 14:10

Re: Exe die sich selbst löscht

Beitrag von pyromane »

Code: Alles auswählen

ShellExecute_(0,"open","cmd.exe","/c del "+Chr(34)+ProgramFilename()+Chr(34),"c:\",#SW_HIDE)
Problem lag woanders. Code oben funktioniert. EInen schönen Tag noch!
PureBasic 5.21 LTS auf Windows 7 x64 (Intel i5 2500K, 8GB Ram, Nvidia GTX 780)
Benutzeravatar
Falko
Admin
Beiträge: 3535
Registriert: 29.08.2004 11:27
Computerausstattung: PC: MSI-Z590-GC; 32GB-DDR4, ICore9; 2TB M2 + 2x3TB-SATA2 HDD; Intel ICore9 @ 3600MHZ (Win11 Pro. 64-Bit),
Acer Aspire E15 (Win11 Home X64). Purebasic LTS 6.11b1
HP255G8 Notebook @AMD Ryzen 5 5500U with Radeon Graphics 2.10 GHz 3.4GHz, 32GB_RAM, 3TB_SSD (Win11 Pro 64-Bit)
Kontaktdaten:

Re: Exe die sich selbst löscht

Beitrag von Falko »

Ich habe mal deine abgewandelte Procedure am Anfang mit dem PB-Beispiel zusammen
ausprobiert und sehe keine aufflackernde DOS-Shell während das Programm gelöscht wird.

Wenn du dieses als Exe kompilierst und die ausführst, dürfte der es ausgeführt und nachdem es
beendet wird, ohne eine aufflackernde Shell auch gelöscht werden. Bei mir klappt dieses Beispiel soweit
ganz gut.

Code: Alles auswählen

;Diese Procedure löscht das hier gestartete Programm
Procedure SelfErase()
  RunProgram(GetEnvironmentVariable("comspec"), "/c del "+Chr(34)+ProgramFilename()+Chr(34), "", #PB_Program_Hide)
  End
EndProcedure

;
; ------------------------------------------------------------
;
;   PureBasic - Console example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;
    text$  = "Feel the Power of PureBasic!"        ; just a small text$ string
    dlay   = 4000                                  ; delay will set to 4000

;
;-------- Open our Console --------
;

    OpenConsole()                                  ; First we must open a console
    ConsoleTitle ("PureBasic - Console Example:")  ; Now we can give the opened console a Titlename ;)                                                  
    EnableGraphicalConsole(1)

;                                                                                                   
;-------- Ask and display the UserName --------
;
    
    ConsoleLocate (18,12)                          ; x y position 
    Print ("Please enter your name:   ")           ; Ask for name
    name$=Input()                                  ; Wait for user input

    ClearConsole()                                 ; This will clean the ConsoleScreen
    
    ConsoleLocate (24,10)                          ; x y position 
    PrintN ("Welcome "+name$)                      ; Print our text and the UserName
    ConsoleLocate (24,12)                          ; x y position
    PrintN (text$)                                 ; Print our text

    Delay (dlay)                                   ; Waits for moment

;
;-------- Cls and Cycle the Text-BG-Color 0 to 15 --------
;                                                  

    ClearConsole()                                 ; This will clean the ConsoleScreen
                                                   ; Info: Standard colors are (8 for text, 0 for backround)
    For i = 0 To 15
        ConsoleColor (0,i)                         ; Change BackGround text color (max 15) in every loop         
        ConsoleLocate (24,4+i)                     ; x y position 
        Print (text$)                              ; Print our text
    Next i

    Delay (dlay)                                   ; Waits for moment

;
;-------- Cls and Cycle the Text-FG-Color 0 to 15 --------
;

    ConsoleColor(0,0)                              ; Set back to black (0,0) for complete background...
    ClearConsole()                                 ; This will clean the ConsoleScreen
                                                   ; Info: Standard colors are (8 for text, 0 for backround)
    For i = 0 To 15
        ConsoleColor (i,0)                         ; Change ForGround text color (max 15) in every loop         
        ConsoleLocate (24,4+i)                     ; x y position 
        Print (text$)                              ; Print our text
    Next i

    Delay (dlay)                                   ; Waits for moment

;
;-------- Cls and Cycle the Background-Color 0 to 15 --------
;

    For a = 1 To 15
        ConsoleColor(a,a)                          ; Cycle background color...
        ClearConsole()                             ; This will clean the ConsoleScreen
        ;                                          ; Info: Standard colors are (8 for text, 0 for backround)
        For i = 0 To 15
            ConsoleColor (i,a)                     ; Change ForGround text color (max 15) in every loop         
            ConsoleLocate (24,4+i)                 ; x y position 
            Print (text$)                          ; Print our text
        Next i
        ;
        Delay(dlay/10)                             ; Waits for moment
    Next a    

    ;-------- Exit --------

    CloseConsole()

SelfErase()
Sollte das bei dir auch so sein, stimmt irgendwas anderes im Programm nicht, das quasi das löschen
der Exe kurzzeitig verhindert.

Gruß,
Falko
Bild
Win11 Pro 64-Bit, PB_6.11b1
Antworten