RyukShini

Uploading files with AutoIT in Wordress

25 posts in this topic

Hello everyone!

I am trying to make a script that uploads files for me in wordpress(All I need to do is to manually choose which files to upload)
Here is my script so far:
 

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Upload()

Func Upload()
    
    $sPD = "log=username&pwd=mypassword&wp-submit=Log+ind&redirect_to=http%3A%2F%2Fmyurl.com%2Fwp-admin%2F&testcookie=1"
oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://myurl.com/wp-login.php " & $sUSR, False) ; Post url
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
$oHTTP.SetRequestHeader("Accept-Language", "en-US,en;q=0.5")
$oHTTP.SetRequestHeader("User-Agent", "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.52 YaBrowser/15.12.2490.3614 (beta) Yowser/2.5 Safari/537.36")
$oHTTP.SetRequestHeader("Referer", "http://myurl.com/wp-login.php?redirect_to=http%3A%2F%2Fmyurl.com%2Fwp-admin%2F&reauth=1")
$oHTTP.SetRequestHeader("Cookie", "wordpress_test_cookie=WP+Cookie+check")
$oHTTP.SetRequestHeader("Connection", "keep-alive")
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") ; Header data >


$oHTTP.Send($sPD)
$oHTTP.Open("GET", "http://myurl.com/wp-admin/media-new.php", False) ; Post url
$oHTTP.SetRequestHeader("Host", "myurl.com")
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0")
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
$oHTTP.SetRequestHeader("Accept-Language", "en-US,en;q=0.5")
$oHTTP.SetRequestHeader("Referer", "http://myurl.com/wp-admin/")
$oHTTP.Send()

Endfunc

The upload button = "Choose Files"

Example code from:

https://www.autoitscript.com/autoit3/docs/functions/FileOpenDialog.htm

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
    Local Const $sMessage = "Select a single file of any type."

    ; Display an open dialog to select a file.
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)

        ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)

        ; Display the selected file.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)
    EndIf
EndFunc   ;==>Example

The HTML:
 

<p class="drag-drop-buttons"><input style="position: relative; z-index: 1;" id="plupload-browse-button" value="Choose Files" class="button" type="button"></p>

Some header info in the HTTP request:
 

POST http://myurl.com/wp-admin/async-upload.php HTTP/1.1
Host: myurl.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://myurl.com/wp-admin/media-new.php
Content-Length: 4555551
Content-Type: multipart/form-data; boundary=---------------------------12345678910
Cookie: LONG COOKIE HERE!
DNT: 1
Connection: keep-alive

-----------------------------102062144610664
Content-Disposition: form-data; name="name"

hdfhfg.jpg
-----------------------------102062144610664
Content-Disposition: form-data; name="post_id"

0
-----------------------------102062144610664
Content-Disposition: form-data; name="_wpnonce"

123456
-----------------------------102062144610664
Content-Disposition: form-data; name="type"


-----------------------------102062144610664
Content-Disposition: form-data; name="tab"


-----------------------------102062144610664
Content-Disposition: form-data; name="short"

1
-----------------------------102062144610664
Content-Disposition: form-data; name="async-upload"; filename="hdfhfg.jpg"
Content-Type: image/jpeg

This wouldn't be much of a problem if I just had some simple post data, but this makes my head spin....

Thanks in advance Masters!

(I could probably easily do this with IE, but I'd rather not use IE, I am not a big fan of it)
 

Share this post


Link to post
Share on other sites

@RyukShini you posted what you want to do, and where you pulled your code from, but I see nothing regarding what is not working for you. Are you getting an error? Are the files just not uploading? How about some actual detail rather than having us guess ;)

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
3 hours ago, JLogan3o13 said:

@RyukShini you posted what you want to do, and where you pulled your code from, but I see nothing regarding what is not working for you. Are you getting an error? Are the files just not uploading? How about some actual detail rather than having us guess ;)

 

Everything is working, I made all this happen without a problem.
Now my problem is that I don't have a clue about this form of data on how to implement it in a http request with AutoIT:
 

-----------------------------102062144610664
Content-Disposition: form-data; name="name"

hdfhfg.jpg
-----------------------------102062144610664
Content-Disposition: form-data; name="post_id"

0
-----------------------------102062144610664
Content-Disposition: form-data; name="_wpnonce"

123456
-----------------------------102062144610664
Content-Disposition: form-data; name="type"


