It is currently Mon Mar 01, 2021 1:44 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Fri Sep 30, 2016 11:01 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Oct 14, 2014 12:09 pm
Posts: 356
loulou2522 wrote:
Thanks WARD for this great code

When did you post a new release ?


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Tue Dec 27, 2016 2:08 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Oct 14, 2014 12:09 pm
Posts: 356
HI Ward,
No more news ?


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Sat Feb 18, 2017 8:13 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Oct 14, 2014 12:09 pm
Posts: 356
No more news ?


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Thu Sep 21, 2017 4:51 am 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 963
Location: UA
Recently I've used it, just few small changes needed to work fine with newer PB versions.
Really useful stuff, sometimes very cool instead of writing those many routines from scratch

_________________
..


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Mon Sep 25, 2017 8:11 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Oct 14, 2014 12:09 pm
Posts: 356
Hi lunasole,
Can you share your modification ? THanks a lot


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Mon Sep 25, 2017 7:22 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 963
Location: UA
loulou2522 wrote:
Hi lunasole,
Can you share your modification ? THanks a lot


Hi. All you need is to remove structure declaration at line 4417 (Structure PROCESS_MEMORY_COUNTERS) and remove 3 constants of enumeration at line 84 (Enumeration ; for FileSetPos)
File: PureAutoIt.pbi

_________________
..


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Mon Sep 25, 2017 7:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Oct 14, 2014 12:09 pm
Posts: 356
Thanks lunasole


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Thu Dec 03, 2020 3:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Jul 14, 2006 8:53 pm
Posts: 707
Location: Malta
this is a really great job
It doesn't work on 64bit for me....but the 32bit version seems to work fine

_________________
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Fri Dec 04, 2020 5:41 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 339
Location: NL
Another one is available at the autoit side, but they seem quite different..

https://www.autoitscript.com/forum/topi ... /#comments
https://www.autoitscript.com/forum/appl ... p?id=64240

Main source for archive
Code:
;IncludeFile "FonctionsIncludes\StringIs.PB" ;I separated the functions into several activated files If necessary remove
;IncludeFile "FonctionsIncludes\InetFonctions.PB" ; I separated the functions into several activated files If necessary remove

#File = 0


;Macro     ###########################

Procedure.s ComSpec () ; not work in macro
  ProcedureReturn GetEnvironmentVariable("COMSPEC")
EndProcedure

Macro ScriptDir ()
GetCurrentDirectory()
EndMacro

Macro AutoItVersion ()
    "3.3.14.5"
EndMacro

Macro aScriptDir ()
    StringTrimRight(GetPathPart(ProgramFilename()), 1)
EndMacro

Macro ScriptName ()
    GetFilePart(ProgramFilename())
EndMacro

Macro ScriptFullPath ()
    ProgramFilename()
EndMacro

