Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-27-2007, 12:53 PM
Junior Member
 
Join Date: Apr 2007
Posts: 22
Default Get the "Exit Code" from an application

I am running an executable and passing some parameteres on it and it is working fine.

Code:
Shell.run("C:\\test\\executable.exe 00006");
But I would like to get the EXIT CODE to determine the status of what happened. How can I do that?
Reply With Quote
  #2 (permalink)  
Old 08-28-2007, 03:17 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: Get the "Exit Code" from an application

You will have to call win32 api directly

Code:
struct { 
  unsigned long cb; 
  char* lpReserved; 
  char* lpDesktop; 
  char* lpTitle; 
  unsigned long dwX; 
  unsigned long dwY; 
  unsigned long dwXSize; 
  unsigned long dwYSize; 
  unsigned long dwXCountChars; 
  unsigned long dwYCountChars; 
  unsigned long dwFillAttribute; 
  unsigned long dwFlags; 
  unsigned short wShowWindow; 
  unsigned short cbReserved2; 
  pointer lpReserved2; 
  pointer hStdInput; 
  pointer hStdOutput; 
  pointer hStdError; 
} STARTUPINFOA;

struct { 
	unsigned long hProcess; 
	unsigned long hThread; 
	unsigned long dwProcessId; 
	unsigned long dwThreadId; 
} PROCESS_INFORMATION; 

dllimport "kernel32.dll" stdcall Boolean CloseHandle(pointer);
dllimport "kernel32.dll" stdcall long WaitForSingleObject(pointer, unsigned int);
dllimport "kernel32.dll" stdcall Boolean GetExitCodeProcess(pointer, unsigned int *);

dllimport "kernel32.dll" stdcall Boolean CreateProcessA(
	String lpApplicationName,					// name of executable module
	String lpCommandLine,						// command line string
	pointer lpProcessAttributes,				// SD
	pointer lpThreadAttributes,					// SD
	Boolean bInheritHandles,					// handle inheritance option
	unsigned int dwCreationFlags,				// creation flags
	pointer lpEnvironment,						// new environment block
	String lpCurrentDirectory,					// current directory name
	STARTUPINFOA* lpStartupInfo,				// startup information
	PROCESS_INFORMATION* lpProcessInformation	// process information
);

var NORMAL_PRIORITY_CLASS = 0x00000020;
var IDLE_PRIORITY_CLASS = 0x00000040;
var HIGH_PRIORITY_CLASS = 0x00000080;
var REALTIME_PRIORITY_CLASS = 0x00000100;
var BELOW_NORMAL_PRIORITY_CLASS = 0x00004000;
var ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000;

var INFINITE = 0xFFFF;
var WAIT_TIMEOUT = 0x102;

function runAppWithPriority(command, priority) {
	var pi = new Object;
	pi.value = new Struct(PROCESS_INFORMATION);
	
	var si = new Struct(STARTUPINFOA);
	si.cb = si.structSize;
	
	var result = CreateProcessA(null, command, null, null, false, 
		priority, null, null, si, pi);
	
	if (!result) return false;
	
	CloseHandle(pi.value.hThread);
	CloseHandle(pi.value.hProcess);

	return true;
}

function getProcessExitCode(command) {
	var pi = new Object;
	pi.value = new Struct(PROCESS_INFORMATION);
	
	var si = new Struct(STARTUPINFOA);
	si.cb = si.structSize;
	
	var result = CreateProcessA(null, command, null, null, false, 
		NORMAL_PRIORITY_CLASS, null, null, si, pi);
		
	if (!result) return undefined;
	
	CloseHandle(pi.value.hThread);
	
	if (WaitForSingleObject(pi.value.hProcess, INFINITE) != WAIT_TIMEOUT)
	{
		var code = new Object;
		code.value = 0;
		
		GetExitCodeProcess(pi.value.hProcess, code);
	
		CloseHandle(pi.value.hProcess);
		
		return code.value;
	}
	
	CloseHandle(pi.value.hProcess);
	return undefined;
}

trace(getProcessExitCode("notepad.exe"));
Reply With Quote
  #3 (permalink)  
Old 08-28-2007, 11:04 AM
Junior Member
 
Join Date: Apr 2007
Posts: 22
Default Re: Get the "Exit Code" from an application

I copy pasted the code to my .as file but didn't work, I suppose I will have to put the code that you gave me inside the SCRIPT of my .skp file but I have no previous experience (I mainly code SWFKit commands from my .as files). Can you give me some guidelines on how to execute this last part from .as files:

Code:
Global.trace(getProcessExitCode("notepad.exe"));
and put all the rest in a script file?
Reply With Quote
  #4 (permalink)  
Old 08-30-2007, 12:03 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: Get the "Exit Code" from an application

Please download swfkit pro 3.2, and paste the above code into the "initialize" script. Now you can call the method in actionscript, as shown in the following code
Code:
import SWFKit.*;

var g = new Global;
Global.trace(g.getProcessExitCode("notepad.exe"));
Reply With Quote
  #5 (permalink)  
Old 09-01-2007, 09:15 AM
Junior Member
 
Join Date: Apr 2007
Posts: 22
Default Re: Get the "Exit Code" from an application

