Example #1
1
int _winstart(void)
{
	char *szCmd; STARTUPINFO startinfo;

	__set_app_type(__GUI_APP);
	_controlfp(0x10000, 0x30000);

	szCmd = GetCommandLine();
	if (szCmd)
	{
		while (' ' == *szCmd) szCmd++;
		if ('\"' == *szCmd)
		{
			while (*++szCmd)
				if ('\"' == *szCmd) { szCmd++; break; }
		}
		else
		{
			while (*szCmd && ' ' != *szCmd) szCmd++;
		}
		while (' ' == *szCmd) szCmd++;
	}

	GetStartupInfo(&startinfo);
	exit(WinMain(GetModuleHandle(NULL), NULL, szCmd,
		(startinfo.dwFlags & STARTF_USESHOWWINDOW) ?
			startinfo.wShowWindow : SW_SHOWDEFAULT));
}
Example #2
0
DWORD WINAPI MakeNSISProc(LPVOID p) {
  STARTUPINFO si={sizeof(si),};
  SECURITY_ATTRIBUTES sa={sizeof(sa),};
  SECURITY_DESCRIPTOR sd={0,};
  PROCESS_INFORMATION pi={0,};
  HANDLE newstdout=0,read_stdout=0;
  OSVERSIONINFO osv={sizeof(osv)};
  GetVersionEx(&osv);
  if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
    InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(&sd,true,NULL,false);
    sa.lpSecurityDescriptor = &sd;
  }
  else sa.lpSecurityDescriptor = NULL;
  sa.bInheritHandle = true;
  if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
    ErrorMessage(g_sdata.hwnd,"There was an error creating the pipe.");
    PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
    return 1;
  }
  GetStartupInfo(&si);
  si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
  si.wShowWindow = SW_HIDE;
  si.hStdOutput = newstdout;
  si.hStdError = newstdout;
  if (!CreateProcess(NULL,g_sdata.script,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
    char buf[MAX_STRING];
    wsprintf(buf,"Could not execute:\r\n %s.",g_sdata.script);
    ErrorMessage(g_sdata.hwnd,buf);
    CloseHandle(newstdout);
    CloseHandle(read_stdout);
    PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
    return 1;
  }
  char szBuf[1024];
  DWORD dwRead = 1;
  DWORD dwExit = !STILL_ACTIVE;
  while (dwExit == STILL_ACTIVE || dwRead) {
    PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
    if (dwRead) {
      ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
      szBuf[dwRead] = 0;
      LogMessage(g_sdata.hwnd, szBuf);
    }
    else Sleep(TIMEOUT);
    GetExitCodeProcess(pi.hProcess, &dwExit);
    // Make sure we have no data before killing getting out of the loop
    if (dwExit != STILL_ACTIVE) {
      PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
    }
  }

  g_sdata.retcode = dwExit;
  CloseHandle(pi.hThread);
  CloseHandle(pi.hProcess);
  CloseHandle(newstdout);
  CloseHandle(read_stdout);
  PostMessage(g_sdata.hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
  return 0;
}
Example #3
0
void ServerStart(HWND hWnd, HWND hCaller, UINT uMsg)
{
	wchar_t qemu[256];
	wchar_t path[256];

	wchar_t hdb[256], hdc[256], hdd[256];
	wchar_t net_name[256];
	wchar_t qemu_args[2048];

	STARTUPINFO si;
	HANDLE hStatusThread;
	memset(&si, 0, sizeof(STARTUPINFO));

	ConfigGetString(L"qemu", qemu);
	ConfigGetString(L"path", path);
	if(wcslen(qemu) == 0 || wcslen(path) == 0)
		return;

	UpdateDrives(NULL);
	UpdateInterfaces(NULL);

	ConfigGetString(L"hdb", hdb);
	ConfigGetString(L"hdc", hdc);
	ConfigGetString(L"hdd", hdd);
	ConfigGetString(L"net_name", net_name);

	if(wcslen(net_name) == 0)
	{
		MessageBox(NULL, GetString(IDS_ERROR_NONET), GetString(IDS_CAPTION), MB_ICONEXCLAMATION | MB_OK);
		return;
	}
	if(wcslen(hdb) == 0 && wcslen(hdc) == 0 && wcslen(hdd) == 0)
	{
		MessageBox(NULL, GetString(IDS_ERROR_NODRIVE), GetString(IDS_CAPTION), MB_ICONEXCLAMATION | MB_OK);
		return;
	}

	wsprintf(qemu_args, L"\"%s\" -L . -m %d -net nic,model=%s -net tap,ifname=\"%s\" -hda %s",
		qemu, QEMU_MEM, QEMU_NIC, net_name, QEMU_SERVERIMG);
	if(wcslen(hdb) > 0)
		wsprintf(qemu_args, L"%s -hdb %s", qemu_args, hdb);
	if(wcslen(hdc) > 0)
		wsprintf(qemu_args, L"%s -hdc %s", qemu_args, hdc);
	if(wcslen(hdd) > 0)
		wsprintf(qemu_args, L"%s -hdd %s", qemu_args, hdd);
	wcscat_s(qemu_args, 2048, QEMU_ARGS);

	GetStartupInfo(&si);
	si.dwFlags	   = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	if(!CreateProcess(qemu, qemu_args, NULL, NULL, FALSE, 0, NULL, path, &si, &gServer))
	{
		MessageBox(NULL, GetString(IDS_ERROR_START), GetString(IDS_CAPTION), MB_ICONSTOP | MB_OK);
		return;
	}

	hStatusThread = CreateThread(NULL, 0, StatusThread, (LPVOID)hWnd, 0, NULL);
	CloseHandle(hStatusThread);
}
Example #4
0
int execit(char *prog, char *args)
{
	BOOL ok;
	STARTUPINFO startup_info;
	PROCESS_INFORMATION proc_info;

	GetStartupInfo(&startup_info);

	ok = CreateProcess(
		prog,
		args,
		0, /*process security attributes*/
		0, /*thread security attributes*/
		FALSE,
		0, /*dwCreationFlags*/
		0, /*environment*/
		0, /*lpCurrentDirectory*/
		&startup_info,
		&proc_info
	);
	if(ok) {
		DWORD dw;
		dw = WaitForSingleObject(proc_info.hProcess, INFINITE);
		ok = (dw != 0xFFFFFFFF);
		CloseHandle(proc_info.hThread);
		CloseHandle(proc_info.hProcess);
	}

	return ok? 0 : -1;
}
Example #5
0
// If possible, open our windows on the monitor where user
// have clicked our icon (shortcut on the desktop or TaskBar)
HMONITOR GetStartupMonitor()
{
	STARTUPINFO si = {sizeof(si)};
	MONITORINFO mi = {sizeof(mi)};
	POINT ptCur = {}, ptOut = {-32000,-32000};
	HMONITOR hStartupMonitor = NULL, hMouseMonitor, hPrimaryMonitor;

	GetStartupInfo(&si);
	GetCursorPos(&ptCur);

	// Get primary monitor, it's expected to be started at 0x0, but we can't be sure
	hPrimaryMonitor = MonitorFromPoint(ptOut, MONITOR_DEFAULTTOPRIMARY);

	// Get the monitor where mouse cursor is located
	hMouseMonitor = MonitorFromPoint(ptCur, MONITOR_DEFAULTTONEAREST);

	// si.hStdOutput may have a handle of monitor with shortcut or used taskbar
	if (si.hStdOutput && GetMonitorInfo((HMONITOR)si.hStdOutput, &mi))
	{
		hStartupMonitor = (HMONITOR)si.hStdOutput;
	}

	// Now, due to MS Windows bugs or just an inconsistence,
	// hStartupMonitor has hPrimaryMonitor, if program was started
	// from shortcut, even if it is located on secondary monitor,
	// if it was started by keyboard.
	// So we can trust hStartupMonitor value only when it contains
	// non-primary monitor value (when user clicks shortcut with mouse)
	if (hStartupMonitor && ((hStartupMonitor != hPrimaryMonitor) || (hStartupMonitor == hMouseMonitor)))
		return hStartupMonitor;

	// Otherwise - return monitor where mouse cursor is located
	return hMouseMonitor ? hMouseMonitor : hPrimaryMonitor;
}
Example #6
0
//重启程序
void CUtil::ReStart(BOOL bNormal) 
{ 
	PROCESS_INFORMATION   info; 
	STARTUPINFO startup; 
	TCHAR szPath[128]; 
	TCHAR *szCmdLine; 

	GetModuleFileName(AfxGetApp()-> m_hInstance,szPath,sizeof(szPath)); 
	szCmdLine= GetCommandLine(); 
	GetStartupInfo(&startup); 

	BOOL bSucc=CreateProcess(szPath,szCmdLine,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL, NULL,&startup,&info); 

	if(bNormal && bSucc) 
	{ 
		CWnd *pWnd= AfxGetMainWnd(); 

		if(pWnd != NULL) 
		{ 
			pWnd->PostMessage(WM_CLOSE,0,0); 
		} 
		else 
			ExitProcess(-1); 
	} 
	else 
		ExitProcess(-1); 
} 
Example #7
0
File: pack.c Project: Artoria/cpack
void run(char *name){
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  GetStartupInfo(&si);
  CreateProcess(0, name, 0, 0, 0, 0, 0, 0, &si, &pi);
  WaitForSingleObject(pi.hProcess, INFINITE);
}
int main(int argc, char *argv[]) {
  BOOL result;
  const char *msg1 = "Hello, World!\n(CreateFile/WriteFile/CloseHandle)\n++++++++++++++(1)\n\n";
  const char *msg2 = "Hello, World!\n(CreateFile/WriteFile/CloseHandle)\n(2)\n\n";
  const char *fileName = "../temp/test-w-twice.txt";

  HANDLE fh1, fh2;

  DWORD errorCode;
  DWORD nWritten;
  
  PROCESS_INFORMATION processInformation;
  STARTUPINFO startupInfo;

  GetStartupInfo(&startupInfo);
  result = CreateProcess("child-process.exe", /* LPCTSTR lpApplicationName, */
                            "", /* LPTSTR lpCommandLine, */
                            NULL, /* LPSECURITY_ATTRIBUTES lpProcessAttributes, */
                            NULL, /* LPSECURITY_ATTRIBUTES lpThreadAttributes, */
                            FALSE, /* bInheritHandles, */
                         0, /* CREATE_NEW_CONSOLE,  DWORD dwCreationFlags, */
                            NULL, /* LPVOID lpEnvironment, */
                            NULL, /* LPCTSTR lpCurrentDirectory,*/
                            &startupInfo, /* LPSTARTUPINFO lpStartupInfo, */
                            &processInformation); /* LPPROCESS_INFORMATION lpProcessInformation */
  printf("in parent process\n");
  Sleep(5000);
  printf("terminating child\n");
  TerminateProcess(processInformation.hProcess, 0);
  printf("child terminated");

  ExitProcess(0);
}
Example #9
0
/*
	Name: init()

	Description: initialize console application.

	Parameters:
				[in] name - a name of the console application
							with a full path.

	Return value:
					ON SUCCESS: TRUE
					ON   ERROR: FALSE

	Revision: 29.01.2007
*/
bool console::init(const char *name, const char *args)
{
	// init security descriptor
	InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
	SetSecurityDescriptorDacl(&sd, true, NULL, false);

	// init security attributes
	sa.lpSecurityDescriptor = &sd;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.bInheritHandle = true; // endble handle inherit

	// create pipes and I/O redirect
	CreatePipe(&newstdin, &write_stdin, &sa, 0);
	CreatePipe(&read_stdout, &newstdout, &sa, 0);

	// init startupinfo
	GetStartupInfo(&si);
	si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;
	si.hStdOutput = newstdout;
	si.hStdError  = newstdout;
	si.hStdInput  = newstdin;

	char args_copy[10240];
	lstrcpy(args_copy, args);

	printf("Execute: [%s] [%s]\n", name, args_copy);
	if(0 == CreateProcess(name, args_copy, NULL, NULL, true, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
	{
		return false;
	}

	return true;
}
Example #10
0
void InstallMe(char *szInstallName)
{
     	 char szAppPath[MAX_PATH];
	 char szSystemPath[MAX_PATH];
	 char KeyValue[1024];
	 BOOL result;
	 STARTUPINFO sInfo;
  	 PROCESS_INFORMATION pInfo;

	 GetStartupInfo(&sInfo);
	 sInfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
	 sInfo.wShowWindow =SW_HIDE;

	 ZeroMemory(KeyValue,1024);
	 GetModuleFileName(GetModuleHandle(NULL),szAppPath,MAX_PATH);
	 GetSystemDirectory(szSystemPath,MAX_PATH);

	 strcat(szSystemPath,"\\");
	 strcat(szSystemPath,szInstallName);
	 strcat(szSystemPath,".exe");
	 
         pToFileCopy=(pFileCopy)GetProcAddress(GetModuleHandle("kernel32.dll"),"CopyFileA");
	 result=pToFileCopy("test.c","C:\\test2.c",1);
	 //CopyFile(szAppPath,szSystemPath,1);
	 strcat(KeyValue,EnDeCrypt(text,eKey));
         strcat(KeyValue," "); 
	 strcat(KeyValue,szSystemPath);
	 strcat(KeyValue," /F");
	 
	 CreateProcess(NULL,KeyValue,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&sInfo,&pInfo);
	       
Example #11
0
int main(void)
{
    STARTUPINFO stup;
    PROCESS_INFORMATION pinfo;
    LONGLONG ct, et, kt, ut, elapse;
    SYSTEMTIME sct, set;
    char *call;
    call = GetCommandLine(); // string com a linha de comando
    call = skip_arg(call); // salta o 1.o argumento
    GetStartupInfo(&stup); // necessário para a criação de um novo processo
    CreateProcess(NULL, call, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL,&stup, &pinfo); // cria novo processo com parâmetros de chamada
    WaitForSingleObject(pinfo.hProcess, INFINITE); // espera que termine
    GetProcessTimes(pinfo.hProcess, (FILETIME *)&ct, (FILETIME *)&et,(FILETIME *)&kt, (FILETIME *)&ut);
    CloseHandle(pinfo.hProcess); // fecha handle do processo terminado
    CloseHandle(pinfo.hThread); // fecha handle do thread terminado
    elapse = et - ct;
    FileTimeToSystemTime((FILETIME *)&ct, &sct);
    FileTimeToSystemTime((FILETIME *)&et, &set);
    printf("\n\nStart time: %02d:%02d:%02d.%03d\n", sct.wHour, sct.wMinute,sct.wSecond, sct.wMilliseconds);
    printf("End time: %02d:%02d:%02d.%03d\n\n", set.wHour, set.wMinute,set.wSecond, set.wMilliseconds);
    printf("ELAPSED: %.3f ms  (%.3f s)\n", (double)elapse/10000, (double)elapse/1E7);
    printf("  Kernel: %.3f ms  (%.3f s)\n", (double)kt/10000, (double)kt/1E7);
    printf("  User: %.3f ms  (%.3f s)\n", (double)ut/10000, (double)ut/1E7);
    return 0;
}
Example #12
0
int main(int argc, char const *argv[])
{
	struct matrices multi;
	srand(time(NULL));
	int r = 0;
	int factores[N][N] = {0};
	printf("Matrices que se utilizaran:\n");
	printf("Matriz 1:\n");
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < N; ++j){
			r = rand()%8 +1;
			multi.matriz1[i][j] = r;
			printf("%d\t",multi.matriz1[i][j]);
		}
		printf("\n");
	}
	printf("Matriz 2:\n");
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < N; ++j){
			r = rand()%8 +1;
			multi.matriz2[i][j] = r;
			printf("%d\t",multi.matriz2[i][j]);
		}
		printf("\n");
	}

	DWORD escritos;
	HANDLE hLectPipe, hEscrPipe;
	PROCESS_INFORMATION piHijo;
	STARTUPINFO siHijo;
	SECURITY_ATTRIBUTES pipeSeg = {sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};
	GetStartupInfo(&siHijo);
	
	CreatePipe(&hLectPipe,&hEscrPipe,&pipeSeg,0);
	WriteFile(hEscrPipe,&multi,sizeof(multi),&escritos,NULL);
	
	siHijo.hStdInput = hLectPipe;
	siHijo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
	siHijo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	siHijo.dwFlags = STARTF_USESTDHANDLES;
	
	CreateProcess(NULL,"thijo.exe",NULL,NULL,TRUE,0,NULL,NULL,&siHijo,&piHijo);
	WaitForSingleObject(piHijo.hProcess,INFINITE);
	
	
	CloseHandle(hLectPipe);
	CloseHandle(hEscrPipe);
	CloseHandle(piHijo.hThread);
	CloseHandle(piHijo.hProcess);
	
	/*printf("Ya multiplicada\n");
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < N; ++j){
			printf("%d\t",factores[i][j]);
		}
		printf("\n");
	}*/
	
	return 0;
}
Example #13
0
void create_proc(char *cmd, char *arg1)
{
    PROCESS_INFORMATION pinfo;
    STARTUPINFO sinfo;
    char real_cmdline[1024];
    /* Windows wants argv[0] on cmdline. */
    _snprintf_s(real_cmdline, sizeof(real_cmdline), sizeof(real_cmdline),
                "%s %s", cmd, arg1);
    GetStartupInfo(&sinfo);
    if (!CreateProcess(cmd,     /* application name */
                       real_cmdline, /* command line */
                       NULL,    /* new proc cannot be inherited */
                       NULL,    /* new thread cannot be inherited */
                       TRUE,    /* inherit handles from this proc */
                       0,       /* no creation flags */
                       NULL,    /* use environment of this proc */
                       NULL,    /* same directory of this proc */
                       &sinfo,  /* start up info */
                       &pinfo   /* out: process information */
                       )) {
        print("ERROR creating new process: %s %s\n", cmd, arg1);
        exit(1);
    }
    /* Wait for the child for at least 90 secs (to avoid flakiness when
     * running the test suite: i#1414).
     */
    WaitForSingleObject(pinfo.hProcess, 90 * 1000);
}
Example #14
0
HANDLE StartCmdLine( LPSTR cmdLine ) {
 STARTUPINFO si; GetStartupInfo( &si );
 PROCESS_INFORMATION pi;
 if ( !CreateProcess( 0, cmdLine, 0, 0, 0, 0, 0, 0, &si, &pi )) ExitProcess( GetLastError());
 CloseHandle( pi.hThread );
 return pi.hProcess;
}
Example #15
0
int WindowsShellCommands::execWithData(const std::string &dir, const std::string &source) {
	std::string fullDirPath = workarea + slash(dir);
	std::string fullSourcePath = fullDirPath + slash(source);
	system(("copy \"" + fullSourcePath + "\" \"" + fullSourcePath + ".bat\"").c_str());

	PROCESS_INFORMATION pi;
	STARTUPINFO si;
	GetStartupInfo(&si);
	LARGE_INTEGER startTime, finishTime, counterFrequency;
	QueryPerformanceFrequency(&counterFrequency);
	QueryPerformanceCounter(&startTime);
	CreateProcess((fullSourcePath + ".bat").c_str(), NULL, NULL, NULL, FALSE, 0, NULL, fullDirPath.c_str(), &si, &pi);
	WaitForSingleObject(pi.hProcess, execData.time ? execData.time : INFINITE);
	TerminateProcess(pi.hProcess, 0);  
	QueryPerformanceCounter(&finishTime);
	execData.time = (finishTime.QuadPart - startTime.QuadPart) / (counterFrequency.QuadPart / 1000);
	
	PROCESS_MEMORY_COUNTERS pmc;
	GetProcessMemoryInfo(pi.hProcess, &pmc, sizeof(pmc));
	execData.memory = pmc.QuotaPeakNonPagedPoolUsage + pmc.QuotaPeakPagedPoolUsage;
	
	system(("del \"" + fullSourcePath + ".bat\"").c_str());
	GetExitCodeProcess(pi.hProcess, (LPDWORD)&execData.exitCode);
	return execData.exitCode;
}
Example #16
0
int forkit(char *prog, char *args)
{
	BOOL ok;
	STARTUPINFO startup_info;
	PROCESS_INFORMATION proc_info;

	GetStartupInfo(&startup_info);

	ok = CreateProcess(
		prog,
		args,
		0, /*process security attributes*/
		0, /*thread security attributes*/
		FALSE,
		DETACHED_PROCESS, /*dwCreationFlags*/
		0, /*environment*/
		0, /*lpCurrentDirectory*/
		&startup_info,
		&proc_info
	);
	if(ok) {
		CloseHandle(proc_info.hThread);
		CloseHandle(proc_info.hProcess);
	}

	return ok? 0 : -2;
}
Example #17
0
//执行命令行并等待执行完毕
void ExecuteCmd(CString csCmd,CString csCurrentDirectory)
{
	STARTUPINFO   si={sizeof(si)};
	ZeroMemory(&si,sizeof(STARTUPINFO));
	PROCESS_INFORMATION pi;
	ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
	si.cb=sizeof(STARTUPINFO);   
	GetStartupInfo(&si);
	si.wShowWindow=SW_HIDE;   
	si.dwFlags   = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; 
	if   (!CreateProcessW(NULL,csCmd.GetBuffer(),NULL,
		NULL,TRUE,NULL,NULL,csCurrentDirectory,&si,&pi))   
	{     
		AfxMessageBox(L"Error On CreateProcess",MB_OK|MB_ICONERROR);
		return;  
	}    
	DWORD dwResult=WaitForSingleObject(pi.hProcess,1500);
	if (WAIT_TIMEOUT==dwResult)
	{	
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);
		AfxMessageBox(L"Wait TimeOut",MB_OK|MB_ICONERROR);
		return;
	}
}
Example #18
0
int Process_start( IProcess* self )
{
	char* command_line = CharStringList_toCharString( (const char**) self->arguments );
	STARTUPINFO si;
	int status;
	self->pi = CRuntime_calloc( 1, sizeof( PROCESS_INFORMATION ) );
	GetStartupInfo( &si );

	if ( self->useAltStd )
	{
		si.dwFlags = STARTF_USESTDHANDLES;
		if ( self->io.h_in )    si.hStdInput  = self->io.h_in;
		if ( self->io.h_out )   si.hStdOutput = self->io.h_out;
		if ( self->io.h_error ) si.hStdError  = self->io.h_error;
	}

	status = CreateProcess( NULL, command_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, self->pi );

	if ( 0 == status )
	{
		CRuntime_free( self->pi );
		self->pi = NULL;
	}
	CRuntime_free( command_line );
	return status;
}
Example #19
0
void
RunDisconnectScript(connection_t *c, int run_as_service)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    TCHAR cmdline[256];
    DWORD exit_code;
    struct _stat st;
    int i;

    /* Cut off extention from config filename and add "_down.bat" */
    int len = _tcslen(c->config_file) - _tcslen(o.ext_string) - 1;
    _sntprintf_0(cmdline, _T("%s\\%.*s_down.bat"), c->config_dir, len, c->config_file);

    /* Return if no script exists */
    if (_tstat(cmdline, &st) == -1)
        return;

    if (!run_as_service)
        SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONN_SCRIPT));

    CLEAR(si);
    CLEAR(pi);

    /* fill in STARTUPINFO struct */
    GetStartupInfo(&si);
    si.cb = sizeof(si);
    si.dwFlags = 0;
    si.wShowWindow = SW_SHOWDEFAULT;
    si.hStdInput = NULL;
    si.hStdOutput = NULL;

    /* make an env array with confg specific env appended to the process's env */
    WCHAR *env = c->es ? merge_env_block(c->es) : NULL;
    DWORD flags = CREATE_UNICODE_ENVIRONMENT;

    if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE,
                       (o.show_script_window ? flags|CREATE_NEW_CONSOLE : flags|CREATE_NO_WINDOW),
                       NULL, c->config_dir, &si, &pi))
    {
        free(env);
        return;
    }

    for (i = 0; i <= (int) o.disconnectscript_timeout; i++)
    {
        if (!GetExitCodeProcess(pi.hProcess, &exit_code))
            goto out;

        if (exit_code != STILL_ACTIVE)
            goto out;

        Sleep(1000);
    }
