Sign in to follow this  
Followers 0
heartkey

CreateProcessW Struct

7 posts in this topic

Hi guys, and firstly, Happy New Year :evil: ,

So here's my problem:

I'm trying since long to call the "CreateProcessW" kernel32.dll in order to start a new program in another desktop location , but the function in question doesn't like my structure...;)

Here's the code:

#include <Winapi.au3>

Desk_StartProgram("c:\windows\explorer.exe", "c:\windows\", "Test") ;"Test" is the name given to the desktop in which the program must be displayed, of course I created the named desktop  before. 

Func Desk_StartProgram($hPath, $hCurrentdir, $hDesktop)

        Local $tSTARTUPINFO = DllStructCreate("dword  cbSize;" & _
            "ptr Reserved;" & _
            "ptr Title;" & _
            "str Desktop;" & _ ; When the "str" of this line is replaced by "ptr" the program is running properly, however it remains in the current desktop (default) 
            "dword X;" & _
            "dword Y;" & _
            "dword XSize;" & _
            "dword YSize;" & _
            "dword XCountChars;" & _
            "dword YCountChars;" & _
            "dword FillAttribute;" & _
            "dword Flags;" & _
            "ushort ShowWindow;" & _
            "ushort Reserved2;" & _
            "ptr Reserved2;" & _
            "ptr hStdInput;" & _
            "ptr hStdOutput;" & _
            "ptr hStdError")

            MsgBox(0,"",_WinAPI_GetLastErrorMessage()) ;returns "The operation was successful." 
            DllStructSetData($tSTARTUPINFO, "Desktop", $hDesktop)
            MsgBox(0,"",_WinAPI_GetLastErrorMessage()) ; returns "The operation was successful." 

    Local $tPROCESS_INFORMATION = DllStructCreate("ptr Process;" & _
            "ptr Thread;" & _
            "dword ProcessId;" & _
            "dword ThreadId")

        $aCall = DllCall("kernel32.dll", "int", "CreateProcessW", _
            "wstr", $hPath, _
            "wstr", "", _ ; CMDLINE
            "ptr", 0, _
            "ptr", 0, _
            "int", 0, _
            "dword", 4, _ ; deliberately pre-hung 
            "ptr", 0, _
            "wstr", $hCurrentdir, _ ; Curent Dir
            "ptr", DllStructGetPtr($tSTARTUPINFO), _
            "ptr", DllStructGetPtr($tPROCESS_INFORMATION))

    If @error Or Not $aCall[0] Then
        MsgBox(0,"",_WinAPI_GetLastErrorMessage()) ; returns "The parameter is incorrect." 
        Return SetError(1, 0, 0)
    EndIf

    Local $hThread = DllStructGetData($tPROCESS_INFORMATION, "Thread")
    DllCall("kernel32.dll", "int", "ResumeThread", "ptr", $hThread)
    Return DllStructGetData($tPROCESS_INFORMATION, "ProcessId")
EndFunc

Hoping someone can give me help, because I despair of being able to succeed one day ...

Cheers, Heartkey

Share this post


Link to post
Share on other sites



Hi,

My reply on the French forum didn't find its way; don't know why.

Compare with this thread where Trancexx creates a process (this is the code in code tags, not the attached file).

Now str will convert an AutoIt string into ANSI (1char = 1byte) as opposed to wstr where 1 [unicode] char = 1 or 2 16-bit word.

Happy New ProcessW


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

That should always be pointer. It's "ptr Desktop;"

Func Desk_StartProgram($hPath, $hCurrentdir, $sDesktop)

        Local $tSTARTUPINFO = DllStructCreate("dword  cbSize;" & _
            "ptr Reserved;" & _
            "ptr Title;" & _
            "ptr Desktop;" & _
            "dword X;" & _
            "dword Y;" & _
            "dword XSize;" & _
            "dword YSize;" & _
            "dword XCountChars;" & _
            "dword YCountChars;" & _
            "dword FillAttribute;" & _
            "dword Flags;" & _
            "ushort ShowWindow;" & _
            "ushort Reserved2;" & _
            "ptr Reserved2;" & _
            "ptr hStdInput;" & _
            "ptr hStdOutput;" & _
            "ptr hStdError")

            Local $tDesktop = DllStructCreate("wchar[" & StringLen($sDesktop) + 1 & "]")
            DllStructSetData($tDesktop, 1, $sDesktop)
            DllStructSetData($tSTARTUPINFO, "Desktop", DllStructGetPtr($tDesktop))
;...

Or something like that.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thank you for these answers,

trancexx solution works well (run the program properly) but in the current desktop ...

Thanks, Anthony.

PS: The CPP source code :

bool CDesktopManager::LaunchApplication(TCHAR *pszApplicationFilePath, TCHAR *pszDesktopName)
{
    bool bReturn = false;

    try
    {
        TCHAR szDirectoryName[ARRAY_SIZE] = {0};
        TCHAR szExplorerFile[ARRAY_SIZE]= {0};

        _tcscpy_s(szDirectoryName, _tcslen(pszApplicationFilePath) + 1, pszApplicationFilePath);

        PathRemoveFileSpec(szDirectoryName);

        STARTUPINFO sInfo = {0};
        PROCESS_INFORMATION pInfo = {0};

        sInfo.cb = sizeof(sInfo);
        sInfo.lpDesktop = pszDesktopName;

        //Lanuching a application into dekstop
        BOOL bCreateProcessReturn = CreateProcess(pszApplicationFilePath, 
            NULL, 
            NULL, 
            NULL, 
            TRUE, 
            NORMAL_PRIORITY_CLASS, 
            NULL, 
            szDirectoryName, 
            &sInfo, 
            &pInfo);

        TCHAR *pszError = NULL;
        bReturn = true;
    }
    return bReturn;
}
Edited by heartkey

Share this post


Link to post
Share on other sites

cbSize member is not set.

If that doesn't help, check that the new desktop is ok.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

And the desktop is ok...;)

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  
Followers 0