Leaderboard
Popular Content
Showing content with the highest reputation on 02/15/2022 in all areas
-
@ados Why don't you get the information you want directly from WMI ! There is no need to go thru PS. You can then create the report you want easily using AutoIt. Example : #include <Constants.au3> #include <Array.au3> Opt("MustDeclareVars", True) ReadProduct("Windows Live Writer") Func ReadProduct($sProductName) Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Product WHERE Name = "' & $sProductName & '"') If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object") If Not $colItems.count Then Exit MsgBox(0, "", "Product not found") For $oItem In $colItems ConsoleWrite($oItem.Name & @CRLF) ConsoleWrite($oItem.InstallDate & @CRLF) ConsoleWrite($oItem.IdentifyingNumber & @CRLF) Next EndFunc ;==>ReadProduct1 point
-
Sort question in C++
jugador reacted to pixelsearch for a topic
Hi everybody Here are 2 working AutoIt scripts related to the C++ code of the preceding post : 1) SortAll.au3 : it's an include file with 1 function SortAll() which is called when a script needs a fast sorting. #include-once #include "AutoItConstants.au3" #include "MsgBoxConstants.au3" ;================================================================== Func SortAll(ByRef $aArray, $iSortCol = 0, $iType = 1, $iSense = 0) If $iSortCol = Default Then $iSortCol = 0 ; 1st column = 0 If $iType = Default Then $iType = 1 ; 0 = String sort, 1 = Numeric sort If $iSense = Default Then $iSense = 0 ; 0 = ascending, 1 = descending If Not IsArray($aArray) Then MsgBox($MB_TOPMOST, "Error : variable $aArray is not an Array", _ "Its type is : " & VarGetType($aArray)) Return SetError(1, 0, 0) EndIf Local $iDims = UBound($aArray, $UBOUND_DIMENSIONS) If $iDims < 1 Or $iDims > 2 Then MsgBox($MB_TOPMOST, "Error : Dimensions = " & $iDims, _ "Array is not 1D or 2D") Return SetError(2, 0, 0) EndIf Local $iRows = UBound($aArray, $UBOUND_ROWS) If $iRows < 2 Then MsgBox($MB_TOPMOST, "Nothing to sort", _ "Array doesn't have 2 rows") ; no matter 1D or 2D Return 1 ; success anyway EndIf Local $iCols = UBound($aArray, $UBOUND_COLUMNS) ; always 0 for 1D array. If $iDims = 2 Then If $iCols = 0 Then MsgBox($MB_TOPMOST, "Error", _ "2D Array got 0 columns") Return SetError(3, 0, 0) ElseIf $iSortCol < 0 Or $iSortCol > $iCols - 1 Then MsgBox($MB_TOPMOST, "Error : sort column " & $iSortCol, _ "Please choose between 0 and " & $iCols - 1) Return SetError(4, 0, 0) EndIf EndIf If $iType < 0 Or $iType > 1 Then MsgBox($MB_TOPMOST, "Unknown Type of sort " & $iType, _ "It should be : 0 = String sort, 1 = Numeric sort") Return SetError(5, 0, 0) EndIf If $iSense < 0 Or $iSense > 1 Then MsgBox($MB_TOPMOST, "Unknown Sense of sort " & $iSense, _ "It should be : 0 = Ascending, 1 = Descending") Return SetError(6, 0, 0) EndIf Local $hDLLSort = DllOpen("sortall.dll") ; as no path indicated, dll is searched first in path environment, then in script path. ; if path is indicated (@ScriptDir for example), then it's the contrary. If $hDLLSort = -1 Then MsgBox($MB_TOPMOST, "Error", _ "sortall.dll can't be opened") Return SetError(20, 0, 0) EndIf Local $tStruct2 = DllStructCreate("int[" & $iRows & "]") ; will be filled by dll If @error Then MsgBox($MB_TOPMOST, "DllStructCreate : error " & @error, _ "Check AutoIt help file for this error") DllClose($hDLLSort) Return SetError(21, 0, 0) EndIf Local $sData = "", $sDelim = Chr(1) ; don't change Chr(1), it's used in the dll too If $iDims = 1 Then ; 1D If $iType = 1 And StringLeft(StringStripWS($aArray[0], 1), 2) = "0x" Then ; $STR_STRIPLEADING = 1 For $i = 0 To $iRows - 1 $sData &= Number(StringStripWS($aArray[$i], 1)) & $sDelim ; $sDelim also at end of string (used by dll +++) Next Else For $i = 0 To $iRows - 1 $sData &= $aArray[$i] & $sDelim Next EndIf Else ; 2D If $iType = 1 And StringLeft(StringStripWS($aArray[0][$iSortCol], 1), 2) = "0x" Then For $i = 0 To $iRows - 1 $sData &= Number(StringStripWS($aArray[$i][$iSortCol], 1)) & $sDelim Next Else For $i = 0 To $iRows - 1 $sData &= $aArray[$i][$iSortCol] & $sDelim Next EndIf EndIf Local $aBackup = $aArray ; backup the array before the sort (extremely fast !) Local $aRet = DllCall($hDLLSort, "int:cdecl", "sortall", "str", $sData, "ptr", DllStructGetPtr($tStruct2), _ "str", $sDelim, "int", $iRows, "int", $iSense, "int", $iType) If @error Then MsgBox($MB_TOPMOST, "DllCall : error " & @error, _ "Check AutoIt help file for this error") DllClose($hDLLSort) Return SetError(22, 0, 0) EndIf If $aRet[0] <> 0 Then MsgBox($MB_TOPMOST, "sortall.dll : error " & $aRet[0], _ "Check C++ code in dll") DllClose($hDLLSort) Return SetError(23, 0, 0) EndIf Local $iIndex If $iDims = 1 Then ; 1D For $i = 0 To $iRows - 1 $iIndex = DllStructGetData($tStruct2, 1, $i + 1) ; row index before sorting ; If $i <> $iIndex Then ; test not really useful when original array is 1D $aArray[$i] = $aBackup[$iIndex] ; EndIf Next Else ; 2D For $i = 0 To $iRows - 1 $iIndex = DllStructGetData($tStruct2, 1, $i + 1) ; row index before sorting If $i <> $iIndex Then For $j = 0 To $iCols - 1 $aArray[$i][$j] = $aBackup[$iIndex][$j] Next EndIf Next EndIf DllClose($hDLLSort) Return 1 ; success EndFunc ;==>SortAll 2) Test.au3 : a test on a 1D array of 100.000 numeric elements (integers, floats or doubles) #include <Array.au3> #include <SortAll.au3> ; pixelsearch's sortall.dll Opt("MustDeclareVars", 1) Local $iRows = 100000, $aArray[$iRows] ConsoleWrite("$iRows = " & $iRows & @CRLF) ;~ GenerateArrayInt($aArray, $iRows) GenerateArrayDouble($aArray, $iRows) ;~ GenerateArrayFloat($aArray, $iRows) _ArrayDisplay($aArray, "UNsorted", Default, Default, Default, _ "Numbers*") ; * at end of header means numeric sort ;==================================== Local $hTimer = TimerInit() Local $iSortCol = 0 ; value not important when 1D Local $iRet = SortAll($aArray, $iSortCol, 1, 0) ; numeric sort, ascending If $iRet Then ; 1 = success, 0 = fail with @error > 0 ConsoleWrite("Generating sorted 1D array = " & Int(TimerDiff($htimer)) & " ms" & @crlf) _ArrayDisplay($aArray, "sorted (col " & $iSortCol & ")", Default, Default, Default, _ "Numbers*") ; * at end of header means numeric sort EndIf ;==================================== Func GenerateArrayInt(ByRef $aArray, $iRows) For $i = 0 To $iRows - 1 $aArray[$i] = Random(-1000000, +1000000, 1) Next EndFunc ;==>GenerateArrayInt ;==================================== Func GenerateArrayDouble(ByRef $aArray, $iRows) For $i = 0 To $iRows - 1 $aArray[$i] = Random(-1000000, +1000000) ; $aArray[$i] = Random(-1, 1) Next EndFunc ;==>GenerateArrayDouble ;==================================== Func GenerateArrayFloat(ByRef $aArray, $iRows) For $i = 0 To $iRows - 1 $aArray[$i] = Number("" & Random(-1000000, +1000000, 1) & "." & Random(0,99,1), 3) Next EndFunc ;==>GenerateArrayFloat Console : $iRows = 100000 Generating sorted 1D array = 3058 ms Timer to be divided by 5 (or more) if your computer is recent => less than 1s to rewrite a whole 1D sorted array of 100.000 elements, yes ! For readers who are interested and got a compiler, you should be able to compile the C++ code of the preceding post, then place the resulting dll (named "sortall.dll") in one of the folders of your PATH environment (or in the folder of the test file "test.au3") If the dll isn't found in one of these folders, then this error will appear when you run the test file : Personally, I placed the dll in my Windows folder (which isn't really recommended) and the include file... in AutoIt's include files folder, which isn't recommended either ! I'll probably change that soon. Good luck.1 point -
You can replace all strings within a document including Text Boxes using the following. Func _pmailwordreplacetext($wordfilepath, $snrarray) ; Create application object Local $oWord = _Word_Create(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Open document Local $oDoc = _Word_DocOpen($oWord, $wordfilepath) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _ "Error opening '"&$wordfilepath&"'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; ***************************************************************************** ; Replace operation ; ***************************************************************************** ;DEBUG!!! ;_ArrayDisplay($snrarray) For $i = 0 To UBound($snrarray) - 1 For $oStoryRange In $oDoc.StoryRanges _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1], Default, $oStoryRange) While 1 If IsObj($oStoryRange.NextStoryRange) Then $oStoryRange = $oStoryRange.NextStoryRange _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1], Default, $oStoryRange) Else ExitLoop EndIf WEnd Next Next ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Paragraph control character successfully replaced.") ; Save document _Word_DocSave($oDoc) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSave Example", _ "Error saving the Word document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSave Example", "Document successfully saved as '" & _ ; $oDoc.FullName & "'") _Word_DocClose($oDoc) _Word_Quit($oWord) EndFunc1 point
-
Send a hidden command/text to a cmd console/window
behdadsoft reacted to Cyber for a topic
You can create a .bat file? like this: cd Testfolder myApps.exe save in 12345.bat and: ShellExecute("12345.bat","","","",@SW_HIDE)1 point