0xdefea7 Posted June 11, 2013 Posted June 11, 2013 (edited) Hello Everyone, I am working on a script to switch desktops. Everything is working fairly well aside from the fact that when I create a new process, it is not spawning in my new desktop. In C++, I can change the desktop by changing a value passed in the STARTUPINFO struct. AutoIt has a similar translated struct called the $tagStartupInfo structure. It seems that I am unable to set the data for the "Desktop" element of the $tagStartupInfo struct that I created. Can someone please point out my error? Thank you in advance! Here is my code: (Edited to reflect the correct code now) expandcollapse popup#include-once #include <WinAPI.au3> #include <WinAPIEx.au3> Global $User32 = "User32.dll" Global $hLastDesktop, $hCurrentDesktop $tDesktop = DllStructCreate("handle Desktop1;" & _ "handle Desktop2;" & _ "handle Desktop3;" & _ "handle Desktop4;") $tStartupInfo = DllStructCreate($tagStartupInfo) DllStructSetData($tStartupInfo, "Size", DllStructGetSize($tStartupInfo)) $tProcessInfo = DllStructCreate($tagPROCESS_INFORMATION) Func FindCurrentDesktop() Return GetThreadDesktop(_WinAPI_GetCurrentThreadId()) EndFunc Func GetThreadDesktop($iTID) $Ret = DllCall($User32, "handle", "GetThreadDesktop", "dword", $iTID) Return $Ret[0] EndFunc Func SetThreadDesktop($hDesktop) $Ret = DllCall($User32, "int", "SetThreadDesktop", "handle", $hDesktop) Return $Ret[0] EndFunc Func SwitchDesktop($hDesktop) $Ret = DllCall($User32, "int", "SwitchDesktop", "handle", $hDesktop) Return $Ret[0] EndFunc Func CreateDesktop($sDesktop) $Ret = DllCall($User32, "handle", "CreateDesktop", "str", $sDesktop, "str", 0, "ptr", 0, "dword", 0, "dword", $GENERIC_ALL, "dword", 0) Return $Ret[0] EndFunc Func CloseDesktop($hDesktop) $Ret = DllCall($User32, "int", "CloseDesktop", "handle", $hDesktop) Return $Ret[0] EndFunc Func ChangeDesktop($hDesktop) $hLastDesktop = FindCurrentDesktop() SwitchDesktop($hDesktop) SetThreadDesktop(FindCurrentDesktop()) EndFunc $sProcessName = "C:\windows\system32\calc.exe" $hLastDesktop = FindCurrentDesktop() DllStructSetData($tDesktop, "Desktop1", $hLastDesktop) $hDesktop2 = CreateDesktop("Desktop2") DllStructSetData($tDesktop, "Desktop2", $hDesktop2) ChangeDesktop($hDesktop2) $sFail = DllStructSetData($tStartupInfo, "Desktop", _WinAPI_CreateString("Desktop2")) If $sFail = 0 Then ConsoleWrite("SetData failure (tStartupInfo): " & @error & @CRLF) ConsoleWrite("Data (tStartupInfo: " & DllStructGetData($tStartupInfo, "Desktop") & @CRLF) _WinAPI_CreateProcess($sProcessName, 0, 0, 0, True, 0, 0, 0, DllStructGetPtr($tStartupInfo), DllStructGetPtr($tProcessInfo)) If @error Then ConsoleWrite("Error: " & @error & " WinAPI: " & _WinAPI_GetLastError() & @CRLF) $hProcess = DllStructGetData($tProcessInfo, "hProcess") ConsoleWrite("Handle to process: " & $hProcess & @CRLF) Sleep(5000) ProcessClose($hProcess) ChangeDesktop($hLastDesktop) CloseDesktop($hDesktop2) Edited June 11, 2013 by 0xdefea7
Solution guinness Posted June 11, 2013 Solution Posted June 11, 2013 Again, look at WinAPIEx and the help file that comes with it. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now