Re: DroopyLib
Posted: Sat Dec 01, 2012 9:45 pm
Excellent Droopy.
Thanks for your great work.
Thanks for your great work.
Code: Select all
Procedure My_Week(date.l)
var_year = Year(date)
var_month = Month(date)
var_day = Day(date)
UK01 = DayOfYear(Date(var_year, var_month, var_day, 0, 0, 0)) - 4
UK02.i = UK01/7
UK03 = DayOfWeek(Date(var_year, var_month, var_day, 0, 0, 0))
If UK03 = 0
UK03 = 7
EndIf
UK04 = DayOfWeek(Date(var_year-1, 1, 4, 0, 0, 0))
If UK04 = 0
UK04 = 7
EndIf
UK05 = DayOfYear(Date(var_year-1, 12, 31, 0, 0, 0)) - 4
UK06.i = UK05/7
UK07 = DayOfWeek(Date(var_year-1, 12, 31, 0, 0, 0))
If UK07 = 0
UK07 = 7
EndIf
UK08 = DayOfWeek(Date(var_year, 1, 4, 0, 0, 0))
If UK08 = 0
UK08 = 7
EndIf
UK09 = DayOfWeek(Date(var_year+1, 1, 4, 0, 0, 0))
If UK09 = 0
UK09 = 7
EndIf
If UK07 < UK08
UK10 = 1
ElseIf UK07 < UK04
UK10 = UK06 + 2
Else
UK10 = UK06 + 1
EndIf
If var_day < 4 And var_month = 1
If UK03 < UK08
UK11=1
Else
UK11=UK10
EndIf
ElseIf var_day > 28 And UK03 < UK09
UK11 = 1
ElseIf UK03 < UK08
UK11 = UK02 + 2
Else
UK11=UK02+1
EndIf
ProcedureReturn UK11
EndProcedure
Pretty sure 5.11 is the lates release ??GeoTrail wrote:Why not just update PB, Sveinung?
I have tested GetPidProcessSveinung wrote:Pretty sure 5.11 is the lates release ??GeoTrail wrote:Why not just update PB, Sveinung?
GetPidProcess
KillProcess
SearchProcess
RunOnlyOneInstance
HandleToFileName
PidToFileName
WaitProgramInitialisation
These are the cpmmands I can't get to work.
Sveinung
Stupid me! Forgot to mention that it was compiling to X64. SORRY!!Bisonte wrote:Maybe you try to get a PID of a x64 program within the PBx86 ?
Code: Select all
Procedure GetPID(Name$, Mode = 0) ; Returns the ProcessID the tasks Name$ or 0 ( Mode = #True : Case Insensitiv)
Protected Process.PROCESSENTRY32
Protected ProcSnap
ProcSnap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
If ProcSnap <> 0
Process\dwsize=SizeOf(Process)
Process32First_(ProcSnap, Process)
While Process32Next_(ProcSnap, Process) > 0
If Mode <> 0
If UCase(PeekS(@Process\szExeFile)) = UCase(Name$)
ProcedureReturn Process\th32ProcessID
Break
EndIf
Else
If PeekS(@Process\szExeFile) = Name$
ProcedureReturn Process\th32ProcessID
Break
EndIf
EndIf
Wend
EndIf
EndProcedure
Code: Select all
Prototype ProcessFirst(Snapshot, Process)
Prototype ProcessNext(Snapshot, Process)
Global ProcessFirst.ProcessFirst
Global ProcessNext.ProcessNext
Global NewList PID()
Prototype GetModuleFileNameEx(hProcess,dwFlags, lpExeName, lpdwSize)
Global GetModuleFileNameEx.GetModuleFileNameEx
Prototype GetProcessImageFileName(hProcess, lpImageFileName, nSize)
Global GetProcessImageFileName.GetProcessImageFileName
Prototype QueryFullProcessImageName(hProcess, dwFlags, lpExeName, lpdwSize)
Global QueryFullProcessImageName.QueryFullProcessImageName
Declare.s PidToFileName(PID)
ProcedureDLL.s HandleToFileName(hWnd.l) ; Returns the file Path and Name of the exe that owns the specified Window Handle
Protected Name.s=""
;// Handle can be found with WindowsEnum()
Pid.l=0
GetWindowThreadProcessId_( hWnd, @Pid )
Name.s=PidToFileName(Pid)
ProcedureReturn Name
EndProcedure
Procedure.s JunctiontoPathname(junction.s)
Protected *Buffer,i,C,nr
Protected Drives.s,Drive.s,DosDeviceName.s,LogicalName.s
If FindString(junction,"Device\LanmanRedirector",1)
LogicalName=RemoveString(junction,"Device\LanmanRedirector")
ProcedureReturn LogicalName
EndIf
*Buffer = AllocateMemory(#MAX_PATH*SizeOf(character))
For i = 0 To GetLogicalDriveStrings_(#MAX_PATH*SizeOf(character), *Buffer)
C = PeekB(*Buffer +i)
If C <> 0
drives.s = UCase(drives) + Chr(C)
EndIf
Next
DosDeviceName = Space(#MAX_PATH*SizeOf(character))
nr=CountString(drives,"\")
For x=1 To nr
drive.s=StringField(drives,x,"\")
QueryDosDevice_(drive, @DosDeviceName, #MAX_PATH*SizeOf(character))
If FindString(junction,DosDeviceName,1)
LogicalName=ReplaceString(junction, DosDeviceName, Drive)
Break
EndIf
Next
ProcedureReturn LogicalName
EndProcedure
Procedure.s PidToFileName(PID)
Protected hProcess
Protected libID
Protected lpdwSize
Protected PathFileName.s = ""
Protected DosDeviceName.s
If OSVersion() => #PB_OS_Windows_Vista
libID = OpenLibrary(#PB_Any, "kernel32.dll")
ElseIf OSVersion() => #PB_OS_Windows_2000 Or OSVersion() < #PB_OS_Windows_Vista
libID = OpenLibrary(#PB_Any, "psapi.dll")
EndIf
CompilerIf #PB_Compiler_Unicode
If OSVersion() = #PB_OS_Windows_2000
GetModuleFileNameEx=GetFunction(libID,"GetModuleFileNameExW")
ElseIf OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
GetProcessImageFileName = GetFunction(libID, "GetProcessImageFileNameW")
ElseIf OSVersion() => #PB_OS_Windows_Vista
QueryFullProcessImageName = GetFunction(libID, "QueryFullProcessImageNameW")
EndIf
CompilerElse
If OSVersion() = #PB_OS_Windows_2000
GetModuleFileNameEx=GetFunction(libID,"GetModuleFileNameExA")
ElseIf OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
GetProcessImageFileName = GetFunction(libID, "GetProcessImageFileNameA")
ElseIf OSVersion() => #PB_OS_Windows_Vista
QueryFullProcessImageName = GetFunction(libID, "QueryFullProcessImageNameA")
EndIf
CompilerEndIf
If GetModuleFileNameEx <> 0 Or GetProcessImageFileName <> 0 Or QueryFullProcessImageName <>0
If OSVersion() = #PB_OS_Windows_2000
hProcess = OpenProcess_( #PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, 0, PID );
ElseIf OSVersion() = > #PB_OS_Windows_XP
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION, 0, PID)
EndIf
If hProcess
PathFileName = Space(#MAX_PATH*4)
lpdwSize=#MAX_PATH*4
If OSVersion() = #PB_OS_Windows_2000
GetModuleFileNameEx(hProcess,0,@PathFileName,@lpdwSize )
ElseIf OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
GetProcessImageFileName(hProcess, @PathFileName, #MAX_PATH)
PathFileName=JunctiontoPathname(PathFileName)
ElseIf OSVersion() => #PB_OS_Windows_Vista
QueryFullProcessImageName(hProcess, DosDevice, @PathFileName, @lpdwSize)
EndIf
CloseHandle_(hProcess)
EndIf
CloseLibrary(libID)
EndIf
ProcedureReturn PathFileName
EndProcedure
;{/*
; MessageRequester("PID Process to Filename","Explorer.exe"+" --> "+PidToFileName(GetPidProcess("Explorer.exe")))
;}
ProcedureDLL GetHandle(WindowsName.s)
retour= FindWindow_(0, WindowsName)
ProcedureReturn retour
EndProcedure
Procedure.b GetPIDProcess(Name.s)
Protected ProcLib
Protected ProcName.s
Protected Process.PROCESSENTRY32
Protected x
Protected RetVal=#False
Name=UCase(Name.s)
ProcLib= OpenLibrary(#PB_Any, "Kernel32.dll")
If ProcLib
CompilerIf #PB_Compiler_Unicode
ProcessFirst = GetFunction(ProcLib, "Process32FirstW")
ProcessNext = GetFunction(ProcLib, "Process32NextW")
CompilerElse
ProcessFirst = GetFunction(ProcLib, "Process32First")
ProcessNext = GetFunction(ProcLib, "Process32Next")
CompilerEndIf
If ProcessFirst And ProcessNext
Process\dwSize = SizeOf(PROCESSENTRY32)
Snapshot =CreateToolhelp32Snapshot_(#TH32CS_SNAPALL,0)
If Snapshot
ProcessFound = ProcessFirst(Snapshot, Process)
x=1
While ProcessFound
ProcName=PeekS(@Process\szExeFile)
ProcName=GetFilePart(ProcName)
If UCase(ProcName)=UCase(Name)
AddElement(PID())
PID()=Process\th32ProcessID
RetVal=#True
EndIf
ProcessFound = ProcessNext(Snapshot, Process)
x=x+1
Wend
EndIf
CloseHandle_(Snapshot)
EndIf
CloseLibrary(ProcLib)
EndIf
ProcedureReturn RetVal
EndProcedure
ret=GetPidProcess("purebasic.exe")
If ret
ForEach PID()
Debug PID()
Next
EndIf
hWin=GetHandle("Unbenannt - Editor")
If hWin
Debug HandleToFileName(hWin)
EndIf
@Sveinung : RunOnlyOneInstance/KillProcess : no bug found23/05/13 : Library 5.11.001
Compiled with PB 5.11 / TB 1.4.9
WaitProgramInitialisation() Bug fixed
SearchProcess() Function rewritten
PidToFileName() Function rewritten
HandleToFileName() Function rewritten
GetPidProcess() Function rewritten
GetPidProcessEx() Function added