Sign in to follow this  
Followers 0
wolf9228

WINAPI_CreateProcess

5 posts in this topic

#1 ·  Posted (edited)

WINAPI_CreateProcess

#include <StructureConstants.au3>








$ProcessID = WINAPI_CreateProcess("Command.exe","/Q /F",@ScriptDir & "\")
$ProcessID = WINAPI_CreateProcess("Command.exe",0,@ScriptDir & "\")
$ProcessID = WINAPI_CreateProcess(@ScriptDir & "\Command.exe",0,0)
$ProcessID = WINAPI_CreateProcess(@ScriptDir & "\Command.exe","/Q /F",0)


Func WINAPI_CreateProcess( _
                    $lpApplicationName = 0, _
                    $lpCommandLine = 0, _
                    $lpCurrentDirectory = 0 , _
                    $lpProcessAttributes = 0, _
                    $lpThreadAttributes = 0, _
                    $bInheritHandles = True, _
                    $dwCreationFlags = 0, _
                    $lpEnvironment = 0 )
;CreateProcess Function
;http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
Local $VarType1,$VarType2,$lpStartupInfo,$StartupInfo,$lpProcessInformation,$ProcessInformation


if Not IsString($lpApplicationName) Or $lpApplicationName  == "" Then
$lpApplicationName = 0
$VarType1 = "int"
Else
$VarType1 = "str"
EndIf
if Not IsString($lpCommandLine) Or $lpCommandLine == "" Then
$lpCommandLine = 0
$VarType2 = "int"
Else
$lpCommandLine = " " & $lpCommandLine & " "
$VarType2 = "str"
EndIf
if Not IsString($lpCurrentDirectory) Or $lpCurrentDirectory == "" Then
$lpCurrentDirectory = 0
$VarType3 = "int"
Else
$VarType3 = "str"
EndIf


$StartupInfo = DllStructCreate($tagSTARTUPINFO)
DllStructSetData($StartupInfo,"Size",DllStructGetSize($StartupInfo))
$lpStartupInfo = DllStructGetPtr($StartupInfo)
$ProcessInformation = DllStructCreate($tagPROCESS_INFORMATION)
$lpProcessInformation = DllStructGetPtr($ProcessInformation)

$BOOL = DllCall("Kernel32.dll","int","CreateProcess",$VarType1,$lpApplicationName,$VarType2,$lpCommandLine , _
"ptr",$lpProcessAttributes,"ptr",$lpThreadAttributes,"int",$bInheritHandles,"long",$dwCreationFlags , _
"ptr",$lpEnvironment ,$VarType3,$lpCurrentDirectory,"ptr",$lpStartupInfo,"ptr",$lpProcessInformation)
if @error Then Return SetError(@error,0,0)
if $BOOL[0] = 0 Then SetError(@error,0,$BOOL[0])
Return SetError(@error,0,DllStructGetData($ProcessInformation,"ProcessID"))
EndFunc

Command.exe

If $CMDLINE[0] > 0 Then
$TXT = ""
For $i = 1 To $CMDLINE[0] Step 1
$TXT = $TXT & " " & $CMDLINE[$i]
Next
MsgBox(0,"lpCommandLine",$TXT)
Else
MsgBox(0,"lpCommandLine","No CommandLine")
EndIf
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$ProcessID = WINAPI_CreateProcess("Command.exe","/Q /F",@ScriptDir)

Don`t work.

EDIT:

I use Windows XP.

EDIT2:

What's wrong with ShellExecute() or Run()?

Also In Autoit library The Function does not work correctly

LPCTSTR mean A part In Autoit But there is something else in this Function

Try this code

#include <StructureConstants.au3>
$ProcessID = WINAPI_CreateProcess("Command.exe","/Q /F",@ScriptDir & "\")
$ProcessID = WINAPI_CreateProcess("Command.exe",0,@ScriptDir & "\")
$ProcessID = WINAPI_CreateProcess(@ScriptDir & "\Command.exe",0,0)
$ProcessID = WINAPI_CreateProcess(@ScriptDir & "\Command.exe","/Q /F",0)


Func WINAPI_CreateProcess( _
                    $lpApplicationName = 0, _
                    $lpCommandLine = 0, _
                    $lpCurrentDirectory = 0 , _
                    $lpProcessAttributes = 0, _
                    $lpThreadAttributes = 0, _
                    $bInheritHandles = True, _
                    $dwCreationFlags = 0, _
                    $lpEnvironment = 0 )
;CreateProcess Function
;http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
Local $VarType1,$VarType2,$lpStartupInfo,$StartupInfo,$lpProcessInformation,$ProcessInformation


if Not IsString($lpApplicationName) Or $lpApplicationName  == "" Then
$lpApplicationName = 0
$VarType1 = "int"
Else
$VarType1 = "str"
EndIf
if Not IsString($lpCommandLine) Or $lpCommandLine == "" Then
$lpCommandLine = 0
$VarType2 = "int"
Else
$lpCommandLine = " " & $lpCommandLine & " "
$VarType2 = "str"
EndIf
if Not IsString($lpCurrentDirectory) Or $lpCurrentDirectory == "" Then
$lpCurrentDirectory = 0
$VarType3 = "int"
Else
$VarType3 = "str"
EndIf


$StartupInfo = DllStructCreate($tagSTARTUPINFO)
DllStructSetData($StartupInfo,"Size",DllStructGetSize($StartupInfo))
$lpStartupInfo = DllStructGetPtr($StartupInfo)
$ProcessInformation = DllStructCreate($tagPROCESS_INFORMATION)
$lpProcessInformation = DllStructGetPtr($ProcessInformation)

$BOOL = DllCall("Kernel32.dll","int","CreateProcess",$VarType1,$lpApplicationName,$VarType2,$lpCommandLine , _
"ptr",$lpProcessAttributes,"ptr",$lpThreadAttributes,"int",$bInheritHandles,"long",$dwCreationFlags , _
"ptr",$lpEnvironment ,$VarType3,$lpCurrentDirectory,"ptr",$lpStartupInfo,"ptr",$lpProcessInformation)
if @error Then Return SetError(@error,0,0)
if $BOOL[0] = 0 Then SetError(@error,0,$BOOL[0])
Return SetError(@error,0,DllStructGetData($ProcessInformation,"ProcessID"))
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What's wrong with ShellExecute() or Run()?

These two function Working With the WINAPI functions

Meaning that they are A String Data In Autoit

Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

What's wrong with ShellExecute() or Run()?

These two function Working With the WINAPI functions

Meaning that they are A String Data In Autoit

You understand that you say? I suggest you a more detailed look into the matter. The Run() function is based on CreateProcess() API function. Anyway, without much need no sense to avoid use of native AutoIt functions.

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