Jump to content

Recommended Posts

Posted (edited)

I'm having troubles on using _WinAPI_SetThreadDesktop(). Calling this function to any (newly-created or existing) desktop handle fails with error code 170 ("The requested resource is in use").

This error usually happens when the thread wanting to move to a new desktop has hooks or windows on the desktop it is in. As stated by both MSDN and the help file:

Quote

The [...] function will fail if the calling thread has any windows or hooks on its current desktop

I've prepared a small testcase that does not create any GUI but still reproduces the error. Running the script below on my machine (Windows 10 x64) shows that I am able to use _WinAPI_SwitchThread() (and have the whole user session moved to the new desktop) with no problems, but I can't use _WinAPI_SetThreadDesktop() as the mentioned error is throw.

#include <WinAPISys.au3>
#include <WinAPIProc.au3>

; Create a new desktop
$hDesktop = _WinAPI_CreateDesktop("au3_test", $DESKTOP_ALL_ACCESS)

; Test 1: Set thread desktop
_WinAPI_SetThreadDesktop($hDesktop)
If _WinAPI_GetLastError() Then
    MsgBox(0, _WinAPI_GetLastError(), _WinAPI_GetLastErrorMessage())
EndIf

; Test 2: Switch to desktop
$hOldDesktop = _WinAPI_OpenInputDesktop($DESKTOP_ALL_ACCESS)
_WinAPI_SwitchDesktop($hDesktop)
If _WinAPI_GetLastError() Then
    MsgBox(0, _WinAPI_GetLastError(), _WinAPI_GetLastErrorMessage())
EndIf

_WinAPI_SwitchDesktop($hOldDesktop)
_WinAPI_CloseDesktop($hDesktop)

Compiling or running as administrator didn't change anything.

Could this be related to the interpreter executable? Does it create hooks or invisible windows that disallows me to use SetThreadDesktop? Is there some possible workaround, in this case?

The UDF is nothing more than a DllCall so I don't think there is some problem on it. Perhaps I'm missing something on my implementation?

Update

It looks like someone already faced this issue and it is due to a hidden window created by the interpreter:

5c181392ab375_ScreenShot2018-12-17at19_17_44.png.6bd49216bfc8f44344fe22fe661b88cc.png

Compiling as CUI does not remove that window. It looks like it's meant "to allow other programs (or other AutoIt scripts) to interact with AutoIt" (from the help file). It looks like it is also used for registering hotkeys. It looks like there is no easy workaround... 

Edited by Jefrey

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

  • Jefrey changed the title to _WinAPI_SetThreadDesktop() error 170. AutoIt limitation? UDF bug?
Posted

I was sure I was posting on Help & Support forum...

My bad.

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Posted (edited)

Maybe its autoit's hidden window ?
And maybe if a new script starts from the new desktop , the error wont show ?

didn't try anything yet ..

Edit: i see the edit to your post now ..

Deye

Edited by Deye

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...