Jump to content
Sign in to follow this  
DLS

How to find if window handle is active on current virtual desktop (Win10)

Recommended Posts

DLS

I have a working script that changes the core affinity and process priority of multiples of a specific application I have running.  

I have that part figured out.


I would like to make a little modification to it.


Windows10 introduced virtual desktops.  I am trying to have different core affinity and priority of processes on the visible and non-visible desktops.  

What I need is a bool function that could be described as IsWindowOnCurrentDesktop($hWnd).  I have searched the winAPI.au3 but I do not believe anything like that exists built it.

I have searched multiple places before asking for help. I found a Microsoft supplied example of the function I need using C#, but I am unfamiliar with C# to a degree that I cannot port the system call over.

https://blogs.msdn.microsoft.com/winsdk/2015/09/10/virtual-desktop-switching-in-windows-10/

Help is appreciated but not expected.  Thanks in advanced.   In the meantime I will be learning C# syntax and class structure.

Edited by DLS

Share this post


Link to post
Share on other sites
DLS

I got it to work.  Heres the code if someone needs it.

Relevant Function

Func _IsWindowOnCurrentVirtualDesktop($hWnd)
    $CLSID = "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
    $IID = "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
    $TAG = "IsWindowOnCurrentVirtualDesktop hresult(hwnd;ptr*);"
    $IVirtualDesktopManager = ObjCreateInterface($CLSID, $IID, $TAG)
    $Result = False
    $IVirtualDesktopManager.IsWindowOnCurrentVirtualDesktop($hWnd, $Result)
    $IVirtualDesktopManager = 0
    Return $Result
 EndFunc

Entire Program

#requireadmin
#include <WinAPI.au3>
#include <WinAPIProc.au3>
#include <ProcessConstants.au3>

$Process = ProcessList("processname.exe")
For $i = 1 To $Process[0][0]
    $pid = $Process[$i][1]
    $handle = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $pid)
    $hWnd = _GetWindowHandleFromPid($pid)
    ProcessSetPriority ($pid, 0 )                           ;set cpu priority
    _WinAPI_SetProcessAffinityMask($handle, 0x08)           ;set cpu affinity
    ;msgbox(0,"",$Process[$i][0] & "   " & $Process[$i][1]  & "   " & $handle & "   " & $hWnd ) ;debug
    ;msgbox(0, "", _IsWindowOnCurrentVirtualDesktop($hWnd)) ;debug
 Next

Func _IsWindowOnCurrentVirtualDesktop($hWnd)
    $CLSID = "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
    $IID = "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
    $TAG = "IsWindowOnCurrentVirtualDesktop hresult(hwnd;ptr*);"
    $IVirtualDesktopManager = ObjCreateInterface($CLSID, $IID, $TAG)
    $Result = False
    $IVirtualDesktopManager.IsWindowOnCurrentVirtualDesktop($hWnd, $Result)
    $IVirtualDesktopManager = 0
    Return $Result
 EndFunc

 Func _GetWindowHandleFromPid($pid)
    Local $aData = _WinAPI_EnumProcessWindows($pid)
    Return $aData[1][0]
 EndFunc

;~  0x01    CPU1                binary to hex conversion reference chart with 1s for active cores and 0s for disabled
;~  0x02    CPU2
;~  0x03    CPU1+2
;~  0x04    CPU3
;~  0x05    CPU1+3
;~  0x06    CPU2+3
;~  0x07    CPU1+2+3
;~  0x08    CPU4
;~  0x09    CPU1+4
;~  0x0A    CPU2+4
;~  0x0B    CPU1+2+4
;~  0x0C    CPU3+4
;~  0x0E    CPU1+3+4
;~  0x0F    CPU1+2+3+4

 

Edited by DLS
  • Like 1

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  

  • Similar Content

    • PramodR
      By PramodR
      Hello,
      I have to execute below block of code in elevated previllage, as that particular wmic class will work only with admin previlage.
      i am getting out put when i launch autoit as administrator,  but i will not be able to launch autoit as admin in this particular case but my user have admin rights.
      is there any better way i can run those command as administrator.?
      tried below steps:
      i have tried #RequireAdmin but that creates a user prompt  Tried using Runas command but gives error as wrong username or password , stuck with that step.  
       
    • dwaynek
      By dwaynek
      traytip isn't working in windows 10. nothing happens when i use the Traytip command.
      here's a simple script i used:
      TrayTip("I'm a title", "I'm the message", 5) i tried changing the registry setting HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced ( which didn't have EnableBalloonTips) and creating a DWORD entry called EnableBalloonTips and setting it to 1 and logging off then back in. that did not resolve the problem.
      i'm running Windows 10 v1709 b16299.431
    • evanevery
      By evanevery
      An AUTOIT app just stopped running on several machines in our office after applying the recent Win10 1803 update.
      Here are the details:
      1.  The App is now failing the UDPBIND call with a 10022 error.
      2.  The App runs fine on machines which have NOT YET applied the 1803 Win10 update just released
      3.  The App fails on all machines to which the 1803 has been applied - but only if the app is loaded from a network share!
      4.  If the app is run from a LOCAL drive, it continues to run fine even after the 1803 update
      In summary:
      Something has changed with the Win10 1803 update which now prevents AutoIT apps from opening UDP ports (UDPBIND) if the Apps are being loaded/run off a network share!
      I have confirmed this by manually updating a workstation to 1803 and confirming this is what is causing the failure.  (Worked fine immediately before - now fails immediately after)
      Also, I am not having issues running other Autoit network apps from network shares which DON'T use the UDPBIND call. (i.e. "DriveMapAdd" is still working under the same conditions)
      The share which we have been loading/running our apps from is running SMB v1.5 protocols (via Linux/Samba)
    • antonioj84
      By antonioj84
      Hi all to the forum guru and expert I am trying to  automate this. in the registry  I have the network profile name network 2 and network   I want to  change their  CATEGORY  to Private .  Can someone lead me in the right direction.
      Private is 1 and Public is 0
      #RequireAdmin Global $sHKLMRoot = @OSArch = "x64" ? "HKLM64" : "HKLM" RegWrite($sHKLMRoot &"\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\NewNetworks" ,'/v NetworkList /t REG_MULTI_SZ /d 00000000 /f') see  attached picture below
      Much appreaciate
       

    • PhoenixPRO
      By PhoenixPRO
      When I try to automate this install program I can not get any of the buttons to click with the "ControlClick" function or any mouse movement to move the mouse to the and click it.  My OS is Windows 10 64Bit.  I have tried both 32bit and 64bit installs of Autoit V3 to no avail.
      I could not even get the run command to start the program until I used the variation of the command below in the script.
      With the script below the install program starts but will not click the "Next" button no matter what I do.
      Any help will be greatly appreciated.
      Thanks in advance.
       
      #include <MsgBoxConstants.au3>
      Opt("MouseCoordMode", 0) ;1=absolute, 0=relative to active window, 2=client
      Local $Success
      Run(@ComSpec & " /c " & 'C:\PhoenixPro_Install\RDXUtil\RDX_Tools_setup.exe', "C:\PhoenixPro_Install\RDXUtil", @SW_HIDE )

      WinWait("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62")
      WinActivate("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62")
      ControlClick ("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62", 1639, "left", 1) ;Next Button
×