-----------------------------102062144610664
Content-Disposition: form-data; name="tab"


-----------------------------102062144610664
Content-Disposition: form-data; name="short"

1
-----------------------------102062144610664
Content-Disposition: form-data; name="async-upload"; filename="hdfhfg.jpg"
Content-Type: image/jpeg

Normally a post data would simple look like this:
File=image.jpg&somedata=oakdoaksd
or in another script I made at some point:
fileurl=http://imur.com/oksokasd.png&somedata=blabla

But this is not the case here, I am not sure what to do with this sort of data.


Thanks in advance @JLogan3o13

(I coded all of it, learned from this forum and brugbart.dk, made many other web based scripts like these, but never with such HTTP Headers/Post info)

Share this post


Link to post
Share on other sites

May I suggest WinHttp.au3 from the examples forum. It's made for this stuff, _WinHttpSimpleFormFill() function in particular.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
On 24/06/2016 at 6:54 PM, trancexx said:

May I suggest WinHttp.au3 from the examples forum. It's made for this stuff, _WinHttpSimpleFormFill() function in particular.

Thanks a lot @trancexx!
Will definitely look in to that first thing Monday morning!

 

Share this post


Link to post
Share on other sites

np

It could be like this:

#include "WinHttp.au3"


$sDomain = "http://myurl.com/"
$sLoginPage = "/wp-login.php"
$sUploadPage = "/wp-admin/media-new.php"

$sLoginName = "username"
$sPassword = "mypassword"

; Choose file to upload
$sFileToUpload = FileOpenDialog("Choose something (Image better maybe?)", "", "All (*.*)")
If $sFileToUpload Then
    $hOpen = _WinHttpOpen()
    $hConnect = _WinHttpConnect($hOpen, $sDomain)

    ; Login first
    _WinHttpSimpleFormFill($hConnect, _
            $sLoginPage, _
            "loginform", _
            'user_login', $sLoginName, _
            'user_pass', $sPassword)

    ConsoleWrite('! Error for login = ' & @error & @LF)

    _WinHttpSimpleFormFill($hConnect, _
            $sUploadPage, _
            "file-form", _
            'async-upload', $sFileToUpload)

    ConsoleWrite('! Error for upload = ' & @error & @LF)


    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
EndIf

 

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

19 hours ago, trancexx said:

np

It could be like this:

#include "WinHttp.au3"


$sDomain = "http://myurl.com/"
$sLoginPage = "/wp-login.php"
$sUploadPage = "/wp-admin/media-new.php"

$sLoginName = "username"
$sPassword = "mypassword"

; Choose file to upload
$sFileToUpload = FileOpenDialog("Choose something (Image better maybe?)", "", "All (*.*)")
If $sFileToUpload Then
    $hOpen = _WinHttpOpen()
    $hConnect = _WinHttpConnect($hOpen, $sDomain)

    ; Login first
    _WinHttpSimpleFormFill($hConnect, _
            $sLoginPage, _
            "loginform", _
            'user_login', $sLoginName, _
            'user_pass', $sPassword)

    ConsoleWrite('! Error for login = ' & @error & @LF)

    _WinHttpSimpleFormFill($hConnect, _
            $sUploadPage, _
            "file-form", _
            'async-upload', $sFileToUpload)

    ConsoleWrite('! Error for upload = ' & @error & @LF)


    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
EndIf

 

Makes perfectly sense @trancexx
Thank you so much, I will try to finish my script now!

 

EDIT:
 

! Error for login = 4
! Error for upload = 3

I am looking through WinHTTP.au3 now to find out what this error means, but any help is appreciated.

Using simpleformfill is it possible to add costum headers?
I don't really see an example in the help file with costum Headers.

Thanks in advance @trancexx

Edited by RyukShini
error for login & upload

Share this post


Link to post
Share on other sites

Of course it's possible, but shouldn't really be needed in case of usual wordpress installation.

 

Check addresses. Maybe there's specific htaccess configuration on the server in place which redirects in case of .php access.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

21 hours ago, trancexx said:

Of course it's possible, but shouldn't really be needed in case of usual wordpress installation.

 

Check addresses. Maybe there's specific htaccess configuration on the server in place which redirects in case of .php access.

Okay, I will be sure to check the redirects and what not.
Thanks a lot! ;)

 

