Jump to content

How can I run a process in a hidden desktop that is never switched to?


Recommended Posts

I have the following script:

; Script Start - Add your code below here
#include <MsgBoxConstants.au3>
#include <WinAPIMem.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>


Opt("MouseCoordMode", 2)

$UpTo = 3360 ;+1 NEXT TIME



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

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

; Run "notepad.exe" on "MyDesktop" and wait until a process will not be closed by user
Local $pText = _WinAPI_CreateString('MyDesktop10')
Local $tProcess = DllStructCreate($tagPROCESS_INFORMATION)
Local $tStartup = DllStructCreate($tagSTARTUPINFO)
DllStructSetData($tStartup, 'Size', DllStructGetSize($tStartup))
DllStructSetData($tStartup, 'Desktop', $pText)
;If _WinAPI_CreateProcess('', 'J:\Program Files (x86)\Visual Recurrence Analysis\VisualRecurrenceAnalysis.exe', 0, 0, 0, $CREATE_NEW_PROCESS_GROUP, 0, 0, $tStartup, $tProcess) And _WinAPI_CreateProcess("", 'C:\Program Files (x86)\AutoIt3\Beta\AutoIt3_x64.exe "N:\DOWNLOADS\JUSTTOMAKE SPACE\VISUAL RECURRENCE ANALYSIS\00.au3"', 0, 0, 0, $CREATE_NEW_PROCESS_GROUP, 0, 0, $tStartup, $tProcess) Then


$count = 1
for $i = 3 to 10
 for $j = 2 to 10
  If _WinAPI_CreateProcess('', 'N:\DOWNLOADS\JUSTTOMAKE SPACE\VISUAL RECURRENCE ANALYSIS\10\PostQuitMessage.exe 1.txt' & " " & $i & " " & $j & " " & $count & '.csv', 0, 0, 0, $CREATE_NEW_PROCESS_GROUP, 0, 0, $tStartup, $tProcess) then
        ProcessWaitClose(DllStructGetData($tProcess, 'ProcessID'))
  EndIf
  $count = $count + 1
 next
Next


;sleep(5000)

;FileChangeDir("J:\Program Files (x86)\Visual Recurrence Analysis\")
;Run("VisualRecurrenceAnalysis.exe", "")
;sleep(50)

;$Program = @SystemDir&"\cmd.exe"
;ShellExecute("J:\Program Files (x86)\Visual Recurrence Analysis\VisualRecurrenceAnalysis.exe", "", "", "")

;ShellExecute ( "start.bat" )

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

; Free memory allocated for a string
_WinAPI_FreeMemory($pText)


exit(0)

but it stops suddenly, sometimes write 7 files, sometime 3 files, unless I switch to the hidden desktop, which I do not want to do, since I have to work on the default desktop, the script also works in full if I keep opened task manager. Is there any way I can run the process in a hidden desktop and make it finishing writing all the 72 output files?

Link to comment
Share on other sites

Have you tried with virtual desktop ?  I made an example how to use it (see my signature for Virtual Desktop Management).

Since we cannot run your code, it is going to be hard for us to find what is the problem.  You should consider making it runable to us if you want further help.

Link to comment
Share on other sites

where is your virtual desktop management? I have attached the exe file, but I do not know if it will work, since is heavily patched,  basically the problem is that it stops at one point, unless

this line is used or task manager is kept open. the issue can be easily reproducible you can use any process that keep doing something for some time and producing output to the directory.

;_WinAPI_SwitchDesktop($hDesktop)

PostQuitMessage.rar

Link to comment
Share on other sites

Sorry I am not copying/installing anything on my computer that I absolutely need.

Just click on Reveal hidden contents at the bottom of my post to get access at my examples/UDF.

7 minutes ago, chtulu said:

the issue can be easily reproducible you can use any process that keep doing something

why don't you make a snippet that is not working if it is that easy ...

Link to comment
Share on other sites

also this indicates, that you can not have more than 1 desktop already:

Quote
; gives the number of virtual desktops
$iHresult = $oVirtualDesktopManagerInternal.GetCount($iCount)
ConsoleWrite("Number of Desktop = " & $iCount & "/" & $iHresult & @CRLF)
If $iCount > 1 Then Exit MsgBox($MB_SYSTEMMODAL, "", "Please close all additional Virtual Desktops")

 

 

Link to comment
Share on other sites

so, is useless to me. Basically I found out that even if I create a new desktop through windows 10, any application stops running unless you stay on that desktop, which I do not see the point of doing, since I do not want to see the application running. Is there any solution?

Link to comment
Share on other sites

35 minutes ago, chtulu said:

any application stops running unless you stay on that desktop

Very False

Easy to prove it : play a song in first desktop, manually create a new virtual desktop, go to second desktop, music continues to play.  You can do whatever in the second desktop, music will continue to play...

Link to comment
Share on other sites

then is only with this borland c++ builder software and there is nothing I can do.  I can not even run it hidden, I can run notepad hidden but not this application, maybe someone knows why if I am not on the desktop where the application run and I keep task manager open it runs in full, otherwise it does not do his job, I mean I was wrong saying it stops running, it just do not give any output unless you either switch to the desktop or you open task manager. What the application does, is taking an input file, two other variables and an output file as command line arguments, do some calculation and put the output files into the directory, it starts and then stops putting files until you do one of those two things.

Link to comment
Share on other sites

Link to comment
Share on other sites

no is not an issue with the application, because with dexpot you can assign an application to a desktop and it works, but unfortunately at the beginning it shows the application in the desktop where you are.

Link to comment
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
 Share

  • Recently Browsing   0 members

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