Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/19/2021 in all areas

  1. HiAaron, You shouldn't use at same time $WS_CHILD and $WS_EX_MDICHILD Have you tried it like this ? $hChild = GUICreate("Child", 100, 100, -1,-1, $WS_CHILD , -1, $hParent)
    1 point
  2. Do you prefer this one ? #include <Constants.au3> $sText = _ "User: SomeUser" & @CRLF & _ "Login-name: SomeLoginName" & @CRLF & _ "NTSecurity: YES" & @CRLF & _ "Domain: SomeDomain" & @CRLF & _ "Timeout: 00:00:00" & @CRLF & _ "Anything: Before" & @CRLF & _ "Member: MemberOfFirstGroup" & @CRLF & _ "Member: MemberOfSecondGroup" & @CRLF & _ "Member: MemberOfThirdGroup" & @CRLF & _ "Anything: After" MsgBox ($MB_SYSTEMMODAL, "", StringRegExpReplace($sText, "(?|User|Login-name|NTSecurity|Member):\s(.*)|.+\v*", "$1"))
    1 point
  3. This ? #include <Constants.au3> $sText = _ "User: SomeUser" & @CRLF & _ "Login-name: SomeLoginName" & @CRLF & _ "NTSecurity: YES" & @CRLF & _ "Domain: SomeDomain" & @CRLF & _ "Timeout: 00:00:00" & @CRLF & _ "Member: MemberOfFirstGroup" & @CRLF & _ "Member: MemberOfSecondGroup" & @CRLF & _ "Member: MemberOfThirdGroup" MsgBox ($MB_SYSTEMMODAL, "", StringRegExpReplace($sText, "User:\s|Login-name:\s|NTSecurity:\s|Domain:\s.*\v+|Timeout.*\v+|Member:\s", ""))
    1 point
  4. oh my god. Alzheimer is coming ... SORRY, I'll check on this. Really can't remember
    1 point
  5. Not really as there is also a #pragma option for this these days: #pragma compile(ExecLevel, requireAdministrator) The difference is when defined in the Manifest, it will be handed by the Windows OS were #RequireAdmin is handled by AutoIt3 and the script is re-shelled when not at the required level. Jos
    1 point
  6. #include <MsgBoxConstants.au3> Global $Sentence = "Monday Tuesday Wednesday Thursday Friday" Global $NewSentence = StringLeft($Sentence, StringInStr($Sentence, " ", 0, -1)-1) MsgBox($MB_SYSTEMMODAL, "", '>' & $NewSentence & '<') ;Result should be "Monday Tuesday Wednesday Thursday" ...and that's why I posted. You showed initiative. ( and SciTE was already open ) It takes time. Home > Scripting and Development > Developer General Discussion <== This is the wrong place for this type of question
    1 point
  7. ...I do not know, however you could use a running powershell instance started with redirected I/O streams and use it to execute multiple commands without having to rerun it with each new command. Since it is necessary to be able to identify the beginning and the end of the output stream of the various commands, I thought of "injecting" two "flags", one for the beginning and one for the end, for each command executed, so as to be able to extract only the body of the output of the different commands. This little script perhaps clarifies it better than many words. I hope it will be useful to you #include <constants.au3> #include <string.au3> #RequireAdmin ; Use RunAs if you want use a fixed username/password within the script: ; Global $hPowerShellPID = RunAs("UserName", "Domain", "Password", "", "powershell.exe", '', @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_MERGED)) ; or use #RequireAdmin and a simple Run Statement to enter Admin credentials (if needed) at runtime ; Here we start a "permanent" powershell prompt with redirected streams Global $hPowerShellPID = Run("powershell.exe", '', @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_MERGED)) ; this little loop is to wait for the "welcome" message from powershell ; just a way to be sure that the powershell is running and "streaming" Do StdoutRead($hPowerShellPID) Until @extended ; out stream started ; example: ; Here we "execute a command via the Powershell that is running in background... ; ...and we get back to resulting output Local $Out = _Run_Cmdlet("Get-ItemPropertyValue 'Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' -Name 'EnableLUA'", $hPowerShellPID) ConsoleWrite($Out) ; here another command ConsoleWrite(_Run_Cmdlet("dir c:\", $hPowerShellPID)) ; .... and so on ... ; this function execute the passed powershell command and returns the resulting output Func _Run_Cmdlet($sCmd, ByRef $hPS) Local $sStdOut = '' ; we insert a start and an end message in order to identify the "body" of the result of the command executed $sCmd = 'write-host "->StartOfStream<-"; ' & $sCmd & '; write-host "->EndOfStream<-"' & @CRLF StdinWrite($hPS, $sCmd) Do Sleep(250) $sStdOut &= StdoutRead($hPS) ; the presence of the known end message signals the end of the execution Until StringInStr($sStdOut, "->EndOfStream<-" & @LF) ; return only the body of the outpu of the passed command Return _StringBetween($sStdOut, "->StartOfStream<-" & @LF, "->EndOfStream<-" & @LF)[0] EndFunc ;==>_Run_Cmdlet
    1 point
  8. It clears only the graphic handle ($hGraphic) as it will be used to draw each graph bar within the loop in function UpdateGraph(). Sure, it is possible but it will consume more memory. As the draw function is called once per second the CPU usage of each calculation for each graph bar is negligible. Here the updated version which uses HSL for calculation of the gradient from green over yellow to red: #include <Date.au3> #include <WindowsConstants.au3> #include <GuiConstantsEX.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <GDIPlus.au3> Global $o_Autoit_Object_Error_Handler = ObjEvent("AutoIt.Error", "_Autoit_Object_Error_Function") ; Initialize a COM error handler Global $__g_hGDIPDll Global $graph[21], $bars[21] Global $timer, $timeout = 1000 Global $hFlag = 0 _GDIPlus_Startup() Global $hBrush, $hGraphic, $hImage, $hTexture, $width=5, $height=100 $hImage = _GDIPlus_BitmapCreateFromScan0($width, $height) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;create gradient from green over yellow to red using HSL values Global $aColors[Ceiling($height)] Local $iSteps = 120 / UBound($aColors), $i, $h For $h = 120 To 0 Step -$iSteps $aColors[$i] = 0xFF000000 + HSLToRGB((120 + $h) / 360, 1, 0.5) $i += 1 Next ;create one texture which will used to draw the CPU usage accordingly Global $hBmp = _GDIPlus_BitmapCreateFromScan0($width, $height), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp) $hBrush = _GDIPlus_BrushCreateSolid() For $i = 0 To UBound($aColors) - 1 _GDIPlus_BrushSetSolidColor($hBrush, $aColors[$i]) _GDIPlus_GraphicsFillRect($hGfx, 0, $i, $width, $height, $hBrush) Next $hTexture = _GDIPlus_TextureCreate($hBmp) _GDIPlus_ImageDispose($hBmp) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BrushDispose($hBrush) ;================================================== $main = GUICreate("CPU Graph", 125, 220, Default, Default, Default, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) For $i = 1 To 20 $bars[$i] = GUICtrlCreatePic("", 10 + ($i - 1) * 5, 10, 5, $height) Next $host = GUICtrlCreateInput("LocalHost", 10, 115, 100, 20, $ES_AUTOHSCROLL) $user = GUICtrlCreateInput("User", 10, 140, 100, 20, $ES_AUTOHSCROLL) GUICtrlSetFont(-1, 8, 400) $pass = GUICtrlCreateInput("Pass", 10, 165, 100, 20, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 8, 400) $start = GUICtrlCreateButton("Start", 10, 190, 100, 20, $BS_DEFPUSHBUTTON) GUISetState() ;<== Draw Main GUI ;== Main Processing Loop=================================== While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $start Then ConnectWMI() ;<== connect host If $hFlag = 1 Then ;<== If host is connected If TimerDiff($timer) > $timeout Then UpdateGraph() EndIf WEnd ;== Pre Exit Cleanup ====================================== _GDIPlus_BrushDispose($hTexture) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ;========================================================== Func ConnectWMI() ; Connect WMI ==> (Establishes a connection to the WMI data on the remote system) Global $hostname = GUICtrlRead($host) If Ping($hostname, 2000) = 0 Then Msgbox(0, "Error", "Unable to reach specified host") Return 0 EndIf Local $usr = GUICtrlRead($user) Local $pwd = GUICtrlRead($pass) Global $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") Global $objWMIService = $objSWbemLocator.ConnectServer($hostname, "\root\cimv2", $usr, $pwd, "", "", 128) ;next line for testing purposes on local machine ;~ Global $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\" & $hostname & "\root\cimv2") If @error Then Msgbox(0, "Error", "Unable to connect to the Host with the supplied credentials") Return 0 EndIf $hFlag = 1 UpdateGraph() EndFunc ;<== Connect WMI Func UpdateGraph(); Update Graph (sets data points, calls create bar to draw the graph) $usage = _Processor_Usage() For $i = 1 to 19 $graph[$i] = $graph[$i+1] Next $graph[20] = $usage For $i = 1 to 20 CreateBar($bars[$i], $graph[$i]) Next $timer = TimerInit() EndFunc ;<== Update Graph Func _Processor_Usage(); Processor Usage ==> WMI Script to pull CPU usage each cycle Dim $Col_Items = $objWMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor', 'WQL') Local $Obj_Item For $Obj_Item In $Col_Items Return $Obj_Item.PercentProcessorTime Next EndFunc ;<== Processor Usage Func HSLToRGB($h, $s, $l) If Not $s Then Return BitShift(0xFF * $l, -16) + BitShift(0xFF * $l, -8) + BitShift(0xFF * $l, 0) Local Const $q = $l < 0.5 ? $l * (1 + $s) : $l + $s - $l * $s Local Const $p = 2 * $l - $q Return BitShift(0xFF * HUEtoRGB($p, $q, $h - 0.33333333), -16) + BitShift(0xFF * HUEtoRGB($p, $q, $h), -8) + BitShift(0xFF * HUEtoRGB($p, $q, $h + 0.33333333), 0) EndFunc Func HUEtoRGB($p, $q, $t) If($t < 0) Then $t += 1 If($t > 1) Then $t -= 1 If($t < 0.16666666) Then Return $p + ($q - $p) * 6 * $t If($t < 0.5) Then Return $q If($t < 0.66666666) Then Return $p + ($q - $p) * (0.66666666 - $t) * 6 Return $p EndFunc ;==== GDI+ Functions ================================================= Func CreateBar($target, $value) _GDIPlus_GraphicsClear($hGraphic, 0xFF000000) _GDIPlus_GraphicsFillRect($hGraphic, 0, $height - $value, $width, $value, $hTexture) Local Const $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($target, 0x172, 0, $hBitmap)) _WinAPI_DeleteObject($hBitmap) EndFunc ;<==_CreateBar Func _Autoit_Object_Error_Function() ConsoleWrite("! We intercepted a COM Error !" & @CRLF & "=======================" & @CRLF & _ "err.description is: " & @TAB & $o_Autoit_Object_Error_Handler.description & @CRLF & _ "err.windescription:" & @TAB & $o_Autoit_Object_Error_Handler.windescription & @CRLF & _ "err.number is: " & @TAB & Hex($o_Autoit_Object_Error_Handler.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $o_Autoit_Object_Error_Handler.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $o_Autoit_Object_Error_Handler.scriptline & @CRLF & _ "err.source is: " & @TAB & $o_Autoit_Object_Error_Handler.source & @CRLF & _ "err.helpfile is: " & @TAB & $o_Autoit_Object_Error_Handler.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $o_Autoit_Object_Error_Handler.helpcontext & @CRLF & @CRLF) EndFunc ;==>_Autoit_Object_Error_Function
    1 point
  9. Jon

    Forum Information and FAQs

    User Groups and Rights New Members - New members with that joined the forum within the last day. While in this group there are certain restrictions on the number of posts/PMs that can be made. This is to reduce the impact of spammers. After 24 hours members of this group will be promoted the Members group. Members - Members older than one day but with less than 20 posts. Standard access to the forum. Active Members - Members with more than 20 posts have additional rights No advertsSlightly more generous attachment and PM limitsAccess to the Chat forumAbility to upload files to the Downloads section MVPs - Members who are judged by the community to be helpful, who write and share useful code, who help the development of AutoIt. These users have the same rights as normal members but get a team icon, a little more attachment and PM space, and access to the MVP Chat forum section. Moderators - The forum police. This is not a democracy and each of the mods has their own distinct personality. They have the rights to edit posts, delete posts, ban users, delete users, IP ban, etc. Let the poster beware. Developers - A small group of users with access to the AutoIt source code and who have contributed significantly to the internal development of AutoIt. Some of them are also Moderators. Post Count and Rankings Ranks based on increasing post count are as follows: SeekerWayfarerAdventurerProdigyPolymathUniversalistThese titles are auto-generated and have no relation to actual skill level. Once you reach 300 posts you can change the title to whatever you like.
    1 point
×
×
  • Create New...