Leaderboard
Popular Content
Showing content with the highest reputation on 07/25/2017 in all areas
-
Well an Implementation of IPortableDeviceManager Interface to get all Portable Device conected to our pc. #include <Array.au3> #include <WinAPICom.au3> Opt("MustDeclareVars", 1) Global Const $sCLSID_PortableDeviceManager = "{0af10cec-2ecd-4b92-9581-34f6ae0637f3}" Global Const $sIID_IPortableDeviceManager = "{a1567595-4c2f-4574-a6fa-ecef917b9a40}" Global Const $sTagIPortableDeviceManager = "GetDevices hresult(ptr;dword*); RefreshDeviceList hresult(); " & _ "GetDeviceFriendlyName hresult(wstr;wstr;dword*); GetDeviceDescription hresult(wstr;wstr;dword*); " & _ "GetDeviceManufacturer hresult(wstr;wstr;dword*); GetDeviceManufacturer hresult(wstr;wstr;ptr;dword*dword*); " & _ "GetPrivateDevices hresult(ptr;dword*)" Global Enum $eDevID, $eDevName, $eDevManufacturer, $eDevDescription Local $aPnPDevices = GetPortableDevices() If IsArray($aPnPDevices) Then _ArrayDisplay($aPnPDevices) ;~ Success: Return 0 ;~ Failure: Return 2DArray [n][4] |;[n][0]$eDevID, [n][1]$eDevName, [n][2]$eDevManufacturer,[n][3] $eDevDescription Func GetPortableDevices() Local $aDevicesInfo[0][0] ;[n][0]$eDevID, [n][1]$eDevName, [n][2]$eDevManufacturer,[n][3] $eDevDescription Local $oPortableDeviceManager = 0 Local $SizeofArray = 0 Local $hr = 0x80004005 ;E_Fail Just to Initialized <0 Local $taPnPDeviceIDs = 0 Local $tName = 0 $oPortableDeviceManager = ObjCreateInterface($sCLSID_PortableDeviceManager, $sIID_IPortableDeviceManager, $sTagIPortableDeviceManager) If Not IsObj($oPortableDeviceManager) Then Return 0 If FAILED($oPortableDeviceManager.GetDevices(Null, $SizeofArray)) Then Return 0 If $SizeofArray < 1 Then Return 0 $taPnPDeviceIDs = DllStructCreate("ptr[" & $SizeofArray & "]") If FAILED($oPortableDeviceManager.GetDevices(DllStructGetPtr($taPnPDeviceIDs), $SizeofArray)) Then Return 0 ReDim $aDevicesInfo[$SizeofArray][4] For $i = 0 To $SizeofArray - 1 $tName = DllStructCreate("wchar[512]", DllStructGetData($taPnPDeviceIDs, 1, $i + 1)) $aDevicesInfo[$i][$eDevID] = DllStructGetData($tName, 1) $aDevicesInfo[$i][$eDevName] = _GetFriendlyName($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID]) $aDevicesInfo[$i][$eDevManufacturer] = _GetDeviceManufacturer($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID]) $aDevicesInfo[$i][$eDevDescription] = _GetDeviceDescription($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID]) $tName = 0 _WinAPI_CoTaskMemFree(DllStructGetData($taPnPDeviceIDs, 1, $i + 1)) Next Return $aDevicesInfo EndFunc ;==>GetPortableDevices Func _GetDeviceManufacturer($oInterface, $PnPDeviceID) Local $sString = "" $oInterface.GetDeviceManufacturer($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetDeviceManufacturer Func _GetDeviceDescription($oInterface, $PnPDeviceID) Local $sString = "" Local Const $Size = 128 $oInterface.GetDeviceDescription($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetDeviceDescription Func _GetFriendlyName($oInterface, $PnPDeviceID) Local $sString = "" Local Const $Size = 128 $oInterface.GetDeviceFriendlyName($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetFriendlyName Func _GetProperty($oInterface, $PnPDeviceID) Local $sString = "" Local Const $Size = 128 $oInterface.GetDeviceFriendlyName($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetProperty Func FAILED($hr) Return ($hr < 0) EndFunc ;==>FAILED Saludos1 point
-
How dol i splitstring a string into a 2d array ?
asiawatcher reacted to Danp2 for a topic
Here a prior thread on the subject1 point -
Correct. With $aIcons[3] I would define an array with 3 elements. As counting in arrays starts with 0 I would need to use an index from 0 to 2 to access all elements of the array. As the above definition does not contain a counter the array's size is defind by the number of elemens in the following list (["small_plus", "yellow" ...]). If you need to add another icon simply extend the list. Correct. You do not need to define all variables (AutoIt does it for you when you access a varaible for the first time). But defining the variables leads to cleaner code. $i is the variable I (and most other coders) use for the index variable. This variable defines which row of the array to access. As I mentioned above the index of an array starts with 0 and ends with the number of rows minus 1. UBound($aIcons) by default returns the number of rows in an array. To get the highest index I have to subtract 1. The next statement then accesses row by row and creates the output lin. Imagine a one-dimensional (1D) array as a list of values each one in its own row. Imagine a two-dimensional (2D) array as an Excel worksheet with rows and columns. Excel uses a column/row notation (e.g. B4 - column B (= column 2) row 4). An array uses a row/column notation. So in an outer loop you specify which row to process (as we did above) and in an inner loop you specify which column of the current row to process. Hope I could shed some light on the subject1 point
-
How dol i splitstring a string into a 2d array ?
asiawatcher reacted to water for a topic
Always process two rows at once: For $i = 1 To $aDays[0] Step 2 ; Loop through the array returned by StringSplit to display the individual values. MsgBox($MB_SYSTEMMODAL, "", $aDays[$i] & " " & $aDays[$i + 1]) Next1 point -
Need advice on writing better codes using array or ini.
LisHawj reacted to JLogan3o13 for a topic
@LisHawj for future reference, if you stick to the forum for any follow up questions, you will have many more eyes on the issue.1 point -
So you post a oneliner funcky question in a 3 years old thread and expect .....what exactly? Welcome by the way Jos1 point
-
how to detect if an other copy from the same script if runing
nacerbaaziz reacted to Jos for a topic
One other question: You only perform UDF check(@ScriptName) one time, but don't you want to do that when you press buttons in the GUI? Jos1 point -
how to detect if an other copy from the same script if runing
nacerbaaziz reacted to Jos for a topic
Did you test with the compiled version as I expect that is the only way it will work? Jos1 point -
For the current user: $vResult = _AD_GetObjectAttribute(@UserName, "mail")1 point
-
There is a very good tutorial about arrays in the wiki. Worth reading it! As a start: #include <File.au3> ;Read the program.txt file into an array.# Local $aIcons[] = ["small_plus", "yellow", "green", "blue", "red", "plus", "widget", "time", "purple", "elrond", "orange", "avocado", "fruit", "small_plus", "Add_more"] Global $Array_File = "C:\temp\Array.txt", $Icon_dir = "C:\temp" If Not FileExists($Array_File) Then _FileCreate($Array_File) For $i = 0 To UBound($aIcons) - 1 FileWrite($Array_File, "Empty,Empty," & $Icon_dir & "\" & $aIcons[$i] & ".ico" & @CRLF) Next Else Sleep(10) EndIf1 point
-
Something like this? Func check($exefile) Local $OwnPID = @AutoItPID Local $aProcessList = ProcessList($exefile) If @error Then Return -1 For $i = 1 To $aProcessList[0][0] If Not $aProcessList[$i][1] = $OwnPID Then ProcessClose($aProcessList[$i][1]) EndIf Next Return 1 EndFunc ;==>check Jos1 point
-
how to detect if an other copy from the same script if runing
nacerbaaziz reacted to Danp2 for a topic
You should stop apologizing about your English and instead apologize for your lack of effort in solving the issue for yourself. You've been given pointers on how to do it. Now how about you show some code showing where you've actually tried to solve it yourself instead of repeatedly asking for someone else to write the code for you.1 point -
Almost: multiline cells use LF alone, not CRLF. $aContent[$i][$j] = StringRegExpReplace($aContent[$i][$j], "(?<!\r)\n", "#") I replaced LFs by # to display what was replaced, but should be a whitespace or empty string or anything else.1 point
-
[Solved] Excel to Text File with delimiter added
KickStarter15 reacted to water for a topic
I would insert the StringReplace before creating the output file: #include <Excel.au3> Global $sLine = "" Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx") Global $aContent = _Excel_RangeRead($oWorkbook) _Arraydisplay($aContent) For $i = 0 To UBound($aContent, 1) - 1 $sLine = "" For $j = 0 To UBound($aContent, 2) - 1 $aContent[$i][$j] = StringReplace($aContent[$i][$j], @CRLF, "") If $j = 0 Then $sLine = $aContent[$i][$j] Else $sLine = $sLine & "|" & $aContent[$i][$j] EndIf Next ConsoleWrite($sLine & @CRLF) Next1 point -
Whoops! Piotr12... My bad... I forgot that ConsoleWrite() is only good with compiled AutoIt scripts. This will work when run from the command line with AutoIt.exe: #include <WinAPI.au3> _WinAPI_AttachConsole() $hConsole = _WinAPI_GetStdHandle(1) _WinAPI_WriteConsole($hConsole, "Hello Piotr12" & @CRLF)1 point
-
Hello here is a example using GET and POST methods. ConsoleWrite(">GET METHOD USING IMAGE URL<" & @CRLF) _GetMethodTest() ConsoleWrite(">POST METHOD UPLOADING LOCAL IMAGE<" & @CRLF) _PostMethodTest() Func _PostMethodTest() Local Const $sAPIKey = '8f1e0a750088957' Local $sBoundary = "--------Boundary" Local $sHeaders = "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF Local $sData = '' Local $sFileName="OCR.png" Local $sFilePath=@ScriptDir & "\" & $sFileName Local $hFile=FileOpen($sFilePath,16);16=$FO_BINARY Local $sFileData=FileRead($hFile) FileClose($hFile) $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="file"; filename="' & $sFileName & '"' & @CRLF $sData &= 'Content-Type: application/octet-stream' & @CRLF & @CRLF $sData &= BinaryToString($sFileData,0) & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="language"' & @CRLF & @CRLF $sData &="eng" & @CRLF $sData &=$sBoundary & "--" Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://api.ocr.space/Parse/Image", False) $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $sBoundary) $oHTTP.SetRequestHeader("apikey", $sAPIKey) $oHTTP.Send(StringToBinary($sData,1)) Local $sReceived = $oHTTP.ResponseText ConsoleWrite($sReceived & @CRLF) EndFunc ;==>_PostMethodTest Func _GetMethodTest() Local Const $sAPIKey = '8f1e0a750088957' Local $sReturn = InetRead('https://api.ocr.space/parse/imageurl?apikey=' & $sAPIKey & '&url=http://i.imgur.com/fwxooMv.png', 1) ;1=$INET_FORCERELOAD $sReturn = BinaryToString($sReturn) ConsoleWrite($sReturn & @CRLF) EndFunc ;==>_GetMethodTest Consider to use WinHTTP UDF Instead winhttp COM object. Saludos1 point
-
how to basic print on gui?
Skysnake reacted to InunoTaishou for a topic
Could use an edit and append the actions instead of just updating the label. Will give you the history of everything that's happened (per your screen shot) Global $edtEdit = GUICtrlCreateEdit("", 10, 10, 380, 280) ; ... ; ... ; ... ; ... ; Mouse click happens GUICtrlSetData($edtEdit, GUICtrlRead($edtEdit) & "Mouse clicked" & @CRLF)1 point -
Maybe this helps. The wiki provides an UDF for Sharepoint:1 point
-
kurtykurtyboy, If you do decide to go with GUIRegisterMsg, you can always use a UDF function to register (or not) the message(s) you need and provide separate individual handler(s) which the user can add to his own handler if it already exists. Take a look at some of my UDFs (links hidden in my sig) to see how I did it - GUIListViewEx and ChooseFileFolder are good examples. I still hope that one day we will get the ability to chain messages in core code, but I am not holding my breath. I have tried several times to introduce a standard UDF to do it but the resistance from others was too strong. M231 point
-
Automating Windows Explorer
davidacrozier reacted to LarsJ for a topic
I do everything manually, based on C/C++ header files. But because I've added more examples dealing with Shell Interfaces, I've probably only created two new interfaces for this example: IWebBrowser and IWebBrowserApp. The rest of the interfaces are just copied. You find the interface descriptions in IncludesShellInterfaces.au3. IWebBrowser (needed because IWebBrowserApp inherits from IWebBrowser) and IWebBrowserApp together comprise almost 50 methods. But because I only use one method out of these 50, namely get_HWND in IWebBrowserApp, I have only added parameters for this method. The most time consuming task is to add parameters. All in all, I probably only spend five minutes to add the two interface descriptions. So it's not that difficult to create interface descriptions, as it might first appear. Thanks to all for comments and likes.1 point