Macro DesktopCommonDir ()
    GetUserDirectory(#PB_Directory_Desktop)
EndMacro

Macro MyDocumentsDir ()
    GetUserDirectory(#PB_Directory_Documents)
EndMacro

Macro ProgramFilesDir ()
    GetUserDirectory(#PB_Directory_Programs)
EndMacro

Macro TempDir ()
    GetTemporaryDirectory()
EndMacro
 
Macro SystemDir ()
   GetEnvironmentVariable("SystemRoot") + "\System32\"
EndMacro   
 
Macro UserProfileDir ()
   GetEnvironmentVariable("UserProfile") + "\"
EndMacro
 
Macro AppDataDir ()
   GetEnvironmentVariable("AppData") + "\"
EndMacro
 
Macro LogonServer ()
   GetEnvironmentVariable("LOGONSERVER")
 EndMacro
 
Macro HomeShare ()
 GetEnvironmentVariable("HOMESHARE")
EndMacro

Macro HomePath ()
 GetEnvironmentVariable("HOMEPATH")
EndMacro

Macro HomeDrive ()
 GetEnvironmentVariable("HOMEDRIVE")
EndMacro

 Macro UserName ()
   GetEnvironmentVariable("USERNAME")
 EndMacro
 
Macro LocalAppDataDir ()
   GetEnvironmentVariable("LOCALAPPDATA") + "\"
EndMacro
 
Macro ProcessorsThreadNumber ()
  GetEnvironmentVariable("NUMBER_OF_PROCESSORS")
EndMacro 
 
Macro Hours ()
    FormatDate("%hh", Date())
EndMacro

Macro Sec ()
    FormatDate("%ss", Date())
EndMacro

Macro Min ()
    FormatDate("%ii", Date())
EndMacro

Macro MDAY ()
    FormatDate("%dd", Date())
EndMacro

Macro MON ()
    FormatDate("%mm", Date())
EndMacro

Macro Years ()
    FormatDate("%yyyy", Date())
  EndMacro
 
Macro UserName ()
    ComputerName()
EndMacro 
 
Macro UserProfilDir ()
 GetEnvironmentVariable("USERPROFILE") + "\"
EndMacro   

Macro CRLF ()
    #CRLF$
EndMacro

Macro CR ()
    #CR$
EndMacro

Macro LF ()
    #LF$
  EndMacro
 
Macro BlockInput(bool)
    BlockInput_(bool)
EndMacro
 
Macro GetCPUName()
    CPUName()
  EndMacro
 
Macro Sqrt (Number)
    Sqr(Number)
EndMacro
 
 
Procedure DesktopHeights ()
ExamineDesktops()
ProcedureReturn DesktopHeight(0)
EndProcedure
 
Procedure DesktopWidths ()
ExamineDesktops()
ProcedureReturn DesktopWidth(0)
EndProcedure

Procedure DesktopRefresh ()
ExamineDesktops()
ProcedureReturn DesktopFrequency(0)
EndProcedure

Procedure DesktopDepths ()
ExamineDesktops()
ProcedureReturn DesktopDepth(0)
EndProcedure

Macro BlockInput(bool)
    BlockInput_(bool)
EndMacro
 
Procedure  AutoItX64 ()
CompilerSelect #PB_Compiler_Processor
CompilerCase #PB_Processor_x86
      ProcedureReturn 0
CompilerCase #PB_Processor_x64
      ProcedureReturn 1
CompilerEndSelect   
EndProcedure
   

Procedure.s ProcessorArch ()
Command=RunProgram("cmd.exe","/c wmic cpu get architecture","",#PB_Program_Hide | #PB_Program_Open | #PB_Program_Read | #PB_Program_Ascii )
count=0
Arch$=""
If command
While ProgramRunning(command)
  If AvailableProgramOutput(command)
    count=count+1
    ReadCommand$= ReadProgramString(command)
    If Count = 2
      DebugPatch.s=ReplaceString(ReadCommand$," ","")
      If DebugPatch  = "0"
       Arch$ = "x86"
      ElseIf DebugPatch  = "6"
       Arch$ = "IA64"
      ElseIf DebugPatch = "9"
      Arch$ = "x64"
      Else
      Arch$ = "Unknown"
    EndIf
    EndIf
  EndIf
Wend
EndIf
CloseProgram(command)
ProcedureReturn Arch$
EndProcedure
 
 
;MacroEnd  ###########################
 
 ;Fonction   ###########################
Procedure IsNumeric(text.s)
  text.s = Trim(UCase(text))
  If FindString(text, ".", 0)
  t.s = StrF(ValF(text.s))
  If t = Left(LSet(text.s, Len(t), "0"), Len(t))
  ProcedureReturn 1
  EndIf
  Else
  t.s = Str(Val(text.s))
  If t = text
  ProcedureReturn 1
  EndIf
  EndIf
EndProcedure

Macro IsNumber (Number)
  IsNumeric(Str(Number))
EndMacro

;######################################################### MSGBOX #################################################################################

Procedure MsgBox (flag,Title.s,Text.s)
#MB_OKCANCEL=$00000001
#MB_ABORTRETRYIGNORE=$00000002
#MB_YESNOCANCEL=$00000003
#MB_YESNO=$00000004
#MB_RETRYCANCEL=$00000005
#MB_CANCELTRYCONTINUE=$00000006
#MB_HELP = $00004000
#MB_ICONERROR=$00000010
#MB_ICONQUESTION=$00000020
#MB_ICONWARNING=$00000030
#MB_ICONINFORMATION=$00000040
#MB_DEFBUTTON2=$00000100
#MB_DEFBUTTON3=$00000200
#MB_DEFBUTTON4=$00000300
#MB_SYSTEMMODAL=$0001000
#MB_TASKMODAL=$00002000
#MB_DEFAULT_DESKTOP_ONLY=$000020000
#MB_RIGHT=$00080000
#MB_RTLREADING=$00100000
#MB_SETFOREGROUND=$00010000
#MB_TOPMOST=$00040000
#MB_SERVICE_NOTIFICATION=$000200000
ProcedureReturn MessageBox_(0,Text,Title,flag)
EndProcedure



;######################################################### MSGBOX #################################################################################


Macro Floor(x)
  Round(x, #PB_Round_Down)
EndMacro

Macro Ceiling(x)
  Round(x, #PB_Round_Up)
EndMacro

Macro Randoms (Minimum,Maximum)
    Str (Random(Maximum,Minimum))
EndMacro

Procedure.s FileGetSize(NomFichier.s) ; Update Function
Directory$ = GetCurrentDirectory()
FileName$ = NomFichier           
If ExamineDirectory(0, Directory$, FileName$) 
    While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_File
        Size$ = Str(DirectoryEntrySize(0))       
      EndIf
    Wend
    FinishDirectory(0)
  EndIf
  ProcedureReturn Size$
EndProcedure

Macro StringLen (String)
    Len(String)
EndMacro

Macro StringLenS (String)
    Str (Len(String))
EndMacro

Macro ClipPut (String)
    SetClipboardText(String)
EndMacro

Macro ClipGet ()
    GetClipboardText()
EndMacro

Procedure Sleep (Time)
  Delay (Time)
EndProcedure

Macro DirCopy (Source,Dest)
    CopyDirectory(Source,Dest,"", #PB_FileSystem_Recursive)
EndMacro

Macro DirCreate (Source)
    CreateDirectory(Source)
EndMacro

Macro DirRemove (Source)
    DeleteDirectory(Source,"",#PB_FileSystem_Recursive)
EndMacro

Macro StringReplace (String,SearchString,Replace,Occurrence=0,Casesense=0)
    ReplaceString(String,SearchString,Replace,Casesense,Occurrence)
EndMacro

Macro StringRight (String,Count)
    Right (String,Count)
EndMacro

Macro StringLeft (String,Count)
    Left (String,Count)
EndMacro

Macro FileCopy (Source,Dest)
  CopyFile(Source,Dest)
EndMacro

Macro FileMove (Source,Dest)
  CopyFile(Source,Dest)
  DeleteFile(Source)
EndMacro

Procedure FileExists (Source.s)
 If FileSize(Source) = -1
   ProcedureReturn 0
 Else
   ProcedureReturn 1
 EndIf
EndProcedure

Procedure FileDelete (Source.s)
 If FileSize(Source) = -2
    DeleteFile(Source)
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

Macro StringUpper (String)
    UCase (String)
EndMacro

Macro StringLower (String)
    LCase (String)
EndMacro

Macro StringTrimLeft (String,n)
    Mid(String, n+1)
EndMacro

Macro StringTrimRight(String, n)
    Left(String, Len(String) - n)
EndMacro
 
#STIF_DEFAULT = 0
#STIF_SUPPORT_HEX = 1

Procedure.s StringToBinary(str$)
  For x = 1 To Len(str$)
    hexchar$ = Hex(Asc(Mid(str$, x, 1)))
    If Len(hexchar$) = 1
      hexchar$ = "0" + hexchar$
    EndIf
    StringToHex$ + hexchar$
  Next x
  ProcedureReturn "0x"+StringToHex$
EndProcedure
 
Procedure.s BinaryToString(hex$)
  For x = 1 To Len(hex$) Step 2
    HexByte$ = "0x" + Mid(hex$, x, 2)
   StrToIntEx_ (HexByte$, #STIF_SUPPORT_HEX, @ascValue)
    HexToString$ + Chr(ascValue)
  Next x
  ProcedureReturn HexToString$
EndProcedure

Macro StringReverse(String)
    ReverseString(String)
EndMacro

Macro String(String)
    Str(String)
EndMacro
 
Macro TimerInit()
    Str (ElapsedMilliseconds())
EndMacro

Macro TimerDiff(StartTime)
    Str ((ElapsedMilliseconds() - Val(StartTime)))
EndMacro
 
Procedure.s FileGetTime (NomFichier.s,flag,DateFormat.s="%mm/%dd/%yyyy %hh:%ii:%ss")
Directory$ = GetCurrentDirectory()
FileName$ = NomFichier           
If ExamineDirectory(0, Directory$, FileName$) 
  While NextDirectoryEntry(0)
    If DirectoryEntryType(0) = #PB_DirectoryEntry_File
        If flag = 0
        Time= DirectoryEntryDate(0, #PB_Date_Modified)
        ElseIf flag = 1
        Time = DirectoryEntryDate(0, #PB_Date_Created)
        ElseIf flag = 2
        Time = DirectoryEntryDate(0, #PB_Date_Accessed)
        EndIf
     EndIf
    Wend
    FinishDirectory(0)
    EndIf
    ProcedureReturn FormatDate(DateFormat, Time)
  EndProcedure
 
Procedure IsAdmin ()
 If IsUserAnAdmin_()
  ProcedureReturn 1
Else
  ProcedureReturn 0
EndIf
EndProcedure   

Procedure.s GetIpToHostname(hostname.s)
  Define result.s = "", netid.i, ip.l
  netid = OpenNetworkConnection(hostname, 0, #PB_Network_UDP)
  If netid
    ip = GetClientIP(netid)
    If ip
      result = IPString(ip)
    EndIf 
    CloseNetworkConnection(netid)
  EndIf
  ProcedureReturn result
EndProcedure

Procedure.s HostNameToIp(hostname.s)
If InitNetwork()
  ProcedureReturn GetIpToHostname(hostname)
EndIf
EndProcedure

Procedure.s Ping (hostname.s)
Ping = RunProgram("Ping",Hostname+" -n 1 -w 255", "", #PB_Program_Hide | #PB_Program_Open | #PB_Program_Read)
cont=0
work=0
If Ping
   While ProgramRunning(Ping)
      risposta.s=ReadProgramString(Ping)
      cont=FindString(risposta,"TTL=",1)
      If cont
        work=1
        time.s=RemoveString(risposta,Left(risposta,cont+3))
      EndIf
   Wend
EndIf
If work
  ProcedureReturn Time
Else
  ProcedureReturn "1"
EndIf
End
EndProcedure

;#######################FileGetVersion ######################################
  Enumeration
  #FV_FileVersion      = $0001
  #FV_FileDescription  = $0002
  #FV_LegalCopyright   = $0004
  #FV_InternalName     = $0008
  #FV_OriginalFilename = $0010
  #FV_ProductName      = $0020
  #FV_ProductVersion   = $0040
  #FV_CompanyName      = $0080
  #FV_LegalTrademarks  = $0100
  #FV_SpecialBuild     = $0200
  #FV_PrivateBuild     = $0400
  #FV_Comments         = $0800
  #FV_Language         = $1000
  #FV_All              = $1FFF
EndEnumeration
Procedure.s GFVI_GetElementName(elementKey.l)
  If     elementKey = #FV_FILEVERSION        : ProcedureReturn "FileVersion"
  ElseIf elementKey = #FV_FILEDESCRIPTION    : ProcedureReturn "FileDescription"
  ElseIf elementKey = #FV_LEGALCOPYRIGHT   : ProcedureReturn "LegalCopyright"
  ElseIf elementKey = #FV_INTERNALNAME     : ProcedureReturn "InternalName"
  ElseIf elementKey = #FV_ORIGINALFILENAME : ProcedureReturn "OriginalFilename"
  ElseIf elementKey = #FV_PRODUCTNAME     : ProcedureReturn "ProductName"
  ElseIf elementKey = #FV_PRODUCTVERSION   : ProcedureReturn "ProductVersion"
  ElseIf elementKey = #FV_COMPANYNAME       : ProcedureReturn "CompanyName"
  ElseIf elementKey = #FV_LEGALTRADEMARKS  : ProcedureReturn "LegalTrademarks"
  ElseIf elementKey = #FV_SPECIALBUILD     : ProcedureReturn "SpecialBuild"
  ElseIf elementKey = #FV_PRIVATEBUILD     : ProcedureReturn "PrivateBuild"
  ElseIf elementKey = #FV_COMMENTS        : ProcedureReturn "Comments"
  ElseIf elementKey = #FV_Language         : ProcedureReturn "Language"
  EndIf
EndProcedure
CompilerIf #PB_Compiler_Unicode
  Prototype.l GetFileVersionInfoSizeW(lptstrFilename.p-unicode, lpdwHandle.l)
  Prototype.l GetFileVersionInfoW(lptstrFilename.p-unicode, dwHandle.l, dwLen.l, lpData.l)
  Prototype.l VerQueryValueW(pBlock.l,lpSubBlock.p-unicode,lplpBuffer.l,puLen.w)
  Prototype.l VerLanguageNameW(wLang.l,szLang.p-unicode,cchLang.l)
CompilerElse
  Prototype.l GetFileVersionInfoSizeA(lptstrFilename.p-ascii, lpdwHandle.l)
  Prototype.l GetFileVersionInfoA(lptstrFilename.p-ascii, dwHandle.l, dwLen.l, lpData.l)
  Prototype.l VerQueryValueA(pBlock.l,lpSubBlock.p-ascii,lplpBuffer.l,puLen.w)
  Prototype.l VerLanguageNameA(wLang.l,szLang.p-ascii,cchLang.l) 
CompilerEndIf
Procedure.s FileGetVersion(lptstrFilename$,lekFlags,bFieldName=#False)
  Protected lpdwHandle.l, dwLen.w, lpData.l, lplpBuffer.l, puLen.l, *pBlock, lpSubBlock$
  Protected nSize.w, szLang$, bBit.b, lekFlag.l, sElement$, sGFVI$
  lplpBuffer = 0 : puLen = 0 : sGFVI$ = "" : nSize = 128 : szLang$ = Space(nSize)
  If FileSize(lptstrFilename$)>0
    If OpenLibrary(1,"Version.dll")
      CompilerIf #PB_Compiler_Unicode
        GetFileVersionInfoSize.GetFileVersionInfoSizeW = GetFunction(1,"GetFileVersionInfoSizeW")
        GetFileVersionInfo.GetFileVersionInfoW = GetFunction(1,"GetFileVersionInfoW")
        VerQueryValue.VerQueryValueW = GetFunction(1,"VerQueryValueW")
        VerLanguageName.VerLanguageNameW = GetFunction(1,"VerLanguageNameW")
      CompilerElse
        GetFileVersionInfoSize.GetFileVersionInfoSizeA = GetFunction(1,"GetFileVersionInfoSizeA")
        GetFileVersionInfo.GetFileVersionInfoA = GetFunction(1,"GetFileVersionInfoA")
        VerQueryValue.VerQueryValueA = GetFunction(1,"VerQueryValueA")
        VerLanguageName.VerLanguageNameA = GetFunction(1,"VerLanguageNameA")
      CompilerEndIf
      dwLen = GetFileVersionInfoSize(lptstrFilename$,@lpdwHandle)
      If dwLen>0
        *pBlock=AllocateMemory(dwLen)
        If *pBlock>0
          Result = GetFileVersionInfo(lptstrFilename$,0,dwLen,*pBlock)
          If Result
            lpSubBlock$ = "\\VarFileInfo\\Translation"
            Result      = VerQueryValue(*pBlock,lpSubBlock$,@lplpBuffer,@puLen)
            If Result
              CPLI$  = RSet(Hex(PeekW(lplpBuffer)),4,"0")+RSet(Hex(PeekW(lplpBuffer+2)),4,"0")
              VerLanguageName(PeekW(lplpBuffer),szLang$,nSize)
            EndIf
            lekFlag = 1
            For bBit = 1 To 12
              If lekFlag & lekFlags
                sElement$   = GFVI_GetElementName(lekFlag)
                lpSubBlock$ = "\\StringFileInfo\\"+CPLI$+"\\"+sElement$
                Result      = VerQueryValue(*pBlock,lpSubBlock$,@lplpBuffer,@puLen)
                If Result
                  If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf
                  If bFieldName
                    sGFVI$=sGFVI$+sElement$+":"+Chr(9)+PeekS(lplpBuffer,puLen)
                  Else
                    sGFVI$=sGFVI$+PeekS(lplpBuffer,puLen)
                  EndIf
                EndIf
              EndIf
              lekFlag << 1
            Next
            If lekFlag & lekFlags
              If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf
              If bFieldName
                sElement$ = GFVI_GetElementName(lekFlag)
                sGFVI$    = sGFVI$+sElement$+":"+Chr(9)+szLang$
              Else
                sGFVI$    = sGFVI$+szLang$
              EndIf
            EndIf
          EndIf
          FreeMemory(*pBlock)
        EndIf
      EndIf
      CloseLibrary(1)
    EndIf
  EndIf
  ProcedureReturn sGFVI$
EndProcedure
;#######################FileGetVersion ######################################

Procedure.s OSVersions ()
      sVersion.s = ""
      Select OSVersion()
            Case #PB_OS_Windows_NT3_51:       sVersion = "Windows NT3.51"
            Case #PB_OS_Windows_95:           sVersion = "Windows 95"
            Case #PB_OS_Windows_NT_4:         sVersion = "Windows NT4"
            Case #PB_OS_Windows_98:           sVersion = "Windows 98"
            Case #PB_OS_Windows_ME:           sVersion = "Windows ME"
            Case #PB_OS_Windows_2000:         sVersion = "Windows 2000"
            Case #PB_OS_Windows_XP:           sVersion = "Windows XP"
            Case #PB_OS_Windows_Server_2003:  sVersion = "Windows Server 2003"
            Case #PB_OS_Windows_Vista:        sVersion = "Windows Vista"
            Case #PB_OS_Windows_Server_2008:  sVersion = "Windows Server 2008"
            Case #PB_OS_Windows_7:            sVersion = "Windows 7"
            Case #PB_OS_Windows_Server_2008_R2: sVersion = "Windows Server 2008 R2"
            Case #PB_OS_Windows_8:              sVersion = "Windows 8"   
            Case #PB_OS_Windows_Server_2012:    sVersion = "Windows Server 2012"
            Case #PB_OS_Windows_8_1:            sVersion = "Windows 8.1"
            Case #PB_OS_Windows_Server_2012_R2: sVersion = "Windows Server 2012 R2"
            Case #PB_OS_Windows_10:             sVersion = "Windows 10"
            Case #PB_OS_Windows_Future:        sVersion = "Windows Os of the Future"
            Default:                           sVersion = "Unidentified Windows version"
          EndSelect
     ProcedureReturn sVersion
   EndProcedure

   ;FonctionEnd ###########################
   ;Procedure MouseClick (button.s,x=0,y=0,clicks = 1,speed = 10)
   ;  InitMouse()
   ;  ExamineMouse() ; Etat de la souris
   ;  x = MouseX()   ; Position en x de la souris                     
   ;  y = MouseY()   ; Position en y de la souris
     
     
   ; EndProcedure
   ;############################################### Mouse Functions ##################################
   
   Procedure MouseClick (button.s,x=0,y=0,clicks = 1,speed = 10)
    InitMouse()
    ExamineMouse() ; Etat de la souris
    x = MouseX()   ; Position en x de la souris                     
    y = MouseY()   ; Position en y de la souris
  EndProcedure
 
  Procedure MouseMoveSpeed (PosX=0,PosY=0,Speed=0)
    InitMouse()
  x.i = DesktopMouseX()
  y.i = DesktopMouseY()
  cal=x-PosX
  cal2=y-PosY
    Debug x
    Debug cal
   
    For i=cal To x
      Debug i
      Delay (Speed)
      SetCursorPos_(i,DesktopMouseY())
      If stringleft (string(cal),1) = "-"
       i=i-1
      Else
      i=i+1
    EndIf
    Next
   
      For i=cal2 To y
      Debug i
      Delay (Speed)
      SetCursorPos_(DesktopMouseX(),i)
      If stringleft (string(cal2),1) = "-"
       i=i-1
      Else
      i=i+1
      EndIf
     
    Next
  EndProcedure
  ;MouseMoveSpeed (10,100,1)


 
 
Procedure MouseGetPos (Array xy (1)); 0 Return X | 1 Return Y |
x.i = DesktopMouseX()
y.i = DesktopMouseY()
xy(0) =x
xy(1) =y
EndProcedure

;############################################### Mouse Functions ##################################

Procedure StringSplit(Array a$(1), s$, delimeter$)
  Protected count, i
  count = CountString(s$,delimeter$) + 1
  Dim a$(count)
  For i = 1 To count
    a$(i - 1) = StringField(s$,i,delimeter$)
  Next
  ProcedureReturn count ;return count of substrings
EndProcedure

Procedure.s FileGetAttrib  (File.s)
    Value = GetFileAttributes(File)
    If Value = -1
    ProcedureReturn "0"
    Else
      If Value & #PB_FileSystem_ReadOnly   : txt$ + "R" :EndIf
      If Value & #PB_FileSystem_Archive    : txt$ + "A" :EndIf
      If Value & #PB_FileSystem_System     : txt$ + "S" :EndIf
      If Value & #PB_FileSystem_Hidden     : txt$ + "H" :EndIf
      If Value & #PB_FileSystem_Normal     : txt$ + "N" :EndIf
      If Value & #PB_FileSystem_Compressed : txt$ + "C" :EndIf   
  EndIf 
ProcedureReturn txt$
EndProcedure

 Macro Beep  (Frequency,Duration)
     Beep_(Frequency,Duration)
 EndMacro

Procedure.s CpuSerialNumber()
    Define highbits.l
    Define lowbits.l
    Define serial.q
    !MOV eax, $80000003
    !CPUID
    !MOV dword [p.v_lowbits], ecx
    !MOV dword [p.v_highbits], edx
    serial = lowbits | highbits << 32
    ProcedureReturn Str(serial)
  EndProcedure
 
 
 
 
 
;############################################### Process Functions ##################################
 
#SystemProcessInformation = $0005
Structure _UNICODE_STRING Align #PB_Structure_AlignC
  usLength.w
  usMaximumLength.w   
  usBuffer.i
EndStructure
Structure _SYSTEM_PROCESS_INFO Align #PB_Structure_AlignC
  NextEntryOffset.l
  NumberOfThreads.l
  Reserved.q[3]
  CreateTime.q
  UserTime.q
  KernelTime.q
  ImageName._UNICODE_STRING
  BasePriority.l
  ProcessId.i
  InheritedFromProcessId.i
EndStructure
Procedure ProcessList (Array a$(1),Array b$(1))
Dim a$(1)
Dim b$(1)
i=0
Define dwlen, *Buffer, *SPI._SYSTEM_PROCESS_INFO
NtQuerySystemInformation_(#SystemProcessInformation, 0, 0, @dwlen)
If dwlen
  dwlen * 2
  *Buffer = AllocateMemory(dwlen)
  If *Buffer
    If NtQuerySystemInformation_(#SystemProcessInformation, *Buffer, dwlen, @dwlen) = 0
      *SPI = *Buffer
      While *SPI\NextEntryOffset
        If *SPI\ImageName\usBuffer
        a$(i) =PeekS(*SPI\ImageName\usBuffer, -1, #PB_Unicode)
        b$(i) =RSet(Str(*SPI\ProcessId), 4, "0")
        i=i+1
        ReDim a$ (i)
        ReDim b$ (i)
      EndIf
        *SPI + *SPI\NextEntryOffset
      Wend
    EndIf
    FreeMemory(*Buffer)
    ReDim a$ (i-1)
    ReDim b$ (i-1)
  EndIf
EndIf
EndProcedure

Procedure ClosePID (Pida$)
    pid = Val (pida$)
    #PROCESS_TERMINATE = $1
    Handle = OpenProcess_ (#PROCESS_TERMINATE,#False,Pid)
    If Handle <> #Null
    If TerminateProcess_ (Handle, 1)
            result = 1
    EndIf
     CloseHandle_ (Handle)
    EndIf
    ProcedureReturn result
EndProcedure

Procedure ProcessClose (NameOrPID$)
  If IsNumeric (NameOrPID$)
    If ClosePID (NameOrPID$)
      ProcedureReturn 1
    Else
      ProcedureReturn 0
    EndIf
  Else 
Dim ProcessName.s(1)
Dim PID.s(1)         
ProcessList (ProcessName (),PID ())
For i = 0 To ArraySize (ProcessName ())
  If ProcessName (i) = NameOrPID$
    If ClosePID (PID (i))
      ProcedureReturn 1
    Else
      ProcedureReturn 0
    EndIf
  EndIf
Next
EndIf
ProcedureReturn 0
EndProcedure

Procedure ProcessExists (NameOrPID$)
Dim ProcessName.s(1)
Dim PID.s(1)         
ProcessList (ProcessName (),PID ())
For i = 0 To ArraySize(PID ())
  If PID (i) = NameOrPID$
    ProcedureReturn Val (PID (i))
 ElseIf ProcessName (i) = NameOrPID$
   ProcedureReturn Val (PID (i))
  EndIf
Next
ProcedureReturn 0
EndProcedure



Procedure ProcessSetPriority (Process.s, priority)
;$PROCESS_LOW (0) = Veille/Basse
;$PROCESS_BELOWNORMAL (1) = Inférieur à la normale
;$PROCESS_NORMAL (2) = Normale
;$PROCESS_ABOVENORMAL (3) = Supérieure à la normale
;$PROCESS_HIGH (4) = Haute
;$PROCESS_REALTIME (5) = Temps réel (utiliser avec prudence, peut rendre le système instable)
#PROCESS_ALL_ACCESS = 2035711
#PROCESS_LOW =0
#PROCESS_BELOWNORMAL =1
#PROCESS_NORMAL =2
#PROCESS_ABOVENORMAL =3
#PROCESS_HIGH        =4
#PROCESS_REALTIME    =5
PIDPriority=ProcessExists (Process)
If PIDPriority
OpenPIDP = OpenProcess_(#PROCESS_ALL_ACCESS, #False,PIDPriority)

Select priority
  Case 0
    If SetPriorityClass_(OpenPIDP,$00000040) = 0
      ProcedureReturn 0
    Else
      ProcedureReturn 1
      EndIf
  Case 1
    If SetPriorityClass_(OpenPIDP,$00004000)= 0
      ProcedureReturn 0
    Else
      ProcedureReturn 1
      EndIf
  Case 2
   If  SetPriorityClass_(OpenPIDP,$00000020)= 0
      ProcedureReturn 0
    Else
      ProcedureReturn 1
      EndIf
  Case 3
    If SetPriorityClass_(OpenPIDP,$00008000)= 0
      ProcedureReturn 0
    Else
      ProcedureReturn 1
      EndIf
  Case 4
    If SetPriorityClass_(OpenPIDP,$00000080)= 0
      ProcedureReturn 0
    Else
      ProcedureReturn 1
      EndIf
  Case 5
    If SetPriorityClass_(OpenPIDP,$00000100)= 0
      ProcedureReturn 0
    Else
      ProcedureReturn 1
      EndIf
  Default
   If  SetPriorityClass_(OpenPIDP,priority)= 0
      ProcedureReturn 0
    Else
      ProcedureReturn 1
      EndIf
    EndSelect
Else
  ProcedureReturn 0
  EndIf

EndProcedure


;############################################### Process Functions ##################################






;############################################### INI Functions ##################################

Procedure IniWrite (FileName.s,section.s,key.s,value.s)
      Hkml=CreatePreferences(FileName)
      If Hkml = 0
        ProcedureReturn 0
      EndIf
        PreferenceGroup(Section)
        WritePreferenceString(key,value)
ClosePreferences() 
EndProcedure
     
 Procedure.s IniRead (FileName.s,section.s,key.s,DefaultIni.s="") 
  Hkml=OpenPreferences(FileName)
    If Hkml = 0
        ProcedureReturn "0"
      EndIf
  PreferenceGroup(Section)
  ExaminePreferenceKeys()
  While  NextPreferenceKey()
    vp.s=PreferenceKeyName()
    If  vp = key
      save.s=ReadPreferenceString(vp,"0")
      ClosePreferences()
      ProcedureReturn save
    Else
      ProcedureReturn DefaultIni
      EndIf
  Wend
EndProcedure

Procedure IniDelete(filename$, section$, key$ = "")
    If OpenPreferences(filename$)
        If key$ = ""
            RemovePreferenceGroup(section$)
        Else
            If PreferenceGroup(section$)
                RemovePreferenceKey(key$)
            EndIf
        EndIf
        ClosePreferences()
    EndIf
  EndProcedure
 
  Procedure IniReadSectionNames(filename$,Array a$(1))
  i=0
    NewList Groups.s()
    If OpenPreferences(filename$)
        ExaminePreferenceGroups()
        While NextPreferenceGroup()
            AddElement(Groups())
            Groups() = PreferenceGroupName()
        Wend
        ClosePreferences()
      EndIf
Define List1.s
ForEach Groups()
  a$(i) = List1 + Groups()
  i=i+1
  ReDim a$ (i)
  Next
EndProcedure
 
  ;############################################### INI Functions ##################################
 
 
 
 
 
 
 
 
 
 
;############################################### Drive Functions ##################################
 
Global Procedure_Error = 0
Global Procedure_Extended = 0
Enumeration
#DRIVE_UNKNOWN = $0000
#DRIVE_REMOVABLE = $0002
#DRIVE_FIXED = $0003
#DRIVE_REMOTE = $0004
#DRIVE_CDROM = $0005
#DRIVE_RAMDISK =$0006

EndEnumeration
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
 
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

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

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

Procedure.s DriveGetLabel(Drive$)
    #MAX_PATH = 256
    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

Procedure.s DriveGetFileSystem(Drive$)
    #MAX_PATH = 256
    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

 
  ;############################################### drive Functions ##################################

Procedure.s FileGetShortName(File$)
  len = Len(File$)
  ShortName$ = Space(len)
  If GetShortPathName_(File$,ShortName$,len)
    ProcedureReturn ShortName$
  Else
    ProcedureReturn ""
  EndIf
EndProcedure

Procedure.s FileGetLongName(File$)
  len = Len(File$)+512
  ShortName$ = Space(len)
  If GetLongPathName_(File$,ShortName$,len)
    ProcedureReturn ShortName$
  Else
    ProcedureReturn ""
  EndIf
EndProcedure



;################################## HandleFunctions ##########################################################
Procedure.s HandleToHex (Handle)
  Hex$=Hex (Handle)
  If AutoItX64 () = 1
  CountZero=25-Len (Hex$)
  Base$="0x"
  For i = 0 To CountZero
    i=i+1
    Base$=Base$+"0"
  Next
Else
  CountZero=8-Len (Hex$)
  Base$="0x"
  For i = 0 To CountZero
    i=i+1
    Base$=Base$+"0"
  Next
  EndIf
  ProcedureReturn Base$+Hex$
EndProcedure

Procedure.l HexToHandle (Hex.s)
Erg.l=0
For i.l=1 To Len(Hex)
c.l = Asc(Mid(Hex,i,1))
If c>64
c - 55
EndIf
If c>47
c - 48
EndIf
Erg = Erg << 4 + c
Next
ProcedureReturn erg
EndProcedure

#GW_CHILD=$5
#GW_HWNDNEXT=$2
Procedure FindPartialWindow(part$)
  r=GetWindow_(GetDesktopWindow_(),#GW_CHILD)
  Repeat
    t$=Space(999) : GetWindowText_(r,t$,999)
    If FindString(t$,part$,1)<>0
      w=r
    Else
      r=GetWindow_(r,#GW_HWNDNEXT)
    EndIf
  Until r=0 Or w<>0
  ProcedureReturn w
EndProcedure

Procedure IsHWnd (Class$,Title$=#Null$)
  Handle=FindWindow_(Class$,Title$)
  If Handle
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

Procedure.s WinGetHandle (Class$,Title$=#Null$)
  Handle=FindWindow_(Class$,Title$)
  ProcedureReturn HandleToHex (Handle)
EndProcedure
 
Procedure.s WinWait (TitleOrtext$,timeout = 0)
  If timeout = 0
    Repeat
      Delay (10)
      handle=FindPartialWindow(TitleOrtext$)
      If handle <> 0
        ProcedureReturn HandleToHex (Handle)
      EndIf
    ForEver
  Else
    StartTime=ElapsedMilliseconds()
    Repeat
      If ElapsedMilliseconds() - StartTime=>timeout*1000
        ProcedureReturn "0"
      EndIf
      Delay (10)
      handle=FindPartialWindow(TitleOrtext$)
      If handle <> 0
        ProcedureReturn HandleToHex (Handle)
      EndIf
 ForEver
EndIf
EndProcedure

Procedure WinExists (TitleOrtext$)
  If IsNumeric (TitleOrText.s)
      Handle=Val (TitleOrText)
    Else
      Handle=FindPartialWindow(TitleOrtext$)
    EndIf

  If handle = 0
    ProcedureReturn 0
  Else
    ProcedureReturn 1
    EndIf
  EndProcedure
 
  Procedure WinWaitClose (TitleOrtext$,timeout = 0)
    If timeout = 0
      Repeat
        Delay (10)
    handle=FindPartialWindow(TitleOrtext$)
    If handle = 0
      ProcedureReturn 1
    EndIf
    ForEver
  Else
    StartTime=ElapsedMilliseconds()
    Repeat
      Delay (10)
    handle=FindPartialWindow(TitleOrtext$)
    If handle = 0
      ProcedureReturn 1
    EndIf
    If ElapsedMilliseconds() - StartTime=>timeout*1000
        ProcedureReturn 0
    EndIf
      ForEver
    EndIf
  EndProcedure
 
 
  Procedure WinWaitActive (TitleOrtext$,timeout = 0)
    If timeout = 0
      Repeat
        Delay (10)
    handle=FindPartialWindow(TitleOrtext$)
    If handle <> 0
      ProcedureReturn 1
    EndIf
    ForEver
  Else
    StartTime=ElapsedMilliseconds()
    Repeat
      Delay (10)
    handle=FindPartialWindow(TitleOrtext$)
    If handle <> 0
      ProcedureReturn 1
    EndIf
    If ElapsedMilliseconds() - StartTime=>timeout*1000
        ProcedureReturn 0
    EndIf
      ForEver
    EndIf
  EndProcedure
 
 
  Procedure.s WinGetProcess (TitleOrtext$)
  If IsNumeric (TitleOrText.s)
      Handle=Val (TitleOrText)
    Else
      Handle=FindPartialWindow(TitleOrtext$)
    EndIf
Define.i handle, pid, thrid
If handle And IsWindow_(handle)
  thrid = GetWindowThreadProcessId_(handle, @pid)
  ProcedureReturn Str(pid)
EndIf
EndProcedure

Procedure WinMinimizeAll()
  h = GetWindow_(GetDesktopWindow_(), #GW_CHILD)
  Repeat
    If IsWindowVisible_(h) = #True
      c$ = Space(999) : GetWindowText_(h, c$, 999)
      If c$ <> ""
        ShowWindow_(h,6)
      EndIf
    EndIf
    h = GetWindow_(h, #GW_HWNDNEXT)
  Until h = 0
EndProcedure

Procedure WinKill (TitleOrText.s)
  PID.s=WinGetProcess (TitleOrText.s)
  RunProgram ("cmd.exe","/c taskkill /PID "+pid+" /f","",#PB_Program_Hide | #PB_Program_Open | #PB_Program_Read | #PB_Program_Ascii)
  ProcedureReturn WinExists (TitleOrtext)
EndProcedure

Procedure SearchHandle (TitleOrtext$)
handle=FindPartialWindow(TitleOrtext$)   
If handle And IsWindow_(handle)
  ProcedureReturn handle
EndIf
EndProcedure

Procedure WinSetState (TitleOrText.s,Flag)
    #SW_HIDE = 0
    #SW_SHOW = 5
    #SW_MINIMIZE = 6
    #SW_MAXIMIZE = 3
    #SW_RESTORE = 9
    #SW_DISABLE = 4
    #SW_ENABLE = 1
    If IsNumeric (TitleOrText.s)
      Handle=Val (TitleOrText)
    Else
      Handle=SearchHandle (TitleOrText.s)
    EndIf
     If IsNumeric(Str(Handle)) = 1
       Select flag
         Case 0
           ShowWindow_(Handle,0)
         Case 5
           ShowWindow_(Handle,5)
         Case 6
           ShowWindow_(Handle,6)
         Case 3
           ShowWindow_(Handle,3)
         Case 9
           ShowWindow_(Handle,9)
         Case 4
           ShowWindow_(Handle,4)
         Case 1
           ShowWindow_(Handle,1)
         Default
         ProcedureReturn 0
       EndSelect
    ProcedureReturn 1
  Else
    ProcedureReturn 0
    EndIf
  EndProcedure
 
                                                                                                     
 Procedure WinActive (TitleOrText.s)
    Handle = GetForegroundWindow_ ()
    If IsNumeric (TitleOrText.s)
      Handle2=Val (TitleOrText)
    Else
      Handle2=SearchHandle (TitleOrText.s)
    EndIf
    If Handle2 = Handle
    ProcedureReturn 1
    Else
    ProcedureReturn 0
    EndIf
  EndProcedure
 
Procedure WinList (Array a$(1),Array b$(1),VisibleWindow = 1)
Dim a$(1)
Dim b$(1)
h = GetWindow_(GetDesktopWindow_(), #GW_CHILD)
i=0
Repeat
    If VisibleWindow = 1
    If IsWindowVisible_(h) = #True
    c$ = Space(999) : GetWindowText_(h, c$, 999)
    ReDim a$ (i)
    ReDim b$ (i)
    a$(i) = c$
    b$(i) = Str(h)
    i=i+1
  EndIf
Else
    c$ = Space(999) : GetWindowText_(h, c$, 999)
    ReDim a$ (i)
    ReDim b$ (i)
    a$(i) = c$
    b$(i) = Str(h)
    i=i+1
  EndIf
    h = GetWindow_(h, #GW_HWNDNEXT)
   
  Until h = 0
   
EndProcedure


Procedure WinSetTitle (TitleOrText.s,NewTitle.s)
  If IsNumeric (TitleOrText.s)
    ProcedureReturn SetWindowText_ (Val(TitleOrText.s),NewTitle)
    Else
Handle=SearchHandle (TitleOrText.s)
ProcedureReturn SetWindowText_ (Handle,NewTitle)
EndIf
EndProcedure


Procedure.s PixelGetColor (x,y)
HDC = GetDC_(0)
 PixelColour = GetPixel_(hDC,x,y)
 Red = Red(PixelColour)
 Green = Green(PixelColour)
 Blue = Blue(PixelColour)
 PixelColour$ = "#" + RSet(Hex(Red), 2, "0") + RSet(Hex(Green), 2, "0") + RSet(Hex(Blue), 2, "0")
 ReleaseDC_(0,HDC)
 ProcedureReturn PixelColour$
EndProcedure


Procedure WinSetTrans (TitleOrtext$,transparency)
  alpha=SearchHandle (TitleOrtext$)
  Debug alpha
  If SetLayeredWindowAttributes_(alpha,1,transparency,2)
    ProcedureReturn 1
  Else
    ProcedureReturn 0
    EndIf
EndProcedure





;################################## HandleFunctions ##########################################################












;################################## Shutdown ##########################################################

Procedure ShutdownPrivilege()
  #TOKEN_ADJUST_PRIVILEGES = 32   
  #TOKEN_QUERY = 8               
  #SE_PRIVILEGE_ENABLED = 2
  Structure MyLUID
    LowPart.l
    HighPart.l
    Attributes.l
  EndStructure
  Structure MyTOKEN
    PrivilegeCount.l
    LowPart.l
    HighPart.l
    Attributes.l
  EndStructure
  Global hdlProcessHandle.l
  Global hdlTokenHandle.l
  Global tmpLuid.MyLUID
  Global tkp.MyTOKEN
  Global tkpNewButIgnored.MyTOKEN
  Global lBufferNeeded.l
  hdlProcessHandle = GetCurrentProcess_()
  OpenProcessToken_(hdlProcessHandle, #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @hdlTokenHandle)
  ; Get the LUID for shutdown privilege
  SysName.s = "" + Chr(0)
  Name.s = "SeShutdownPrivilege" + Chr(0)
  Erg.l = LookupPrivilegeValue_(SysName, Name, @tmpLuid)
  tmpLuid\Attributes = #SE_PRIVILEGE_ENABLED
  tkp\PrivilegeCount = 1
  tkp\LowPart = tmpLuid\LowPart
  tkp\HighPart = tmpLuid\HighPart
  tkp\Attributes = tmpLuid\Attributes
  ; Enable the shutdown privilege in the access token of this process
  Erg.l = AdjustTokenPrivileges_(hdlTokenHandle, 0, @tkp, SizeOf(MyTOKEN), @tkpNewButIgnored, @lblBufferNeeded)

EndProcedure

Procedure HibernateAllowed()
   Protected LibraryID
   Protected Result = #False
   
   LibraryID = OpenLibrary(#PB_Any, "powrprof.dll")
   If LibraryID
      Result = CallFunction(LibraryID, "IsPwrHibernateAllowed")
      CloseLibrary(LibraryID)
   EndIf
   
   ProcedureReturn Result
 EndProcedure
 
 Procedure Suspend(Hibernate, ForceCritical=#False, DisableWakeEvent=#False)
   Protected LibraryID
   Protected Result = #False
   
   LibraryID = OpenLibrary(#PB_Any, "powrprof.dll")
   If LibraryID
      Result = CallFunction(LibraryID, "SetSuspendState", Hibernate, ForceCritical, DisableWakeEvent)
      CloseLibrary(LibraryID)
   EndIf
   
   ProcedureReturn Result
EndProcedure
 
Procedure Shutdown (Flag)
  ShutdownPrivilege()
    #SD_LOGOFF=0
    #SD_SHUTDOWN=1
    #SD_REBOOT=2
    #SD_FORCE=4
    #SD_POWERDOWN=8
    #SD_FORCEHUNG=16
    #SD_STANDBY=32
    #SD_HIBERNATE=64
    Select Flag
        Case 0
         ProcedureReturn ExitWindowsEx_ (0,0)
        Case 1
         ProcedureReturn ExitWindowsEx_ (1,0)
        Case 2
         ProcedureReturn ExitWindowsEx_ (2,0)
        Case 4
         ProcedureReturn ExitWindowsEx_ (4,0)
        Case 8
         ProcedureReturn ExitWindowsEx_ (8,0)
        Case 16
          ProcedureReturn ExitWindowsEx_ (10,0)
        Case 32
          ProcedureReturn Suspend(0)
        Case 64
          If HibernateAllowed()
            ProcedureReturn Suspend(1)
          Else
            ProcedureReturn 0
          EndIf
         Default
         ProcedureReturn ExitWindowsEx_ (Flag,0)
    EndSelect
  EndProcedure


;################################## Shutdown ##########################################################


;################################## Environment ##########################################################
 Macro EnvGET(envvariable)
    GetEnvironmentVariable(envvariable)
EndMacro
 
Macro EnvSet (envvariable,value)
    SetEnvironmentVariable(envvariable, value)
EndMacro

 

;################################## Environment ##########################################################





;################################## FileDirDisk  ##########################################################

#SHERB_NOCONFIRMATION = 1
#SHERB_NOPROGRESSUI   = 2
#SHERB_NOSOUND        = 4
Prototype EmptyRecycleBin(hwnd = 0, pszRootPath.s = #Null$, dwFlags = #SHERB_NOCONFIRMATION | #SHERB_NOSOUND | #SHERB_NOPROGRESSUI)
If OpenLibrary(0, "shell32.dll")
  CompilerIf #PB_Compiler_Unicode
    Global FileRecycleEmpty.EmptyRecycleBin = GetFunction(0, "SHEmptyRecycleBinW")
  CompilerElse
    Global FileRecycleEmpty.EmptyRecycleBin = GetFunction(0, "SHEmptyRecycleBinA")
  CompilerEndIf
EndIf

;FileRecycleEmpty()

;################################## FileDirDisk  ##########################################################


Top
 Profile  
Reply with quote  
 Post subject: Re: PureAutoIt - Complete Autoit Functions In Purebasic
PostPosted: Thu Dec 10, 2020 6:18 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 339
Location: NL
ps what is not working on 64 bit Windows?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye