Jump to content
Sign in to follow this  

run a process

Recommended Posts



How do you do to run a process in a new desktop after switching in it ?

I try like this but that don't work (the process run always in the default desktop) :

$OriginalThread = DLLCall("kernel32.dll","int","GetCurrentThreadId")
$OriginalInput = DllCall('user32.dll', 'hwnd', 'OpenInputDesktop', 'int', 0, 'int', 0, 'int', 0x100)
$NouveauBureau = DLLCall("user32.dll","int","CreateDesktop","str","NouveauBureau", "str","","ptr",0,"int",0,"int",0x10000000,"ptr",0)
$Startup = DllStructCreate($tagSTARTUPINFO)
$Process = DllStructCreate($tagPROCESS_INFORMATION)
DllCall('user32.dll', 'int', 'SetThreadDesktop', 'hwnd', $NouveauBureau[0])
DllStructSetData($Startup, "Size", DllStructGetSize($Startup))
DllStructSetData($Startup, "Desktop", DllStructGetData($Startup, "NouveauBureau"))
_API_CreateProcess("", "C:\Windows\Notepad.exe", 0, 0, False, 0, 0, "", DllStructGetPtr($Startup), DllStructGetPtr($Process))
_API_CloseHandle(DllStructGetData($Process, "hProcess"))
_API_CloseHandle(DllStructGetData($Process, "hThread" ))
DllCall('user32.dll', 'int', 'SetThreadDesktop', 'hwnd', $OriginalThread[0])

Certainly i make a mistake but i can't fing where...

Thanks !

Share this post

Link to post
Share on other sites

If you look in my signature you will find the create process function.

inside the STARTUPINFO you can specify the name of the desktop you want your process to be run DO IT BEFORE YOU SWITCH

!Careful keep track of the PID otherwise you will never be able to close that desktop again.

Another thing pointer to NULL strings are different in AUTOIT from C and you cannot use just 0 so

$NouveauBureau = DLLCall("user32.dll","int","CreateDesktop","str","NouveauBureau", "str",Pt_emptyStr,"ptr",Pt_emptyStr,"int",0,"int",0x10000000,"ptr",Pt_emptyStr)
DllCall('user32.dll', 'int', 'SetThreadDesktop', 'hwnd', $NouveauBureau[0])

Func Pt_emptyStr()
    $temp = DllStructCreate("char [" & Stringlen($str) + 1 & "]")
     DllStructSetData($temp,1, $str)
    $P_empty = DllStructGetPtr($temp)
    Return $P_empty

is the correct function

Edited by Hermano

-----------------------------------------------CARPE DIEMProcess Create functionDisplay_Library_FunctionsSkype erase history

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.