• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

AutoIT Create Desktop And Run Program in it By MR~X[AU3 Src]

Status
Not open for further replies.

F.I.G.H.T.E.R

ϻɵĐęřåŦō&#1136
User
Joined
Mar 26, 2013
Messages
975
Reputation
0
Reaction score
15,790
Points
493
Credits
0
‎12 Years of Service‎
20%
Create Desktop And Run Program in it


By
MR~X


[
AU3 Src]

[HIDE-THANKS]

Code:
>#include 
#include 
#include 
#include 
#include 
#include 

; Retrieve a handle to the current desktop and create a new desktop named "MyDesktop"
Local $hPrev = _WinAPI_GetThreadDesktop(_WinAPI_GetCurrentThreadId())
Local $hDesktop = _WinAPI_CreateDesktop('MyDesktop', BitOR($DESKTOP_CREATEWINDOW, $DESKTOP_SWITCHDESKTOP))
If Not $hDesktop Then
MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Unable to create desktop.')
Exit
EndIf

; Switch to the newly created desktop
_WinAPI_SwitchDesktop($hDesktop)

; Run "program.exe" on MyDesktop and wait until a process will not be closed by user
Local $pText = _WinAPI_CreateString('MyDesktop')
Local $tProcess = DllStructCreate($tagPROCESS_INFORMATION)
Local $tStartup = DllStructCreate($tagSTARTUPINFO)
DllStructSetData($tStartup, 'Size', DllStructGetSize($tStartup))
DllStructSetData($tStartup, 'Desktop', $pText)
FileInstall('program.exe', @AppDataDir &'\program.exe')
If _WinAPI_CreateProcess('', @AppDataDir & '\program.exe', 0, 0, 0, $CREATE_NEW_PROCESS_GROUP, 0, 0, $tStartup, $tProcess) Then
ProcessWaitClose(DllStructGetData($tProcess, 'ProcessID'))
EndIf

; Switch to previous desktop and close "MyDesktop"
_WinAPI_SwitchDesktop($hPrev)
_WinAPI_CloseDesktop($hDesktop)

; Free memory allocated for a string
_WinAPI_FreeMemory($pText)
[/HIDE-THANKS]
 
Status
Not open for further replies.
Back
Top