I changed something in the wp-login.php?redirect thingy
but still no luck I get errors
! Error for login = 4
! Error for upload = 3 (This error being understandable since we aren't logged in)

What does 4 error in "Error for login = 4????" stand for?
Thanks in advance @trancexx

Edited by RyukShini

Share this post


Link to post
Share on other sites
21 hours ago, RyukShini said:

Okay, I will be sure to check the redirects and what not.
Thanks a lot! ;)

 

I changed something in the wp-login.php?redirect thingy
but still no luck I get errors
! Error for login = 4
! Error for upload = 3 (This error being understandable since we aren't logged in)

What does 4 error in "Error for login = 4????" stand for?
Thanks in advance @trancexx

It means server isn't serving you for some reason. Could you create new user and send me credentials via mail, I would like to see it first hand. I won't touch anything else, no worries.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

3 hours ago, trancexx said:

It means server isn't serving you for some reason. Could you create new user and send me credentials via mail, I would like to see it first hand. I won't touch anything else, no worries.

Sorry I am not able to do so.
It is not my company, but I have another wordpress site I personally own, same principle?
you could try using that if you want.

You have messages disabled?
I can't sent it to you.

e80780a4c9d755054e33b32c941cf25e.png

Edited by RyukShini
Cannot receive messages

Share this post


Link to post
Share on other sites

Use email. Mine is at top of the UDF.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
6 minutes ago, trancexx said:

Use email. Mine is at top of the UDF.

Replied, thanks in advance.

Share this post


Link to post
Share on other sites
2 hours ago, RyukShini said:

Replied, thanks in advance.

Well, it works for me.
If you check uploads you'll see mine. I used this exact code (with my credentials):

#include "WinHttp.au3"

$sLoginPage = '/wp-login.php'
$sUploadPage = '/wp-admin/media-new.php'


$sDomain = 'theyogapants.club'
$sLogin = 'that_username'
$sPassword = 'that_passwrd'


$sFileToUpload = FileOpenDialog("Choose something (Image better maybe?)", "", "All (*.*)")


$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; Login first
_WinHttpSimpleFormFill($hConnect, _
        $sLoginPage, _
        "loginform", _
        'user_login', $sLogin, _
        'user_pass', $sPassword)

ConsoleWrite('! Error for login = ' & @error & @LF)


$sResponse = _WinHttpSimpleFormFill($hConnect, _
        $sUploadPage, _
        "file-form", _
        'async-upload', $sFileToUpload)

ConsoleWrite('! Error for upload = ' & @error & @LF)


_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
3 hours ago, trancexx said:

Well, it works for me.
If you check uploads you'll see mine. I used this exact code (with my credentials):

#include "WinHttp.au3"

$sLoginPage = '/wp-login.php'
$sUploadPage = '/wp-admin/media-new.php'


$sDomain = 'theyogapants.club'
$sLogin = 'that_username'
$sPassword = 'that_passwrd'


$sFileToUpload = FileOpenDialog("Choose something (Image better maybe?)", "", "All (*.*)")


$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; Login first
_WinHttpSimpleFormFill($hConnect, _
        $sLoginPage, _
        "loginform", _
        'user_login', $sLogin, _
        'user_pass', $sPassword)

ConsoleWrite('! Error for login = ' & @error & @LF)


$sResponse = _WinHttpSimpleFormFill($hConnect, _
        $sUploadPage, _
        "file-form", _
        'async-upload', $sFileToUpload)

ConsoleWrite('! Error for upload = ' & @error & @LF)


_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 

First of all, amazing support, second of all so simple!
will do this first thing in the morning, thanks.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

17 hours ago, trancexx said:

Well, it works for me.
If you check uploads you'll see mine. I used this exact code (with my credentials):

#include "WinHttp.au3"

$sLoginPage = '/wp-login.php'
$sUploadPage = '/wp-admin/media-new.php'


$sDomain = 'theyogapants.club'
$sLogin = 'that_username'
$sPassword = 'that_passwrd'


$sFileToUpload = FileOpenDialog("Choose something (Image better maybe?)", "", "All (*.*)")


$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; Login first
_WinHttpSimpleFormFill($hConnect, _
        $sLoginPage, _
        "loginform", _
        'user_login', $sLogin, _
        'user_pass', $sPassword)

ConsoleWrite('! Error for login = ' & @error & @LF)


$sResponse = _WinHttpSimpleFormFill($hConnect, _
        $sUploadPage, _
        "file-form", _
        'async-upload', $sFileToUpload)

ConsoleWrite('! Error for upload = ' & @error & @LF)


_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 

Received this:

! Error for login = 1
! Error for upload = 3

:(

 

I checked the HTML/PHP on both pages and they are identical in the upload stage, no idea whats wrong.

Works for Yoga, does not work for other site(will check headers, cookies and everything)
Headers, Cookies are also identical(except for the domain of course)

 

Might be due to an extra layer of security and I may need to use user-agent in my header.
how would you add a costum header in the simpleformfill ?
Thanks in advance

Edited by RyukShini
user-agent

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

6 hours ago, RyukShini said:

Might be due to an extra layer of security and I may need to use user-agent in my header.
how would you add a costum header in the simpleformfill ?

If you want another user agent then do this:

$hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586")

...and it will be added to all requests that use that $hOpen.

Also you can add whatever header with _WinHttpSimpleFormFill:

_WinHttpSimpleFormFill($hConnect, _
        $sLoginPage, _
        "loginform", _
        'user_login', $sLogin, _
        'user_pass', $sPassword, _
        "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586")

You can also add more than one, just use @CRLF to separate each other:

_WinHttpSimpleFormFill($hConnect, _
        $sLoginPage, _
        "loginform", _
        'user_login', $sLogin, _
        'user_pass', $sPassword, _
        "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586" & @CRLF & _
        "Referer: http://google.com" & @CRLF & _
        "DNT: 1")

 

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
18 hours ago, trancexx said:

If you want another user agent then do this:

$hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586")

...and it will be added to all requests that use that $hOpen.

Also you can add whatever header with _WinHttpSimpleFormFill:

_WinHttpSimpleFormFill($hConnect, _
        $sLoginPage, _
        "loginform", _
        'user_login', $sLogin, _
        'user_pass', $sPassword, _
        "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586")

You can also add more than one, just use @CRLF to separate each other:

_WinHttpSimpleFormFill($hConnect, _
        $sLoginPage, _
        "loginform", _
        'user_login', $sLogin, _
        'user_pass', $sPassword, _
        "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586" & @CRLF & _
        "Referer: http://google.com" & @CRLF & _
        "DNT: 1")

 

Amazing I am gonna try.
However I found out it might not be the error afterall.
It may be due to the wordpress installation being in Danish on the other site, but still the IDs, Class, all of the HTML code is still in English of course, so I am not sure if WinHTTP takes that in to consideration?
Will try to fool around with it a bit.

 

<form name="loginform" id="loginform" action="http://url.dk/wp-login.php" method="post">
    <p>
        <label for="user_login">Brugernavn eller e-mail<br />
        <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
    </p>
    <p>
        <label for="user_pass">Adgangskode<br />
        <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
    </p>
        <p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever"  /> Husk mig</label></p>
    <p class="submit">
        <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log ind" />
        <input type="hidden" name="redirect_to" value="http://url.dk/wp-admin/" />
        <input type="hidden" name="testcookie" value="1" />
    </p>
<form name="loginform" id="loginform" action="http://url.com/wp-login.php" method="post">
    <p>
        <label for="user_login">Username or Email<br />
        <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
    </p>
    <p>
        <label for="user_pass">Password<br />
        <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
    </p>
        <p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever"  /> Remember Me</label></p>
    <p class="submit">
        <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In" />
        <input type="hidden" name="redirect_to" value="http://url.com/wp-admin/" />
        <input type="hidden" name="testcookie" value="1" />
    </p>

 

Share this post


Link to post
Share on other sites

Language shouldn't make difference.

So you can do it from your browser by navigating to http://url.dk/wp-login.php


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
On 01/07/2016 at 6:48 PM, trancexx said:

Language shouldn't make difference.

So you can do it from your browser by navigating to http://url.dk/wp-login.php

Everything works in the same way.
only difference is the language, I honestly don't understand why this happens.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Ascer
      By Ascer
      1. Description
      Anti-bot system to avoid spam. Vector graphic style generates 4 random numbers from 0-9 and create a picture. 2. Requirements
      .NET Framework 1.1 - 4.5 (on this version Microsoft destroy old rules) 3. Possibilities.

      4. Downloads.
      Source package Capatcha.rar
    • Valnurat
      By Valnurat
      How can I get combobox value by using  the ENTER key?
    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • Valnurat
      By Valnurat
      I have a ComboBox and I want, when I start writting in it, that it will show me what is the first in the list.
      Like, is I start writting:
      "pe" it  should show me "peter" if that is the first in the list.
      How can I do that?
       
      While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClos ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Local $iIdx = _ArraySearch($aResult,$sComboRead,0,0,0,0,1,1) Local $aComputerOwner = _AD_GetObjectsInOU("OU=al,DC=AD,DC=AL,DC=ORG","(&(objectclass=computer)(managedby=" & $aResult[$iIdx][0] & "))",Default,"cn") _ArrayDelete($aComputerOwner,0) _GUICtrlListView_SetItemCount($idMylist,UBound($aComputerOwner)) If IsArray($aComputerOwner) Then For $i = 0 To UBound($aComputerOwner) - 1 GUICtrlCreateListViewItem($aComputerOwner[$i], $idMylist) Next Else GUICtrlSetData($idMylist, "No computer|") EndIf EndSwitch WEnd  
    • Valnurat
      By Valnurat
      Hi.
      I'm trying to add an array to my gui listview, but it fails with
      "C:\Program Files (x86)\AutoIt3\Include\GuiListView.au3" (473) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: DllStructSetData($tBuffer, "Text", $aItems[$iI][0]) DllStructSetData($tBuffer, "Text", ^ ERROR My code is:
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #Include <AD.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Global $aResult[0][2] Local $aNames[4] = ["DKSO","DKKO","SELU","SEES"] Local Const $iWidth = 300, $iHeight = 250, $iW = 85, $iH = 25 Local $hGUI = GUICreate("Find Computer Owner", $iWidth, $iHeight) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("", 2, 2, 296, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT)) ;$WS_VSCROLL Local $idMylist = GUICtrlCreateListView("", 2, 114, 296, 100) Local $idClos = GUICtrlCreateButton("Close", ($iWidth - $iW) / 2, ($iHeight - $iH) - 7 , $iW, $iH) _AD_Open() Local $sFill = "" For $i = 0 to UBound($aNames) -1 Local $aUserInfo = _AD_GetObjectsInOU("OU=Al,DC=ad,DC=al,DC=org","(&(objectCategory=Person)(objectclass=user)(sAMAccountName=" & $aNames[$i] & "*))","","distinguishedName,cn") if @error Then MsgBox(0,@error,@extended) Exit EndIf For $x = $aUserInfo[0][0] To 1 Step -1 If $aUserInfo[$x][0] = "" Or StringInStr($aUserInfo[$x][0], "Resources") > 0 Or StringInStr($aUserInfo[$x][0], "Leavers") > 0 Or StringInStr($aUserInfo[$x][0], "Administration") > 0 Then _ArrayDelete($aUserInfo, $x) EndIf Next _ArrayConcatenate($aResult, $aUserInfo, 1) Next for $i = 0 To UBound($aResult) -1 If $aResult[$i][0] <> "" Then $sFill &= $aResult[$i][1] & "|" EndIf Next _ArrayDisplay($aResult, 'AD ' & UBound($aResult)) $sFill = StringTrimRight($sFill, 1) _GUICtrlComboBox_BeginUpdate($idComboBox) GUICtrlSetData($idComboBox, $sFill, "") _GUICtrlComboBox_EndUpdate($idComboBox) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUICtrlListView_AddColumn($idMylist, "Computername", 296) Local $sComboRead = "" ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClos ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Local $iIdx = _ArraySearch($aResult,$sComboRead,0,0,0,0,1,1) Local $aComputerOwner = _AD_GetObjectsInOU("OU=al,DC=AD,DC=AL,DC=ORG","(&(objectclass=computer)(managedby=" & $aResult[$iIdx][0] & "))",Default,"cn") _ArrayDelete($aComputerOwner,0) _ArrayDisplay($aComputerOwner) _GUICtrlListView_SetItemCount($idMylist,UBound($aComputerOwner)) If IsArray($aComputerOwner) Then MsgBox(0,"Test",$sComboRead) _GUICtrlListView_AddArray($idMylist, $aComputerOwner) ; <---- it fails Else GUICtrlSetData($idMylist, "No computer|") EndIf EndSwitch WEnd _AD_Close() ; Delete the previous GUI and all controls. GUIDelete($hGUI) Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $hWndListView = $idMylist If Not IsHWnd($idMylist) Then $hWndListView = GUICtrlGetHandle($idMylist) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint Do I do it wrong?
       
      Thank you in advanced.