Member Avatar for nova37

hello am trying to start another exe from my c program , am usign createprocess() but am getting error that , the commond is not recognized as internal or external

  STARTUPINFO startupInfo = {0};
startupInfo.cb = sizeof(startupInfo);

PROCESS_INFORMATION processInformation;
  CreateProcess(
 bpath,    // bpath is char and  have    C:\myf\myapp.exe
  NULL,
  NULL,
  NULL,
  FALSE,
  NORMAL_PRIORITY_CLASS,
  NULL,
  NULL,
  &startupInfo,
  &processInformation
);

Is that a compile-time or run-time error? Did the program include windows.h? What compiler are you using?

bpath is char and have C:\myf\myapp.exe

If you mean bpath is a char-pointer try C:/myf/myapp.exe instead. The \ is an escape symbol but / is recognised as the directory delimiter under windows and *nix.

Member Avatar for nova37

its run time error , i can't use / and / because i get windows dir using

char wdir[255];
GetWindowsDirectory(wdir,255);

so in wdir i get something like c:\windows\system32\
so start cmd i convert wdir to srting and then add \cmd.exe to that and convert again that string to char .
so in copy , move cases etc bpath works fine but in createprocess() it not works ????

On my computer GetWindowsDirectory() returns "c:\windows", not "c:\windows\system32\"; Check the output of GetWindowsDirectory() to see if it is returning what you think it is returning

#include "stdafx.h"
#include <Windows.h>

#include <iostream>
using std::cout;

int main(int argc, char* argv[])
{
    char wdir[255] = {0};
    GetWindowsDirectory(wdir,sizeof(wdir));
    cout << wdir << '\n';
    return 0;
}

Hi,
I think that it can be useful an example from Microsoft:
Click Here

Cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.