Jump to content

PureAutoIt machine code compiler small executable


ghost911
 Share

Recommended Posts

EnableExplicit

Global Procedure_Error = 0
Global Procedure_Extended = 0

Procedure.s DriveGetType(Drive$)
    Procedure_Error = 0
    Procedure_Extended = 0
    Select GetDriveType_(Drive$)
        Case #DRIVE_UNKNOWN
            ProcedureReturn "UNKNOWN"
        Case #DRIVE_REMOVABLE
            ProcedureReturn "REMOVABLE"
        Case #DRIVE_FIXED
            ProcedureReturn "FIXED"
        Case #DRIVE_REMOTE
            ProcedureReturn "REMOTE"
        Case #DRIVE_CDROM
            ProcedureReturn "CDROM"
        Case #DRIVE_RAMDISK
            ProcedureReturn "RAMDISK"
        Default
            Procedure_Error = 1
            ProcedureReturn ""
    EndSelect
EndProcedure

MessageRequester("Disc type", DriveGetType("C:\"))


Procedure.s DriveGetLabel(Drive$)
    Protected Label$
    Label$=Space(#MAX_PATH+1)
    If Not GetVolumeInformation_(Drive$,Label$,#MAX_PATH+1,0,0,0,0,0)
        Procedure_Error = 1
        ProcedureReturn ""
    EndIf
    ProcedureReturn Label$
EndProcedure

MessageRequester("Disk label", DriveGetLabel("C:\"))

Procedure.s DriveGetSerial(Drive$)
    Protected Serial.l
    If Not GetVolumeInformation_(Drive$,0,0,@Serial,0,0,0,0)
        Procedure_Error = 1
        ProcedureReturn ""
    EndIf
    ProcedureReturn Str(Serial & $FFFFFFFF)
EndProcedure

MessageRequester("Disk Serial", DriveGetSerial("C:\"))

Procedure.s DriveSpaceFree(Drive$)
    Protected.q free_bytes
    If GetDiskFreeSpaceEx_(Drive$, 0, 0, @free_bytes)
;       ProcedureReturn Str(free_bytes) ; Bytes
;       ProcedureReturn Str(free_bytes/1024.0) ; Kb
        ProcedureReturn StrF(free_bytes/1048576.0, 4) ; Mb
;       ProcedureReturn StrF(free_bytes/1073741824.0, 3) ; Gb
    Else
        Procedure_Error = 1
        ProcedureReturn "0"
    EndIf
EndProcedure

MessageRequester("Free on drive", DriveSpaceFree("C:\"))


Procedure.s DriveSpaceTotal(Drive$)
    Protected.q total_bytes
    If GetDiskFreeSpaceEx_(Drive$, 0, @total_bytes, 0)
;       ProcedureReturn Str(total_bytes) ; Bytes
;       ProcedureReturn Str(total_bytes/1024.0) ; Kb
        ProcedureReturn StrF(total_bytes/1048576.0, 4) ; Mb
;       ProcedureReturn StrF(total_bytes/1073741824.0, 3) ; Gb
    Else
        Procedure_Error = 1
        ProcedureReturn "0"
    EndIf
EndProcedure

MessageRequester("Disk size", DriveSpaceTotal("C:\"))


Procedure.s DriveGetFileSystem(Drive$)
    Protected FileSystem$
    FileSystem$=Space(#MAX_PATH+1)
    If GetVolumeInformation_(Drive$,0,0,0,0,0,@FileSystem$,#MAX_PATH+1)
        ProcedureReturn FileSystem$
    Else
        Procedure_Error = 1
        ProcedureReturn "1"
    EndIf
EndProcedure

MessageRequester("File system type", DriveGetFileSystem("C:\"))
EnableExplicit

Procedure.s GetLogicalDrives(Type, List Drives.s())
    Protected i, Drive$, drives_avail = GetLogicalDrives_() ; Returns the bit flags of existing disks
    For i = 0 To 25
        If ((drives_avail >> i) & 1) ; If the disc exists
             Drive$ = Chr(i + 65)+":\"
            If #True = Type Or GetDriveType_(Drive$) = Type
                AddElement(Drives())
                Drives() = Drive$
            EndIf
        EndIf
    Next
EndProcedure


Procedure.s DriveGetDrive(Type$, List Drives.s())
    Select Type$
        Case "UNKNOWN"
            GetLogicalDrives(#DRIVE_UNKNOWN, Drives())
        Case "REMOVABLE"
            GetLogicalDrives(#DRIVE_REMOVABLE, Drives())
        Case "FIXED"
            GetLogicalDrives(#DRIVE_FIXED, Drives())
        Case "REMOTE"
            GetLogicalDrives(#DRIVE_REMOTE, Drives())
        Case "CDROM"
            GetLogicalDrives(#DRIVE_CDROM, Drives())
        Case "RAMDISK"
            GetLogicalDrives(#DRIVE_RAMDISK, Drives())
        Case "ALL"
            GetLogicalDrives(#True, Drives())
        Default
            ProcedureReturn ""
    EndSelect
EndProcedure


NewList Drives.s()
DriveGetDrive("ALL", Drives())
Define List1.s
ForEach Drives()
    List1 + Drives() + #CRLF$
Next

MessageRequester("List", List1)

 

Edited by AZJIO
Link to comment
Share on other sites

EnableExplicit

Define ini$
ini$ = GetPathPart(ProgramFilename()) + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension) + ".ini"

Procedure.s IniRead(filename$, section$, key$, def$ = "")
    Protected res$
    If OpenPreferences(filename$)
        If PreferenceGroup(section$)
            res$ = ReadPreferenceString(key$, def$)
        EndIf
        ClosePreferences()
    EndIf
    ProcedureReturn res$
EndProcedure

Procedure IniWrite(filename$, section$, key$, value$)
    Protected res
    If FileSize(filename$) < 0
;       CreateFile(0, filename$)
;       WriteString(0, #CRLF$)
;       CloseFile(0)
        CreatePreferences(filename$)
        ClosePreferences()
    EndIf
    If OpenPreferences(filename$)
        PreferenceGroup(section$)
        res = WritePreferenceString(key$, value$)
        ClosePreferences()
    EndIf
    ProcedureReturn res
EndProcedure

Procedure IniDelete(filename$, section$, key$ = "")
    If OpenPreferences(filename$)
        If key$ = ""
            RemovePreferenceGroup(section$)
        Else
            If PreferenceGroup(section$)
                RemovePreferenceKey(key$)
            EndIf
        EndIf
        ClosePreferences()
    EndIf
EndProcedure

IniWrite(ini$, "Set", "KeyWin", "new_value")
MessageRequester("Here it is", IniRead(ini$, "Set", "KeyWin", "Default value"))
IniDelete(ini$, "Set", "KeyWin")
IniDelete(ini$, "Set")


; EnableExplicit

; Define ini$
; ini$ = GetPathPart(ProgramFilename()) + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension) + ".ini"
; Make the ini-file was not empty

Procedure IniReadSectionNames(filename$, List Groups.s())
    If OpenPreferences(filename$)
        ExaminePreferenceGroups()
        While NextPreferenceGroup()
            AddElement(Groups())
            Groups() = PreferenceGroupName()
        Wend
        ClosePreferences()
    EndIf
EndProcedure

NewList Groups.s()
IniReadSectionNames(ini$, Groups())
Define List1.s
ForEach Groups()
    List1 + Groups() + #CRLF$
Next
MessageRequester("List", List1)


Procedure IniReadSection(filename$, section$, Map key_value.s())
    If OpenPreferences(filename$)
        If PreferenceGroup(section$)
            ExaminePreferenceKeys()
            While  NextPreferenceKey()
                AddMapElement(key_value(), PreferenceKeyName())
                key_value() = PreferenceKeyValue()
                ; key_value(PreferenceKeyName()) = PreferenceKeyValue()
            Wend
        EndIf
        ClosePreferences()
    EndIf
EndProcedure

NewMap key_value.s()
IniReadSection(ini$, "Set", key_value())
Define Map1.s
ForEach key_value()
    Map1 + MapKey(key_value()) + " = " + key_value() + #CRLF$
Next
MessageRequester("Map", Map1)

 

Edited by AZJIO
Link to comment
Share on other sites

Macro BlockInput(bool)
    BlockInput_(bool)
EndMacro

BlockInput(1)
Delay(3000)
BlockInput(0)

I fixed two functions. There it is not possible to get the size of the field to return data.

Procedure.s DriveGetLabel(Drive$)
    Protected Label$
    Label$=Space(#MAX_PATH+1)
    If Not GetVolumeInformation_(Drive$,Label$,#MAX_PATH+1,0,0,0,0,0)
        Procedure_Error = 1
        ProcedureReturn ""
    EndIf
    ProcedureReturn Label$
EndProcedure

MessageRequester("Disk label", DriveGetLabel("C:\"))

Procedure.s DriveGetFileSystem(Drive$)
    Protected FileSystem$
    FileSystem$=Space(#MAX_PATH+1)
    If GetVolumeInformation_(Drive$,0,0,0,0,0,@FileSystem$,#MAX_PATH+1)
        ProcedureReturn FileSystem$
    Else
        Procedure_Error = 1
        ProcedureReturn "1"
    EndIf
EndProcedure

MessageRequester("File system type", DriveGetFileSystem("C:\"))

 

Edited by AZJIO
Link to comment
Share on other sites

#TH32CS_SNAPPROCESS = $2 
#MAX_PATH = 999 
Structure PROCESSENTRY32 
     dwSize.d 
     cntUsage.d 
     th32ProcessID.d 
     th32DefaultHeapID.l 
     th32ModuleID.d 
     cntThreads.d 
     th32ParentProcessID.d
     pcPriClassBase.l 
     dwFlags.d 
    szExeFile.b [#MAX_PATH]
 EndStructure 
Structure ProcInfo
  Name.s
  PID.l
EndStructure
Procedure ProcessList(List ProcList.ProcInfo())
  Protected pe32.PROCESSENTRY32
  Protected hthSnapshot
  
  pe32\dwSize = SizeOf(PROCESSENTRY32)
  ClearList(ProcList())
  
  hthSnapshot = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
  If hthSnapshot
    Process32First_(hthSnapshot, @pe32) 
    While Process32Next_(hthSnapshot, @pe32) 
      If AddElement(ProcList())
        ProcList()\Name = LCase(PeekS(@pe32\szExeFile))
        ProcList()\PID  = pe32\th32ProcessID
      EndIf
    Wend 
    CloseHandle_(hthSnapshot)
  EndIf
EndProcedure
NewList ProcList.ProcInfo()
ProcessList(ProcList())
ForEach ProcList()
  Debug ProcList()\Name + "  "+ProcList()\PID
Next

 

 

I do not understand it does not work to get processes via APIs

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...