PureBasic -

, ! .


» PureBasic - »  PureBasic »  ( ).


( ).

1 30 32

1

- ((
, . "C:\Program Files (x86)\PSE" , "PSE"
, 004.exe
, PSE. ,   - MessageRequester("","!") ?
, ,

:
ShellExecute_(0, "RunAS", GetEnvironmentVariable("comspec"), "/c del "+Chr(34)+ProgramFilename()+Chr(34), "", #SW_SHOWNORMAL)

, . , . . , , - .
- ?

Goga (11.09.2021 13:12:37)

0

2

?
DeleteDirectory?

AZJIO (11.09.2021 13:37:25)

0

3

. DeleteDirectory , .

0

4

, . , , .

GetModuleFileNameEx

:
EnableExplicit
     	
;    EXE-        PID
Procedure.s ProcessNameFromHwnd(hWnd)
	Protected PID, psapi_dll, Path$, GetModuleFileNameEx, hProcess
	psapi_dll = OpenLibrary(#PB_Any, "psapi.dll")
	If psapi_dll
    GetModuleFileNameEx = GetFunction(psapi_dll, "GetModuleFileNameExW") ;     !
    If GetModuleFileNameEx
    	If GetWindowThreadProcessId_(hWnd, @PID)
        hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, #Null, PID)
        If hProcess
        	Path$ = Space(#MAX_PATH)
        	If Not CallFunctionFast(GetModuleFileNameEx, hProcess, #Null, @Path$, #MAX_PATH)
            Path$ = ""
        	EndIf
        	CloseHandle_(hProcess)
        EndIf
    	EndIf
    EndIf
    CloseLibrary(psapi_dll)
	EndIf
	ProcedureReturn Path$
EndProcedure

Define hWnd, Path$

hWnd=FindWindow_(0, " ")
If hWnd
	Path$=ProcessNameFromHwnd(hWnd)
	Debug Path$
EndIf

- . , , .

Linux, .

AZJIO (06.10.2021 15:56:57)

0

5

,

0

6

newJS ():

,

, , . , exe-, , . exe- ,   c cmd.exe
... . , .exe .

Goga (18.09.2021 05:00:42)

0

7

Goga
( ), cmd taskkill ?

0

8

Goga
- ?

0

9

Smitis ():

Goga
( ), cmd taskkill ?

, . , ,   wscript.exe. , . D- , , . " ". - " ", , , " " . . , , .

0

10

Goga
C: , . : %temp%?

0

11

, . -,  - - . , , . .. . (, c:\Program Files (x86)) . .. Vbscript, , , :

:
;      !!!!!!!!!   !!!!!!!!!!!!!!!!!!
NameProga$=ProgramFilename() 
  DirToDelete.s = GetPathPart(NameProga$)  
  DirToDelete = LCase(Left(DirToDelete, Len(DirToDelete)-1))  
  TempDir.s = GetTemporaryDirectory() 
  ScriptName.s = TempDir + "3.vbs"  
  
  If CreateFile(0, ScriptName)
       WriteData(0,?vbs_begin, ?vbs_end-?vbs_begin)
  CloseFile(0) 
       parametr$="//nologo"+" "+ScriptName+" "+DirToDelete
       Result =MessageRequester("","      ?", #PB_MessageRequester_YesNo):If Result = #PB_MessageRequester_No:End:EndIf ; 
       ShellExecute_(0, "RunAS", "wscript.exe", parametr$, TempDir, #SW_SHOWNORMAL) 
  EndIf
  
     
  VBS_BEGIN:
     IncludeBinary "3.vbs"
  VBS_END:

, , 3.vbs

:
If Wscript.Arguments.Count=1 Then
  Dim x
  Wscript.Sleep 1000
  Path = Wscript.Arguments(0)
  Set objShell = CreateObject("Wscript.Shell")
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists(Path) Then
    'CurrentPath = objFSO.GetAbsolutePathName(".")
    'msgbox CurrentPath
    On Error Resume Next
    For x = 1 To 10
      objFSO.DeleteFolder(Path)
      If Err.Number = 0 Then Exit For
      Wscript.Sleep 1000
    Next
  End If
  Call objFSO.DeleteFile(WScript.ScriptFullName, True)
End If

0

12

:
DirToDelete = #DOUBLEQUOTE$ + LCase(Left(DirToDelete, Len(DirToDelete)-1)) + #DOUBLEQUOTE$

Lin (06.10.2021 09:49:27)

0

13

, :

:
;     !   ,        !
Select MessageRequester("! ", "    ?", #MB_YESNO|#MB_ICONWARNING)
  Case #IDYES
    PathPart$ = GetPathPart(ProgramFilename())
    If CreateFile(0, "del.bat")
       WriteStringN(0,"@echo off") 
       WriteStringN(0,"CD\.")
       WriteStringN(0,"timeout /t 2 /nobreak >nul 2>nul")
       WriteStringN(0,"rd /s /q " + Chr(34) + PathPart$  + Chr(34) )
      CloseFile(0)
    RunProgram("del.bat")
    End
    EndIf
  Case #IDNO
    MessageRequester("! ", " ")
EndSelect

0

14

temp.

:
cd /d "%temp%" && rd /s /q "."

, %temp% , , , . .

0

15

():

Chr(34)

#DOUBLEQUOTE$

Lin (06.10.2021 09:52:57)

0

16

Lin ():

#DOUBLEQUOTE$

. .

:
~"\""

0

17

ϸ
, , , , . Chr(34) .

AZJIO (06.10.2021 12:28:29)

0

18

Lin ():

#DOUBLEQUOTE$

Chr(34) 30 . "/" "\" . .

0

19

"/" "\"

#PS$ , , - . images Data images + #PS$ + pic1.png, , , , . CompilerSelect #PB_Compiler_OS

- EXE- \.

AZJIO (06.10.2021 16:00:21)

0

20

AZJIO ():

CompilerSelect #PB_Compiler_OS

, , , "images/pic1.png", , images + #PS$ + pic1.png

0

21

AZJIO ():

GetModuleFileNameEx = GetFunction(psapi_dll, "GetModuleFileNameExW") ;

:

:
EXE_Location$ = Space(#MAX_PATH)
GetModuleFileName_(#Null, EXE_Location$, #MAX_PATH)
Debug EXE_Location$
ϸ ():

.

, :) ... IDE : #Q$ = Chr(34)

Lin (06.10.2021 17:56:39)

0

22

Lin ():

:

ProgramFilename()

, AutoIt3 , , , , , , AutoIt3- PID , PID  hWnd, PureBasic hWnd, , , , , , , .

0

23

Lin ():

:

DirToDelete = #DOUBLEQUOTE$ + LCase(Left(DirToDelete, Len(DirToDelete)-1)) + #DOUBLEQUOTE$

():

, :
:

; ! , !
Select MessageRequester("! ", " ?", #MB_YESNO|#MB_ICONWARNING)
  Case #IDYES
    PathPart$ = GetPathPart(ProgramFilename())
    If CreateFile(0, "del.bat")
       WriteStringN(0,"@echo off")
       WriteStringN(0,"CD\.")
       WriteStringN(0,"timeout /t 2 /nobreak >nul 2>nul")
       WriteStringN(0,"rd /s /q " + Chr(34) + PathPart$  + Chr(34) )
      CloseFile(0)
    RunProgram("del.bat")
    End
    EndIf
  Case #IDNO
    MessageRequester("! ", " ")
EndSelect

. , , . , , )

0

24

- , UTF (-64) , 866 . 866 ?

0

25

Rerer777 ():

866 ?

https://www.purebasic.com/documentation … efile.html
https://www.purebasic.com/documentation … ormat.html

0

26

Rerer777 ():

- , UTF (-64)

BOM.
chcp 65001.

0

27

866

:
EnableExplicit

Procedure StrToArrLetter(Array Arr.s{1}(1), String$)
	Protected LenStr, i
	LenStr = Len(String$)
	If LenStr
    ReDim Arr(LenStr - 1)
    PokeS(Arr(), String$, -1, #PB_String_NoZero)
	EndIf
	ProcedureReturn
EndProcedure

Procedure.s Encode1251To866(sString$)
	Protected sResult$ = "", i, code
	Protected cp1251$, cp866$, Pos
	Protected Dim Arr866.s{1}(0)
	Protected Dim ArrSource.s{1}(0)
	
	cp1251$ = "Ũ"
	cp866$ = "񦧨"
	StrToArrLetter(Arr866(), cp866$)
	StrToArrLetter(ArrSource(), sString$)
	
	For i = 0 To ArraySize(ArrSource())
    code = Asc(ArrSource(i))
    If code >= 1025 And code <= 1105
    	Pos = FindString(cp1251$, ArrSource(i))
    	If Pos
        ArrSource(i) = Arr866(Pos - 1) 
    	EndIf
    EndIf
	Next
	
	ProcedureReturn PeekS(ArrSource())
EndProcedure

Procedure.s Encode866To1251(sString$)
	Protected sResult$ = "", i, code
	Protected cp1251$, cp866$, Pos
	Protected Dim Arr866.s{1}(0)
	Protected Dim ArrSource.s{1}(0)
	
	cp866$ = "Ũ"
	cp1251$ = "񦧨"
	StrToArrLetter(Arr866(), cp866$)
	StrToArrLetter(ArrSource(), sString$)
	
	For i = 0 To ArraySize(ArrSource())
    code = Asc(ArrSource(i))
    If code >= 152 And code <= 8482
    	Pos = FindString(cp1251$, ArrSource(i))
    	If Pos
        ArrSource(i) = Arr866(Pos - 1) 
    	EndIf
    EndIf
	Next
	
	ProcedureReturn PeekS(ArrSource())
EndProcedure

Define Str1.s, Str2.s

Str1 = Encode1251To866("")
Str2 = Encode1251To866("----")
Debug Str1
Debug Str2
Str1 = Encode866To1251(Str1)
Str2 = Encode866To1251(Str2)
Debug Str1
Debug Str2

AutoIt3, ANSI, , , . , Asc() . .

:
Procedure.s _Encoding_1251To866(sString$)
	Protected sResult$ = "", iCode, i
	Protected Dim Arr866.s{1}(0)
	
	StrToArrLetter(Arr866(), sString$)

	For i = 0 To ArraySize(Arr866())
    iCode = Asc(Arr866(i))

    Select iCode
    	Case 192 To 239
        Arr866(i) = Chr(iCode - 64)
    	Case 240 To 255
        Arr866(i) = Chr(iCode - 16)
    	Case 168
        Arr866(i) = Chr(240)
    	Case 184
        Arr866(i) = Chr(241)
    	Case 185
        Arr866(i) = Chr(252)
    EndSelect

    sResult$ + Arr866(i)
	Next

	ProcedureReturn sResult$
EndProcedure

: , .

:
Procedure.s Encode1251To866(sString$)
	Protected sResult$ = "", i, code
	Protected cp1251$, cp866$
	Protected Dim Arr866.s{1}(0)
	Protected Dim ArrSource.s{1}(0)
	
	cp1251$ = ""
	cp866$ = ""
	StrToArrLetter(Arr866(), cp866$)
	StrToArrLetter(ArrSource(), sString$)
	
	For i = 0 To ArraySize(ArrSource())
    code = Asc(ArrSource(i))
    Select code
    	Case 1040 To 1103
        ArrSource(i) = Arr866(code - 1040) 
    	Case 1025
        ArrSource(i) = ""
    	Case 1105
        ArrSource(i) = ""
    EndSelect
	Next
	
	ProcedureReturn PeekS(ArrSource())
EndProcedure

ChkDskGui

:
Import "user32.lib"
	OemToCharBuffA(*Buff,*Buff1,SizeBuff)
	CharToOemBuffA(*Buff,*Buff1,SizeBuff)
EndImport

Procedure.s ToOem(String$)
	Protected Ret$="", *Buff, SizeBuff=Len(String$)
	If SizeBuff>0
    *Buff=AllocateMemory(SizeBuff+1)
    PokeS(*Buff, String$, SizeBuff, #PB_Ascii)
    CharToOemBuffA(*Buff, *Buff, SizeBuff)
    Ret$=PeekS(*Buff, SizeBuff, #PB_Ascii)
    FreeMemory(*Buff)
	EndIf
	ProcedureReturn Ret$
EndProcedure

AZJIO (10.10.2021 08:07:58)

0

28

. , , chcp . . 32 , , .

, . - , ?

0

29

Rerer777 ():

chcp

chcp . PATH/PATHEXT . . .
? cmd ?

Smitis (11.10.2021 22:33:12)

0

30

Rerer777
CreateFile #PB_Ascii CHCP 1251

" ", . bat- - , . ExamineEnvironmentVariables(), .

AZJIO (11.10.2021 18:31:17)

0


» PureBasic - »  PureBasic »  ( ).