Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/14/2015 in all areas

  1. argumentum, Add error.inline=0 to your SciTE user properties file - or change the existing error.inline value to 0. M23
    2 points
  2. Gianni

    Berlin Clock

    ....from the serie "strange clocks": see here for infos on how to read this clock ; Berlin-Uhr HotKeySet("{Esc}", "End") Global $aColors[3] = ["0x757575", "0xFFCC00", "0xFF0033"] ; [off][yellow][red] Local $iSec = 0, $iMin = 0 Global $hGui = GUICreate(' Berlin-Uhr', 275, 240) ; ($nrPerLine, $ctrlWidth, $ctrlHeight, $xPanelPos, $yPanelPos, $xSpace) Local $aGuiSecsX2 = _GuiPanel(01, 55, 35, 115, 010, 5) ; Seconds blink Local $aGuiHourX5 = _GuiPanel(04, 55, 35, 025, 055, 5) ; Hours * 5 Local $aGuiHourX1 = _GuiPanel(04, 55, 35, 025, 100, 5) ; Hours Local $aGuiMinsX5 = _GuiPanel(11, 16, 35, 025, 145, 6) ; Mins * 5 Local $aGuiMinsX1 = _GuiPanel(04, 55, 35, 025, 190, 5) ; Mins GUISetBkColor("0x9A9A9A", $hGui) GUISetState(@SW_SHOW) Do If @SEC <> $iSec Then ; when the second changes do what following $iSec = @SEC GUICtrlSetBkColor($aGuiSecsX2[1], $aColors[@SEC / 2 = Int(@SEC / 2)]) ; second blink If @MIN <> $iMin Then $iMin = @MIN For $i = 1 To 11 If $i < 5 Then GUICtrlSetBkColor($aGuiHourX5[$i], $aColors[2 * (Int(@HOUR / 5) >= $i)]) GUICtrlSetBkColor($aGuiHourX1[$i], $aColors[2 * (Mod(@HOUR, 5) >= $i)]) GUICtrlSetBkColor($aGuiMinsX1[$i], $aColors[Mod(@MIN, 5) >= $i]) EndIf GUICtrlSetBkColor($aGuiMinsX5[$i], $aColors[(Int(@MIN / 5) >= $i) * (1 + ($i = 3 Or $i = 6 Or $i = 9))]) Next EndIf EndIf Until GUIGetMsg() = -3 ; $GUI_EVENT_CLOSE End() Func _GuiPanel($nrPerLine, $ctrlWidth, $ctrlHeight, $xPanelPos, $yPanelPos, $xSpace = 1) ; create the controls Local $aGuiGridCtrls[$nrPerLine + 1] For $i = 1 To $nrPerLine $left = $xPanelPos + ((($ctrlWidth + $xSpace) * ($i - 1)) - $xSpace) $aGuiGridCtrls[$i] = GUICtrlCreateInput("", $left, $yPanelPos, $ctrlWidth, $ctrlHeight, 0x0800) ; 0x0800 = $ES_READONLY GUICtrlSetBkColor(-1, $aColors[0]) Next Return $aGuiGridCtrls EndFunc ;==>_GuiPanel Func End() If WinActive($hGui) Then GUIDelete($hGui) Exit EndIf EndFunc ;==>End
    1 point
  3. UEZ

    jpg to gif

    You have to do some math. 1 second = 1000 miliseconds E.g. you want 5 frames per second (fps) -> 1000 / 5 = 200. Use _GDIPlus_GIFAnimCreateFile($aImages, $sSave, 200) to create the GIF anim using 5 fps or a delay with 200ms between each frame.
    1 point
  4. JLogan3o13

    protect exe file

    zxtnt09, try a forum search, and read some of the other 800 million times this has been asked and answered...
    1 point
  5. You have to upscale the icon manually and add it afterwards to the _GUIImageList_Create. #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> Example() Func Example() _GDIPlus_Startup() Local $idListview, $hImage Local $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES) GUICreate("ImageList Create", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, $iStylesEx) GUISetState(@SW_SHOW) ; Load images $hImage = _GUIImageList_Create(48, 48, 5, 1) ;load icon and upscale the icon to 48x48 pixels Local $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\empty.ico") Local $hBitmap_scaled = _GDIPlus_ImageResize($hBitmap, 48, 48) Local $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled) _GDIPlus_BitmapDispose($hBitmap_scaled) _GDIPlus_BitmapDispose($hBitmap) _GUIImageList_Add($hImage, $hBitmap_GDI) _GUICtrlListView_SetImageList($idListview, $hImage, 1) ; Add columns _GUICtrlListView_AddColumn($idListview, "Items", 120) ; Add items _GUICtrlListView_AddItem($idListview, "Item 1", 0) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() _WinAPI_DeleteObject($hBitmap_GDI) _GDIPlus_Shutdown() EndFunc ;==>Example
    1 point
  6. UEZ

    jpg to gif

    You are not thinking properly with reducing the size using JPG quality! For example when I take a screenshot from my desktop (1600x900) and save it as JPG with quality 50 the filesize is around 95 kb. When saving the bitmap as GIF the filesize is around 375 kb. In your code it makes no sense to set any JPG quality because the screen will be captured to the memory in GDI bitmap format without any quality loss, converted to GDI+ bitmap format and finally the bitmap depth will be reduced to a 8-bit color depth. Thus you have to reduce the bitmap size and/or the color depth of the bitmap: ;creates a GIF animation file #AutoIt3Wrapper_UseX64=n ;~ #AutoIt3Wrapper_Version=b #include <Screencapture.au3> #include "_GDIPlus_GIFAnim.au3" If @OSBuild < 6000 Then Exit MsgBox(16, "ERROR", "Vista or a higher operating system is required to create a GIF animation!", 30) _GDIPlus_Startup() Global $iFrames = 250, $aImages[$iFrames + 1] = [$iFrames], $sSave = @ScriptDir & "\Test.gif", $i, $hHBitmap, $iW = @DesktopWidth, $iH = @DesktopHeight, _ $iX = 0, $iY = 0, $i Global $fEnd, $fTimer = TimerInit() For $i = 1 To $aImages[0] $hHBitmap = _ScreenCapture_Capture("", $iX, $iY, $iX + $iW, $iY + $iH) ;L, T, R, B $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) $aImages[$i] = _GDIPlus_ImageScale($hBmp, 0.2, 0.2) _GDIPlus_BitmapDispose($hBmp) _GDIPlus_BitmapConvertTo8Bit($aImages[$i], 256, $GDIP_DitherTypeSolid) _WinAPI_DeleteObject($hHBitmap) Next ConsoleWrite(_GDIPlus_GIFAnimCreateFile($aImages, $sSave, 40) & ":" & @error & @CRLF) ;40 -> 25 fps (25 * 40 = 1000) $fEnd = TimerDiff($fTimer) ConsoleWrite("Animation created in " & $fEnd & " ms (" & Int($aImages[0] / $fEnd * 1000) & " fps)." & @CRLF) For $i = 1 To $aImages[0] _GDIPlus_ImageDispose($aImages[$i]) Next _GDIPlus_Shutdown() This will create a GIF animation from your desktop with 40 ms delay but the screensize will be reduced to 20%.
    1 point
  7. MikahS

    Get Tree Child number

    @behdadsoft a simple explanation: https://www.autoitscript.com/forum/topic/141263-can-someone-explain-gui-dummy-controls-to-me/?do=findComment&comment=993463 This will only bring up the message box for the child not items: #RequireAdmin #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;global variables Global $aStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) Global $GUI Global $treeObj Global $treeItem[5] Global $treeChild[5] Local $treeText ;Create and show GUI $GUI = GUICreate("TreeView Add", 400, 300) GUISetState(@SW_SHOW, $GUI) ;Create Tree Object $treeObj = GUICtrlCreateTreeView(2, 2, 300, 268, $aStyle, $WS_EX_CLIENTEDGE) ;Add Item and Child to Tree Object Local $iStart = GUICtrlCreateDummy() For $i = 1 To 4 ; start off in first element of array $treeItem[$i] = GUICtrlCreateTreeViewItem("Item" & " " & $i, $treeObj) For $j = 1 To 4 ; start off in first element of array $treeChild[$j] = GUICtrlCreateTreeViewItem("Child" & " " & $j, $treeItem[$i]) Next Next Local $iEnd = GUICtrlCreateDummy() ;loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($treeObj, 1) If Not StringInStr($treeText, "Item") Then MsgBox(0, "", $treeText) EndIf EndSwitch WEnd GUIDelete($GUI) All good?
    1 point
  8. UEZ

    jpg to gif

    I will have a look later because now I've to do some work at home.
    1 point
  9. UEZ

    jpg to gif

    What about the images your are using? Which dimension? GIF images are always 8-bit (256 colors). With difthering the size will increase.
    1 point
  10. ... or start SciTEConfig, Select the "General 2" tab and un-check "Display inline errors in script". Jos
    1 point
  11. The AD UDF (for download please see my signature) allows to retrieve information by functions _AD_GetObjectProperties or _AD_GetObjectAttribute.
    1 point
  12. ​Agree, but let's then also agree that this logic would apply to way too many threads, so that ain't happening unless they spin out of control. Jos
    1 point
  13. UEZ

    jpg to gif

    If you have Vista or a higher OS you can try _GDIPlus_GIFAnim.au3. The 3rd example is how to create a GIF with screenshots. It is very easy to modify the example to add images from disk instead.
    1 point
  14. wakillon

    Transparent Rolling Text

    I was like you some years ago. A bit of research, documentation, and testing and month after month you will see the progress. So...go, go, go !
    1 point
  15. jvds

    AutoIt Console Application

    I was looking around for color output in cmd and then i saw an example that fit your need in color xD the first example on that topic
    1 point
  16. Freely adapted from the helpfile of ConsoleRead. Notice that it should be ran as a compiled exe, and be compiled as a console application (otherwise ConsoleWrite will not write to the dos screen). Use the SciTE compile dialog (Ctrl+F7, check option Create CUI instead of GUI EXE ), or the /console switch to if you command the compiler from the commandline. Run by piping the standard input of the shell session (descriptor CON) to the command, by literally doing this: type CON | myapplication.exe (of course changing the application name to your own). #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <MsgBoxConstants.au3> Example() Func Example() If Not @Compiled Then MsgBox($MB_SYSTEMMODAL, "", "This script must be compiled in order to run the example.") Exit EndIf ConsoleWrite("Enter your name. Enter ^Z on a new line when you're done (equals EOF)." & @CRLF & "Name: ") Local $sOutput While True $sOutput &= ConsoleRead() If @error Then ExitLoop Sleep(25) WEnd ; DOS only recognizes the EOF command when it's at the start of a line, meaning the last character is always a newline While StringRegExp(StringRight($sOutput, 1), "[\r\n]") $sOutput = StringTrimRight($sOutput, 1) WEnd ConsoleWrite("Name received: '" & $sOutput & "'") EndFunc ;==>Example
    1 point
  17. I know, it's not the true forum for this, but I can't write in the example forum. And with my bad English knowledge i will need some time to get the required messages. Maybe a mod can move this. I wrote a script, that can show you the processes on your PC and the windows of those processes: Opt('MustDeclareVars', 1) ;~ #include <GUIConstantsEx.au3> Global Const $GUI_EVENT_CLOSE = -3 Global Const $GUI_CHECKED = 1 Global Const $GUI_SHOW = 16 Global Const $GUI_HIDE = 32 Global Const $GUI_ENABLE = 64 Global Const $GUI_DISABLE = 128 ;~ #include <WindowsConstants.au3> Global Const $WS_MAXIMIZEBOX = 0x00010000 Global Const $WS_MINIMIZEBOX = 0x00020000 Global Const $WS_SIZEBOX = 0x00040000 Global Const $WS_SYSMENU = 0x00080000 Global Const $WS_VSCROLL = 0x00200000 Global Const $WS_BORDER = 0x00800000 Global Const $WS_CAPTION = 0x00C00000 Global Const $WS_POPUP = 0x80000000 Global Const $WS_EX_COMPOSITED = 0x02000000 Global Const $WM_GETMINMAXINFO = 0x0024 Global Const $GUI_SS_DEFAULT_GUI = BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU) SetPrivilege('SeDebugPrivilege', 1) Global $hPsAPI = DllOpen('Psapi.dll') Global $hKernel = DllOpen('Kernel32.dll') OnAutoItExitRegister('_DllClose') Global $Sorted Global $Form1 = GUICreate('Processes and windows monitor', 590, 510, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX), $WS_EX_COMPOSITED) Global $Edit1 = GUICtrlCreateEdit('', 10, 10, 570, 430, 3152064) GUICtrlSetResizing($Edit1, 102) GUICtrlSetState($Edit1, $GUI_HIDE) GUICtrlSetBkColor($Edit1, 0xFFFFFF) Global $List1 = GUICtrlCreateList('', 10, 10, 160, 430, BitOr($WS_BORDER, $WS_VSCROLL)) GUICtrlSetResizing($List1, 354) Global $Edit2 = GUICtrlCreateEdit('', 180, 10, 400, 430, 3152064) GUICtrlSetResizing($Edit2, 102) GUICtrlSetBkColor($Edit2, 0xFFFFFF) Global $Prgs1 = GUICtrlCreateProgress(10, 210, 570, 20) GUICtrlSetState($Prgs1, $GUI_HIDE) GUICtrlSetResizing($Prgs1, 646) Global $ChkB1 = GUICtrlCreateCheckbox('Text only', 10, 450, 60, 20) GUICtrlSetResizing($ChkB1, 834) Global $ChkB2 = GUICtrlCreateCheckbox('Correct the pathes while loading', 80, 450, 180, 20) GUICtrlSetResizing($ChkB2, 834) Global $Radi0 = GUICtrlCreateRadio('Sort with ProcessList()', 10, 480, 120, 20) GUICtrlSetResizing($Radi0, 834) Global $Radi1 = GUICtrlCreateRadio('Sort by ProcessID', 140, 480, 100, 20) GUICtrlSetResizing($Radi1, 834) Global $Radi2 = GUICtrlCreateRadio('Sort by ProcessName', 250, 480, 120, 20) GUICtrlSetResizing($Radi2, 834) Global $Butt1 = GUICtrlCreateButton('Reload', 420, 480, 160, 20) GUICtrlSetResizing($Butt1, 836) Global $Button_About = GUICtrlCreateButton('About', 420, 450, 160, 20) GUICtrlSetResizing($Button_About, 836) GUICtrlSetState($ChkB2, $GUI_CHECKED) GUICtrlSetState($Radi2, $GUI_CHECKED) GUIRegisterMsg($WM_GETMINMAXINFO, 'WM_GETMINMAXINFO') GUISetState() Reload() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Butt1 Reload() Case $List1 GetText() Case $ChkB1 If BitAND(GUICtrlRead($ChkB1), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($Edit1, $GUI_SHOW) GUICtrlSetState($List1, $GUI_HIDE) GUICtrlSetState($Edit2, $GUI_HIDE) Else GUICtrlSetState($Edit1, $GUI_HIDE) GUICtrlSetState($List1, $GUI_SHOW) GUICtrlSetState($Edit2, $GUI_SHOW) EndIf Case $Button_About About() EndSwitch WEnd Func _DllClose() DllClose($hPsAPI) DllClose($hKernel) EndFunc Func WM_GETMINMAXINFO($hWnd, $msg, $wParam, $lParam) Local $Struct = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) If $hWnd = $Form1 Then DllStructSetData($Struct, 7, 598) DllStructSetData($Struct, 8, 511) EndIf EndFunc Func Reload() GUICtrlSetState($ChkB1, $GUI_DISABLE) GUICtrlSetState($ChkB2, $GUI_DISABLE) GUICtrlSetState($Butt1, $GUI_DISABLE) GUICtrlSetState($Radi0, $GUI_DISABLE) GUICtrlSetState($Radi1, $GUI_DISABLE) GUICtrlSetState($Radi2, $GUI_DISABLE) GUICtrlSetState($Edit1, $GUI_HIDE) GUICtrlSetState($List1, $GUI_HIDE) GUICtrlSetState($Edit2, $GUI_HIDE) GUICtrlSetState($Prgs1, $GUI_SHOW) GUICtrlSetState($Button_About, $GUI_DISABLE) GUICtrlSetData($Edit1, '') GUICtrlSetData($List1, '') GUICtrlSetData($Edit2, '') Local $aProcesses = ProcessList() If @error Or IsArray($aProcesses) <> 1 Or UBound($aProcesses, 0) <> 2 Or $aProcesses[0][0] <= 0 Then MsgBox(48, 'Error', 'Error in ProcessList()') Return SetError(1, 0, 0) EndIf Local $aWindows = WinList() If @error Or IsArray($aWindows) <> 1 Or UBound($aWindows, 0) <> 2 Or $aWindows[0][0] <= 0 Then MsgBox(48, 'Error', 'Error in WinList()') Return SetError(1, 0, 0) EndIf If BitAND(GUICtrlRead($Radi0), $GUI_CHECKED) = $GUI_CHECKED Then $Sorted = 0 ElseIf BitAND(GUICtrlRead($Radi1), $GUI_CHECKED) = $GUI_CHECKED Then SortByPID($aProcesses) $Sorted = 1 ElseIf BitAND(GUICtrlRead($Radi2), $GUI_CHECKED) = $GUI_CHECKED Then SortByPName($aProcesses) $Sorted = 2 EndIf Local $percent = 100/$aProcesses[0][0], $progress = 0 For $i = 1 To $aProcesses[0][0] Step +1 GUICtrlSetData($Edit1, 'Process ID: ' & $aProcesses[$i][1] & @CRLF & _ 'Process Name: ' & $aProcesses[$i][0] & @CRLF & _ 'Process Path: ' & _ProcessGetPath($aProcesses[$i][1]) & @CRLF, 1) If $Sorted = 2 Then GUICtrlSetData($List1, $aProcesses[$i][0] & ' - ' & $aProcesses[$i][1] & '|') Else GUICtrlSetData($List1, $aProcesses[$i][1] & ' - ' & $aProcesses[$i][0] & '|') EndIf For $i2 = 1 To $aWindows[0][0] Step +1 If WinGetProcess($aWindows[$i2][1]) = $aProcesses[$i][1] Then GUICtrlSetData($Edit1, 'Window Name: ' & $aWindows[$i2][0] & @CRLF & _ 'Window Handle: ' & $aWindows[$i2][1] & @CRLF, 1) EndIf Next GUICtrlSetData($Edit1, @CRLF, 1) $progress += $percent GUICtrlSetData($Prgs1, $progress) Next GUICtrlSetState($Prgs1, $GUI_HIDE) GUICtrlSetData($Prgs1, 0) If BitAND(GUICtrlRead($ChkB1), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($Edit1, $GUI_SHOW) Else GUICtrlSetState($List1, $GUI_SHOW) GUICtrlSetState($Edit2, $GUI_SHOW) EndIf GUICtrlSetState($Button_About, $GUI_ENABLE) GUICtrlSetState($Radi0, $GUI_ENABLE) GUICtrlSetState($Radi1, $GUI_ENABLE) GUICtrlSetState($Radi2, $GUI_ENABLE) GUICtrlSetState($ChkB1, $GUI_ENABLE) GUICtrlSetState($ChkB2, $GUI_ENABLE) GUICtrlSetState($Butt1, $GUI_ENABLE) EndFunc Func GetText() Local $Title = GUICtrlRead($List1), $PID, $Text If $Sorted = 2 Then $PID = StringTrimLeft($Title, StringInStr($Title, ' - ')+2) Else $PID = StringLeft($Title, StringInStr($Title, ' - ')-1) EndIf $Text = GUICtrlRead($Edit1) $Text = StringMid($Text, StringInStr($Text, 'Process ID: ' & $PID & @CRLF)) $Text = StringLeft($Text, StringInStr($Text, @CRLF & @CRLF, 0, 1)-1) GUICtrlSetData($Edit2, $Text) EndFunc Func _ProcessGetPath($hPID) Local $sPath = DllStructCreate('char[1000]') Local $hProcess = DllCall($hKernel, 'int', 'OpenProcess', 'dword', 0x0400 + 0x0010, 'int', 0, 'dword', $hPID) DllCall($hPsAPI, 'long', 'GetModuleFileNameEx', 'long', $hProcess[0], 'int', 0, 'ptr', DllStructGetPtr($sPath), 'long', DllStructGetSize($sPath)) DllCall($hKernel, 'int', 'CloseHandle', 'hwnd', $hProcess[0]) Local $ret = DllStructGetData($sPath, 1) If BitAND(GUICtrlRead($ChkB2), $GUI_CHECKED) = $GUI_CHECKED Then Local $c, $Drives = DriveGetDrive('ALL') For $i = 1 To $Drives[0] Step +1 If Not StringInStr($Drives[$i], ':') Then ContinueLoop $c = StringInStr($ret, $Drives[$i]) If $c = 1 Then ExitLoop ElseIf $c > 1 Then $ret = StringTrimLeft($ret, $c-1) ExitLoop EndIf Next If StringInStr($ret, '\SystemRoot\') = 1 Then $ret = StringReplace($ret, '\SystemRoot', @WindowsDir, 1) EndIf Return $ret EndFunc Func SortByPID(ByRef $aArray) Local $max, $var, $id For $i = 1 To $aArray[0][0] Step +1 $max = -1 For $i2 = $i To $aArray[0][0] Step +1 If $aArray[$i2][1] < $max Or $max = -1 Then $max = $aArray[$i2][1] $id = $i2 EndIf Next For $i2 = 0 To 1 Step +1 $var = $aArray[$i][$i2] $aArray[$i][$i2] = $aArray[$id][$i2] $aArray[$id][$i2] = $var Next Next EndFunc Func SortByPName(ByRef $aArray) If IsArray($aArray) <> 1 Or UBound($aArray, 0) <> 2 Then Return SetError(1) Local $vVar, $chr = -1, $max, $asc, $id For $i = 0 To $aArray[0][0] Step +1 If StringLen($aArray[$i][0]) > $chr Or $chr = -1 Then $chr = StringLen($aArray[$i][0]) Next For $chr = $chr To 1 Step -1 For $num = 1 To $aArray[0][0] Step +1 $max = -1 For $i = $num To $aArray[0][0] Step +1 $asc = Asc(StringMid($aArray[$i][0], $chr, 1)) If $asc < $max Or $max = -1 Then $max = $asc $id = $i EndIf Next For $i = 0 To 1 $vVar = $aArray[$id][$i] For $ii = $id-1 To $num Step -1 $aArray[$ii+1][$i] = $aArray[$ii][$i] Next $aArray[$num][$i] = $vVar Next Next Next EndFunc ;================================================================================== ; Function: SetPrivilege( $privilege, $bEnable ) ; Description: Enables (or disables) the $privilege on the current process ; (Probably) requires administrator privileges to run ; ; Author(s): Larry (from autoitscript.com's Forum) ; Notes(s): ; http://www.autoitscript.com/forum/index.php?s=&showtopic=31248&view=findpost&p=223999 ;================================================================================== Func SetPrivilege( $privilege, $bEnable ) Const $MY_TOKEN_ADJUST_PRIVILEGES = 0x0020 Const $MY_TOKEN_QUERY = 0x0008 Const $MY_SE_PRIVILEGE_ENABLED = 0x0002 Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv Local $LUID, $TOKEN_PRIVILEGES, $NEWTOKEN_PRIVILEGES, $ret, $f ;MustDeclareVars, me $nTokens = 1 $LUID = DLLStructCreate("dword;int") If IsArray($privilege) Then $nTokens = UBound($privilege) $TOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]") $NEWTOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]") $hCurrProcess = DLLCall("kernel32.dll","hwnd","GetCurrentProcess") $SP_auxret = DLLCall("advapi32.dll","int","OpenProcessToken","hwnd",$hCurrProcess[0], _ "int",BitOR($MY_TOKEN_ADJUST_PRIVILEGES,$MY_TOKEN_QUERY),"int*",0) If $SP_auxret[0] Then $hToken = $SP_auxret[3] DLLStructSetData($TOKEN_PRIVILEGES,1,1) $nTokenIndex = 1 While $nTokenIndex <= $nTokens If IsArray($privilege) Then $priv = $privilege[$nTokenIndex-1] Else $priv = $privilege EndIf $ret = DLLCall("advapi32.dll","int","LookupPrivilegeValue","str","","str",$priv, _ "ptr",DLLStructGetPtr($LUID)) If $ret[0] Then If $bEnable Then DLLStructSetData($TOKEN_PRIVILEGES,2,$MY_SE_PRIVILEGE_ENABLED,(3 * $nTokenIndex)) Else DLLStructSetData($TOKEN_PRIVILEGES,2,0,(3 * $nTokenIndex)) EndIf DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,1),(3 * ($nTokenIndex-1)) + 1) DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,2),(3 * ($nTokenIndex-1)) + 2) DLLStructSetData($LUID,1,0) DLLStructSetData($LUID,2,0) EndIf $nTokenIndex += 1 WEnd $ret = DLLCall("advapi32.dll","int","AdjustTokenPrivileges","hwnd",$hToken,"int",0, _ "ptr",DllStructGetPtr($TOKEN_PRIVILEGES),"int",DllStructGetSize($NEWTOKEN_PRIVILEGES), _ "ptr",DllStructGetPtr($NEWTOKEN_PRIVILEGES),"int*",0) $f = DLLCall("kernel32.dll","int","GetLastError") EndIf $NEWTOKEN_PRIVILEGES=0 $TOKEN_PRIVILEGES=0 $LUID=0 If $SP_auxret[0] = 0 Then Return 0 $SP_auxret = DLLCall("kernel32.dll","int","CloseHandle","hwnd",$hToken) If Not $ret[0] And Not $SP_auxret[0] Then Return 0 return $ret[0] EndFunc Func About() If Not IsDeclared('Form_About') Then Global $Form_About = GUICreate('About...', 275, 230, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), -1, $Form1) Global $A_Label_Name = GUICtrlCreateLabel('Processes and windows monitor', 10, 10, 255, 15) GUICtrlSetFont($A_Label_Name, 12, 600) Global $A_Label_Version = GUICtrlCreateLabel('Version: 0.99', 10, 30, 85, 15) GUICtrlSetFont($A_Label_Version, 11, 450) Global $A_Label_Author = GUICtrlCreateLabel('Author: dwerf', 10, 50, 70, 15) GUICtrlSetFont($A_Label_Author, 8.5, 450) Global $A_Label_Thanks = GUICtrlCreateLabel('Thanks to:' & @CRLF & 'Yashied' & @TAB & @TAB & 'kzru_hunter' & @CRLF & 'Larry' & @TAB & @TAB & 'BugFix' & @CRLF & 'Anton' & @TAB & @TAB & 'AspirinJunkie', 10, 80, 175, 65) GUICtrlSetFont($A_Label_Thanks, 10, 450) Global $A_Label_RU = GUICtrlCreateLabel('http://autoitscript.ru/', 10, 165, 100, 17) GUICtrlSetFont($A_Label_RU, 8.5, 400, 0) GUICtrlSetColor($A_Label_RU, 0x0000FF) GUICtrlSetCursor($A_Label_RU, 0) Global $A_Label_DE = GUICtrlCreateLabel('http://autoit.de/', 10, 185, 80, 17) GUICtrlSetFont($A_Label_DE, 8.5, 400, 0) GUICtrlSetColor($A_Label_DE, 0x0000FF) GUICtrlSetCursor($A_Label_DE, 0) Global $A_Label_COM = GUICtrlCreateLabel('http://autoitscript.com/', 10, 205, 110, 17) GUICtrlSetFont($A_Label_COM, 8.5, 400, 0) GUICtrlSetColor($A_Label_COM, 0x0000FF) GUICtrlSetCursor($A_Label_COM, 0) Global $A_Button_Close = GUICtrlCreateButton('OK', 185, 190, 80, 30) EndIf Local $L_Hover = 0, $gci GUISetState(@SW_SHOW, $Form_About) GUISetState(@SW_DISABLE, $Form1) While 1 $gci = GUIGetCursorInfo($Form_About) If Not @error Then Switch $gci[4] Case $A_Label_RU If Not $L_Hover = 1 Then GUICtrlSetFont($A_Label_RU, 8.5, 400, 4) GUICtrlSetFont($A_Label_DE, 8.5, 400, 0) GUICtrlSetFont($A_Label_COM, 8.5, 400, 0) $L_Hover = 1 EndIf Case $A_Label_DE If Not $L_Hover = 2 Then GUICtrlSetFont($A_Label_RU, 8.5, 400, 0) GUICtrlSetFont($A_Label_DE, 8.5, 400, 4) GUICtrlSetFont($A_Label_COM, 8.5, 400, 0) $L_Hover = 2 EndIf Case $A_Label_COM If Not $L_Hover = 3 Then GUICtrlSetFont($A_Label_RU, 8.5, 400, 0) GUICtrlSetFont($A_Label_DE, 8.5, 400, 0) GUICtrlSetFont($A_Label_COM, 8.5, 400, 4) $L_Hover = 3 EndIf Case Else If Not $L_Hover = 0 Then GUICtrlSetFont($A_Label_RU, 8.5, 400, 0) GUICtrlSetFont($A_Label_DE, 8.5, 400, 0) GUICtrlSetFont($A_Label_COM, 8.5, 400, 0) $L_Hover = 0 EndIf EndSwitch EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $A_Button_Close ExitLoop Case $A_Label_RU ShellExecute('http://autoitscript.ru/') Case $A_Label_DE ShellExecute('http://autoit.de/') Case $A_Label_COM ShellExecute('http://autoitscript.com/') EndSwitch WEnd GUISetState(@SW_ENABLE, $Form1) GUISetState(@SW_HIDE, $Form_About) EndFunc
    1 point
×
×
  • Create New...