Sign in to follow this  
Followers 0
derekG

Can this be done with Win32 API and Autoit?

15 posts in this topic

Hi guys, How are you?

I've been doing some research about how to save desktop layouts, how to open and save a opened applications.

It's all about class, title and PID, right?

In all cases I saw we need to actually open the application on machine in order to catch that info from the window.

How the example bellow can be done?  Besides the drag and drop, how to open an app on a remote computer, give its title dynamically, send to any location and size on server computer and be able to save location and size of several applications, like a layout.

example:

 

Share this post


Link to post
Share on other sites



I doubt if you know the price of that product you compare AutoIt with ;-)

No its not only about process, class, window titles. 

  • Start a program on a remote machine. There are dozens of ways but this is a nice one
    http://windowsitpro.com/powershell/use-powershell-run-programs-remote-computers
  • Drag and drop over machines. I doubt if thats possible.
    The video you show is just a big screen with multiple monitors so its just about dragging and dropping with x, y positions
  • Windows 7 and higher all support IUIAutomation
    See FAQ 31 for references to details
  • Probably you need some manyears to build this stuff with AutoIt but reading all the UDF's over the years from AutoIt the knowledge is in this forum
  • If you arrange the hardware at my home I am willing to do a try on it ;-)

 

Share this post


Link to post
Share on other sites

Thanks for your help Junkew!

I know that's too much, for now I would like to be able save a layout on a desktop.

lise so: Chrome(somewebsite.com) , Firefox(web2,net), Autocad(working project), Illustrator(same) , all with some content , will be better if all this could be save in a .ini file.

When I save this layout I would like to recall this preset/layout from a remote computer.

Thanks.

,

Share this post


Link to post
Share on other sites

Besides that, how can we program a any software to open in y,x values(location on screen) and some dimension(size) without even opening this software on the machine?

All done dynamically with forms:

inputs: 1) address of the app on the machine 2) parametres 3) x,y pixels 4) size

If this is too hard, would be easier just to get a title dynamically, with user input,. since the class is already registered, that way would be easier to manipulate size and location on screen, right, without the PID.

Thanks.

Share this post


Link to post
Share on other sites

Advice is first to read the FAQ.https://www.autoitscript.com/wiki/FAQ at least 31,38,40 you should read

The basics you ask are doable with AutoIt 

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

see you can move it to x,y and at the same time set the width, heidht property

  • and reading from ini files

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

 

 

Share this post


Link to post
Share on other sites

Thanks, Junkew for all your help.

What about this problem:

1. Server where all apps are installed

2. From client, from another computer on a local network, user will input the address of the app that needs to be opened, size and location on the screen the the server is connected to.

The examples I saw, the app needs to be opened on server computer to gather PID, class and window title, how can this be done dynamically from another computer?

Thanks?

  

Share this post


Link to post
Share on other sites

Summarized: you have to write 2 executables yourself that can communicate with each other

  • you cannot do something on another computer without a program that is doing that for you.

1.   Build an executable server.exe that can
      - listen on a certain port on the server
      - can start other executables
      - based on title, processid, .... with a winmove and resize set it to the proper location

2.   To start this executable remotely: 
https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Invoke-Command?view=powershell-5.0

3. Start another client.exe communicating with server.exe sending the commands the server.exe understands

 

 

 

 

Share this post


Link to post
Share on other sites

@derekG Hello. My Pool environment (link in my sig) supports both IPC (through various means) and remote execution across a (W)LAN. However, this is an advanced tool with a steep learning curve, and I won't be holding your hand along the way (please study the examples and adapt to your needs). Just a suggestion.:)

Share this post


Link to post
Share on other sites

Hi guys,

I already have a server running, that's not the problem.

The majority of the solutions I saw about sizing , x,y location the program is already running  then you can save the settings.

What I am asking and what I saw in softwares like I mentioned before was to do all that remotely.

like:

From client: open chrome in 0,0 position and 200x200 size

open autocad  200, 0 500x500 size

On server those apps opens and from client , user can save this layout preset, with all the parametes, size, content, position, files, etc...