CODE INSIDE INITIALIZE SCRIPT, in my .skp file:
Code:
//Initialize
struct { 
  unsigned long cb; 
  char* lpReserved; 
  char* lpDesktop; 
  char* lpTitle; 
  unsigned long dwX; 
  unsigned long dwY; 
  unsigned long dwXSize; 
  unsigned long dwYSize; 
  unsigned long dwXCountChars; 
  unsigned long dwYCountChars; 
  unsigned long dwFillAttribute; 
  unsigned long dwFlags; 
  unsigned short wShowWindow; 
  unsigned short cbReserved2; 
  pointer lpReserved2; 
  pointer hStdInput; 
  pointer hStdOutput; 
  pointer hStdError; 
} STARTUPINFOA;

struct { 
	unsigned long hProcess; 
	unsigned long hThread; 
	unsigned long dwProcessId; 
	unsigned long dwThreadId; 
} PROCESS_INFORMATION; 

dllimport "kernel32.dll" stdcall Boolean CloseHandle(pointer);
dllimport "kernel32.dll" stdcall long WaitForSingleObject(pointer, unsigned int);
dllimport "kernel32.dll" stdcall Boolean GetExitCodeProcess(pointer, unsigned int *);

dllimport "kernel32.dll" stdcall Boolean CreateProcessA(
	String lpApplicationName,					// name of executable module
	String lpCommandLine,						// command line string
	pointer lpProcessAttributes,				// SD
	pointer lpThreadAttributes,					// SD
	Boolean bInheritHandles,					// handle inheritance option
	unsigned int dwCreationFlags,				// creation flags
	pointer lpEnvironment,						// new environment block
	String lpCurrentDirectory,					// current directory name
	STARTUPINFOA* lpStartupInfo,				// startup information
	PROCESS_INFORMATION* lpProcessInformation	// process information
);

var NORMAL_PRIORITY_CLASS = 0x00000020;
var IDLE_PRIORITY_CLASS = 0x00000040;
var HIGH_PRIORITY_CLASS = 0x00000080;
var REALTIME_PRIORITY_CLASS = 0x00000100;
var BELOW_NORMAL_PRIORITY_CLASS = 0x00004000;
var ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000;

var INFINITE = 0xFFFF;
var WAIT_TIMEOUT = 0x102;

function runAppWithPriority(command, priority) {
	var pi = new Object;
	pi.value = new Struct(PROCESS_INFORMATION);
	
	var si = new Struct(STARTUPINFOA);
	si.cb = si.structSize;
	
	var result = CreateProcessA(null, command, null, null, false, 
		priority, null, null, si, pi);
	
	if (!result) return false;
	
	CloseHandle(pi.value.hThread);
	CloseHandle(pi.value.hProcess);

	return true;
}

function getProcessExitCode(command) {
	var pi = new Object;
	pi.value = new Struct(PROCESS_INFORMATION);
	
	var si = new Struct(STARTUPINFOA);
	si.cb = si.structSize;
	
	var result = CreateProcessA(null, command, null, null, false, 
		NORMAL_PRIORITY_CLASS, null, null, si, pi);
		
	if (!result) return undefined;
	
	CloseHandle(pi.value.hThread);
	
	if (WaitForSingleObject(pi.value.hProcess, INFINITE) != WAIT_TIMEOUT)
	{
		var code = new Object;
		code.value = 0;
		
		GetExitCodeProcess(pi.value.hProcess, code);
	
		CloseHandle(pi.value.hProcess);
		
		return code.value;
	}
	
	CloseHandle(pi.value.hProcess);
	return undefined;
}

getAdditionalFile();
return true;
CODE INSIDE FLASH FILES
Code:
var g = new Global;
Global.trace(g.getProcessExitCode("notepad.exe"));
Returns undefined.

I am using flash cs3 in AS2 file, SWFKit 3.2 and compile via Commands | swfkit_previewapp
Reply With Quote
  #6 (permalink)  
Old 09-01-2007, 01:12 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: Get the "Exit Code" from an application

Please try the attached sample.
Reply With Quote
  #7 (permalink)  
Old 09-03-2007, 05:45 AM
Junior Member
 
Join Date: Apr 2007
Posts: 22
Default Re: Get the "Exit Code" from an application

Sorry, no luck (I saw that you worked in Flash 8 ).

It returns "undefined" plus it doesn't open any window of notepad.

Testing in SWFKit 3.2, Flash CS3.

Maybe I am missing the "dll" files that you are importing.
Reply With Quote
  #8 (permalink)  
Old 09-04-2007, 06:47 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: Get the "Exit Code" from an application

You will have to use SWFKit Pro, as the Dll object is only supported in SWFKit Pro.
Reply With Quote
  #9 (permalink)  
Old 09-13-2007, 12:12 PM
Junior Member
 
Join Date: Apr 2007
Posts: 22
Default Re: Get the "Exit Code" from an application

I am using SWFKit Pro 3.2. Sorry I didn't mention it before.
Reply With Quote
  #10 (permalink)  
Old 09-14-2007, 02:40 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: Get the "Exit Code" from an application

It is really weird. Have you tested it with other applications? The "kernel32.dll" is a system file, which must exist on any Windows computer.
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:32 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.