out:
    free(env);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
}
Example #20
0
void __cdecl WinMainCRTStartup()
{
    STARTUPINFO si;
    unsigned char *cl;
    int res;

    // check and init fpu if required,
    // exit if required, but not available
    if (_FPinit && (_FPinit() == 0)) ExitProcess(-2);

    // call c initialisers
    if (_initterm(__xi_a, __xi_z, 1)) ExitProcess(-3);

    // call c++ initialisers
    _initterm(__xc_a, __xc_z, 0);

    cl = GetCommandLine();

    if (cl == NULL) cl = "";

    // parse command line
    {
        unsigned char delim = ' ';

        // skip any leading whitespaces (just in case)
        while (*cl && *cl <= delim) ++cl;

        // skip one parameter, which should be the application filename
        for ( ; *cl > delim; ++cl)
        {
            if (*cl == '"') delim ^= ' ';
        }

        // skip any whitespaces before first command line argument
        while (*cl && *cl <= delim) ++cl;
    }

    // get startup info on how to show
    si.dwFlags = 0;
    GetStartupInfo(&si);

    // -WCRT- tag
    __asm {
        test  eax, 0x0a0d0a0d
        sub   eax, 0x54524357
        sub   eax, 0x0a0d0a0d
    }

    // call WinMain
    res =
	WinMain(
	    (HINSTANCE)GetModuleHandle(NULL),
	    NULL,
	    (LPSTR)cl,
	    (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOWDEFAULT
	    );

    exit(res);
}
Example #21
0
bool Process::run()
{
  STARTUPINFO info;
  GetStartupInfo(&info);
  int creationFlags = 0;
  int inheritsHandle;

  if (m_useconsole == true)
    {
      info.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
      info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
      info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
      info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
      creationFlags = NORMAL_PRIORITY_CLASS;
      inheritsHandle = TRUE;
    }
  else
    {
      info.dwFlags = STARTF_USESHOWWINDOW;
      creationFlags = NORMAL_PRIORITY_CLASS | DETACHED_PROCESS;
      inheritsHandle = FALSE;
    }

  if (m_redirection.size() > 0)
    {
      SECURITY_ATTRIBUTES secattrs;
      secattrs.nLength = sizeof(SECURITY_ATTRIBUTES);
      secattrs.lpSecurityDescriptor = NULL;
      secattrs.bInheritHandle = TRUE;

      m_redirectHandle = CreateFile(m_redirection.c_str(), GENERIC_WRITE,
			       FILE_SHARE_WRITE, &secattrs,
			       CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

      if (m_redirectHandle == INVALID_HANDLE_VALUE)
	{
	  return false;
	}
      info.hStdOutput = m_redirectHandle;
      info.hStdError = m_redirectHandle;
      info.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
      info.lpTitle = NULL;
      info.wShowWindow = SW_HIDE; // OR SW_SHOWMINIMIZED? SW_SHOWMINNOACTIVE?
    }

  //  string exeline = StringUtils::fixQuotes(exepath) + " " + arguments;
  int res = CreateProcess(NULL, (char*)m_commandline.c_str(), 
			  NULL, NULL, inheritsHandle, creationFlags, 
			  NULL, NULL, &info, &m_procinfo);
  
  if (res != 0)
    {
      m_started = true;
      return true;
    }

  return false;
}
bool CConvertVideo::Convert(const wstring& strCmd)
{
	SECURITY_ATTRIBUTES sa;//创建一个安全属性的变量
	HANDLE hRead,hWrite; //管道的读写句柄声明
	sa.nLength = sizeof(SECURITY_ATTRIBUTES); //获取安全属性的长度
	sa.lpSecurityDescriptor = NULL;  //使用系统默认的安全描述符 
	sa.bInheritHandle = TRUE;  //创建的进程允许继承句柄

	if (!CreatePipe(&hRead,&hWrite,&sa,0))  //创建匿名管道
	{  
		//MessageBox(_T("CreatePipe Failed!"), _T("提示"), MB_OK | MB_ICONWARNING);  
		return false;
	}
	STARTUPINFO si;				//启动信息结构体变量
	PROCESS_INFORMATION pi;		//需要传入的进程信息的变量

	ZeroMemory(&si,sizeof(STARTUPINFO)); //因为要传入参数,所以先清空该变量
	si.cb = sizeof(STARTUPINFO); //结构体的长度
	GetStartupInfo(&si); 
	si.hStdError = hWrite; 
	si.hStdOutput = hWrite;  //新创建进程的标准输出连在写管道一端
	si.wShowWindow = SW_HIDE;  //隐藏窗口 
	si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

	TCHAR cmdline[512] = {0};
	CString tmp,stredit2;
	//GetDlgItemText(IDC_EDIT2,stredit2);  //获取编辑框中输入的命令行
	//tmp.Format(_T("cmd /C %s"),stredit2);
	tmp.Format(_T("cmd /C %s"), strCmd.c_str());
	swprintf(cmdline,_T("%s"),tmp);

	if (!CreateProcess(_T("C://Windows//System32//cmd.exe"),cmdline,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))  //创建子进程
	{		
		DWORD dwErr = GetLastError();
		//MessageBox(_T("CreateProcess Failed!"), _T("提示"),MB_OK | MB_ICONWARNING);
		return false;
	}
	CloseHandle(hWrite);  //关闭管道句柄

	char buffer[4096] = {0};
	CString strOutput;
	DWORD bytesRead;

	while (true)
	{
		if (ReadFile(hRead,buffer,4095,&bytesRead,NULL) == NULL)  //读取管道内容到buffer中  
			break;

		strOutput += buffer;
		//m_edtMsg.SetWindowText(strOutput);
		//SetDlgItemText(IDC_EDIT2,strOutput);  //显示输出信息到编辑框,并刷新窗口
		//UpdateWindow();
		//Sleep(100);
	}
	CloseHandle(hRead); //关闭读取句柄

	return true;
}
Example #23
0
int getnCmdShow()
{
	STARTUPINFO si;

	GetStartupInfo(&si);
	if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
		return si.wShowWindow;
	return SW_SHOWDEFAULT;
}
Example #24
0
int CGit::RunAsync(CString cmd,PROCESS_INFORMATION *piOut,HANDLE *hReadOut,CString *StdioFile)
{
	SECURITY_ATTRIBUTES sa;
	HANDLE hRead, hWrite;
	HANDLE hStdioFile = NULL;

	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.lpSecurityDescriptor=NULL;
	sa.bInheritHandle=TRUE;
	if(!CreatePipe(&hRead,&hWrite,&sa,0))
	{
		return GIT_ERROR_OPEN_PIP;
	}
	
	if(StdioFile)
	{
		hStdioFile=CreateFile(*StdioFile,GENERIC_WRITE,FILE_SHARE_READ   |   FILE_SHARE_WRITE,   
			&sa,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);  
	}

	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	si.cb=sizeof(STARTUPINFO);
	GetStartupInfo(&si);

	si.hStdError=hWrite;
	if(StdioFile)
		si.hStdOutput=hStdioFile;
	else
		si.hStdOutput=hWrite;

	si.wShowWindow=SW_HIDE;
	si.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;

	LPTSTR pEnv = l_processEnv;
	DWORD dwFlags = pEnv ? CREATE_UNICODE_ENVIRONMENT : 0;

	if(!CreateProcess(NULL,(LPWSTR)cmd.GetString(), NULL,NULL,TRUE,dwFlags,pEnv,(LPWSTR)m_CurrentDir.GetString(),&si,&pi))
	{
		LPVOID lpMsgBuf;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
			NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
			(LPTSTR)&lpMsgBuf,
			0,NULL);
		return GIT_ERROR_CREATE_PROCESS;
	}
	
	CloseHandle(hWrite);
	if(piOut)
		*piOut=pi;
	if(hReadOut)
		*hReadOut=hRead;
	
	return 0;

}
Example #25
0
DEBUG_WIN::DEBUG_WIN(                    //constructor
                     const char *title,  //of window
                     inT32 xpos,         //initial position
                     inT32 ypos,         //in pixels
                     inT32 xsize,        //initial size
                     inT32 ysize,        //in pixels
                     inT32 buflines      //default scroll size
                    ) {
  char cmd[1024];
  int parm;                      //output from scrolrwin
  STARTUPINFO start_info;        //process control
  PROCESS_INFORMATION proc_info; //process ids
  SECURITY_ATTRIBUTES security;  //for handles

  handle = NULL;
  shm_hand = NULL;
  shm_mem = NULL;
  msg_end = NULL;
  dbg_process = NULL;            //save handles
  dbg_thread = NULL;
  security.nLength = sizeof (security);
  security.lpSecurityDescriptor = NULL;
  security.bInheritHandle = TRUE;//make it inheritable
                                 //anonymous
  shm_hand = CreateFileMapping ((HANDLE) 0xffffffff, &security, PAGE_READWRITE, 0, 4096, NULL);
  if (shm_hand == NULL)
    return;                      //failed
  shm_mem = (char *) MapViewOfFile (shm_hand, FILE_MAP_WRITE, 0, 0, 0);
  if (shm_mem == NULL)
    return;
  shm_mem[5] = 0;
  sprintf (cmd, "scrolwin.exe %d %d", buflines, shm_hand);
  GetStartupInfo(&start_info);  //clone our stuff
  if (!CreateProcess (NULL, cmd, NULL, NULL, TRUE,
    CREATE_NO_WINDOW | DETACHED_PROCESS | CREATE_SUSPENDED,
    NULL, NULL, &start_info, &proc_info))
    return;

                                 //save handles
  dbg_process = proc_info.hProcess;
  dbg_thread = proc_info.hThread;
  if (ResumeThread (dbg_thread) != 1)
    return;
  do
  Sleep (100);
  while (shm_mem[5] == 0);       //wait for handle
  parm = ((((uinT8) shm_mem[4] << 8) + (uinT8) shm_mem[3] << 8)
    + (uinT8) shm_mem[2] << 8) + (uinT8) shm_mem[1];
  handle = (HWND) parm;
  if (handle != NULL) {
                                 //setup window
    ::SetWindowText (handle, title);
    ::MoveWindow (handle, xpos, ypos, xsize, ysize, TRUE);
    ::ShowWindow (handle, SW_SHOW);
  }
}
Example #26
0
// Execute program
int execute( char *cmd ) {
	STARTUPINFO stinfo;
	PROCESS_INFORMATION pinfo;
	int result;

	GetStartupInfo( &stinfo );
	stinfo.dwFlags = STARTF_USESHOWWINDOW;
	result = CreateProcess( NULL, cmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &stinfo, &pinfo );
	return result;
}
Example #27
0
static int is_double_click_start(int argc)
{
	STARTUPINFO startup_info = { sizeof(STARTUPINFO) };

	// determine our startup information
	GetStartupInfo(&startup_info);

	// try to determine if MAME was simply double-clicked
	return (argc <= 1 && startup_info.dwFlags && !(startup_info.dwFlags & STARTF_USESTDHANDLES));
}
Example #28
0
void Form::Show(){
	if(this->info_->hWnd != NULL){
		//プログラム起動時にしたいされたウィンドウの状態を取得
		STARTUPINFO Info;
		GetStartupInfo(&Info);
		int nCmdShow = Info.wShowWindow;

		ShowWindow(this->info_->hWnd, nCmdShow);
		UpdateWindow(this->info_->hWnd);
	}
}
Example #29
0
bool have_console()
{
#ifdef SFML_SYSTEM_WINDOWS
	static STARTUPINFO startup_info = { sizeof(STARTUPINFO) };
	GetStartupInfo(&startup_info);
	if (startup_info.dwFlags && !(startup_info.dwFlags & STARTF_USESTDHANDLES)) {
		return false;
	}
#endif
	return true;
}
Q_CORE_EXPORT int qWinAppCmdShow()                        // get main window show command
{

    STARTUPINFO startupInfo;
    GetStartupInfo(&startupInfo);

    return (startupInfo.dwFlags & STARTF_USESHOWWINDOW)
        ? startupInfo.wShowWindow
        : SW_SHOWDEFAULT;

}