The reason for this question: All software I saw you need to pre open any .exe first to save position, size thru pid, class and win title, how can this be done dynamically and remotely, same lan?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

This is the base to directly show at right location and in the right size.

  • Start minimized, make it transparent, move and size it, make it untransparent.
  • You could use this if you do not want to use the procesxx functions
    $hwnd=Winwait("[CLASS:Notepad]", "",5)
Example()

Func Example()
    ; Run Notepad with the window maximized.
    Local $iPID = Run("notepad.exe", "", @SW_minimize )

    ; Wait 5 seconds for the Notepad window to appear.
    sleep(5000)
    $hwnd=ProcessGetHWND($iPID)
;~     $hwnd=Winwait("[CLASS:Notepad]", "",5)
;~ consolewrite($hwnd)

    ; Set the transparency of the Notepad window to 170.
    WinSetTrans($hwnd, "", 0)
    winactivate($hwnd,"")
    WinSetstate($hwnd, "",@SW_SHOW )

    $locX=int(random(0,1)*300)
    $locY=int(random(0,1)*300)
;~  consolewrite($LocX & $locY)

    WinMove($hwnd, "",$locX,$locY,200,200 )

    ; Wait for 1/2 seconds.
    Sleep(500)

    WinSetTrans($hwnd, "", 255)
    sleep(2000)
    
    ; Close the Notepad process using the PID returned by Run.
     ProcessClose($iPID)
EndFunc   ;==>Example

Func ProcessGetHWND($iPID)
    If IsNumber($iPID) = 0 Or ProcessExists(ProcessGetName($iPID)) = 0 Then
        SetError(1)
    Else
        Local $WinList = WinList()
        Local $i = 1
        Local $HWND = 0
        While $i <= $WinList[0][0] And $HWND = 0
            If WinGetProcess($WinList[$i][0], "") = $iPID Then
                $HWND = $WinList[$i][1]
            Else
                $i += 1
            EndIf
        WEnd
        Return $HWND
    EndIf
EndFunc   ;==>ProcessGetHWND

Func ProcessGetName($PId)
    If IsNumber($PId) = 0 Then
        SetError(2)
    Else
        Local $PList = ProcessList()
        Local $i = 1
        Local $ProcessName = ""

        While $i <= $PList[0][0] And $ProcessName = ""
            If $PList[$i][1] = $PId Then
                $ProcessName = $PList[$i][0]
            Else
                $i = $i + 1
            EndIf
        WEnd
        Return $ProcessName
    EndIf
EndFunc   ;==>ProcessGetName
Edited by junkew
The TCP example of the helpfiles

Share this post


Link to post
Share on other sites

Thanks Junkew!!

So your solution will still open the apps, invisible mode, right?

But if the user wants to create several layouts, offline without playing on the server because, the server is already playing some content/some apps.

Share this post


Link to post
Share on other sites

A good example: 

 

Share this post


Link to post
Share on other sites

you change your requirements :) but all parts are mentioned in previous answer

All you have shown can be done in AutoIt just the algorithm you implement changes a little

1. On the server your run a WallServer.EXE, which has a TCP/IP listener

2. On the client you run your WallClient.EXE which can connect to WallServer.EXE

3. You send a string  from WallClient.EXE to WallServer.EXE
    like {<appinfo>,<x>,<y>,<w>,<h>}{<appinfo>,<x>,<y>,<w>,<h>}{<appinfo>,<x>,<y>,<w>,<h>}{<appinfo>,<x>,<y>,<w>,<h>}

4. The WallServer receives and parses the string
a. The WallServer scans if certain apps are already running and just WinMoves them (maybe first hide)
b. The WallServer kills all the apps not in the string

Variations: First show a static bitmap in front of all other windows and remove that as last to have less flickering/rebuilding stuff

In the forum you can find solutions for crosshair and many other things

 

Share this post


Link to post
Share on other sites

You're the best!!

I will study this!!

I've tried to get info about how those softwares were implemented and no one could tell me, even at .net forum.

Thanks.

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
Sign in to follow this  
Followers 0