Apparently there is a more direct way to do this using WinAPI. It revolves around Window's stations. If you set the lpDesktop member of the StartupInfo struct to an empty string which is different from a null(unintialized value) then windows will create a WindowStation which doesn't interact with the desktop by default. However its theroretical. I attempted this but I have little knowledge of DLL structs and DLL calls but I can share my research.
Read the green people!
__________________________________________________________________________________________________
http://msdn.microsoft.com/en-us/library/ms684859%28v=vs.85%29.aspx
If a window station name was specified in the lpDesktop member of the STARTUPINFO structure that was used when the process was created, the process connects to the specified window station.
Otherwise, if the process is running in the logon session of the interactive user, the process connects to the interactive window station.
If the open operation fails because this window station does not exist, the system tries to create the window station and a default desktop.
If you omit the "Desktop" value for the struct then Windows should connect the process to the default station and desktop object which is "winsta0default" unless the calling process isn't using the default station and desktop, because of inheritance.
http://msdn.microsoft.com/en-us/library/ms687105%28v=vs.85%29.aspx
When a noninteractive process such as a service application attempts to connect to a window station and no window station exists for the process logon session, the system attempts to create a window station and desktop for the session.
Translation: When a process attempts to connect to a non-existent window station the system attempts to create one for you!
If a service is running in the security context of the LocalSystem account but does not include the SERVICE_INTERACTIVE_PROCESS attribute, it uses the following window station and desktop: Service-0x0-3e7$default. This window station is not interactive, so the service cannot display a user interface. In addition, processes created by the service cannot display a user interface.
I'm not so concerned with the security context or naming convention as I wouldn't have the name of the station at process creation time, you can't specify a name without admin rights that I know of. My interest is that it suggests that the dwflag SERVICE_INTERACTIVE_PROCESS is used at process creation time by services that are user interactive. It suggests that the system doesn't create interactive window stations by default.
__________________________________________________________________________________________________
So I think its safe to say that this code will do just as good as the previous.
#include <WinAPI.au3>
#include <WinAPIEx.au3>
ConsoleWrite("!>Return: " & _RunProcessHidden(@SystemDir & '\calc.exe') & @CRLF & "!>@error: " & @error & @CRLF & "!>@extended: " & @CRLF)
Func _RunProcessHidden($sProcessName, $sParam = 0)
Local $tStartupInfo = DllStructCreate($tagStartupInfo)
DllStructSetData($tStartupInfo, "Size", DllStructGetSize($tStartupInfo))
Local $tProcessInfo = DllStructCreate($tagPROCESS_INFORMATION)
If Not DllStructSetData($tStartupInfo, "Desktop", _WinAPI_CreateString("AutoItHidden")) Then Return SetError(2, @error, "")
_WinAPI_CreateProcess($sProcessName, $sParam, 0, 0, True, 0, 0, 0, DllStructGetPtr($tStartupInfo), DllStructGetPtr($tProcessInfo))
If @error Then Return SetError(3, _WinAPI_GetLastError(), "")
Local $aPID = DllCall("Kernel32.dll", "dword", "GetProcessId", "handle", DllStructGetData($tProcessInfo, "hProcess"))
Return $aPID[0]
EndFunc
It seems that the error that I get only happens when executing PortablePutty.exe using this code..............Help?
Edit - I've confirmed that this works using the following compiled script on Windows 7 Professional 64bit.
GUISetState(@SW_SHOW, GUICreate("Test"))
For $i = 0 To 99
FileWriteLine(@DesktopDir & "\Test.txt", "Test" & @CRLF)
Sleep(50)
Next
Exit
No system tray icon, etc.
Anonymous