News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Create Process from specified dir

Started by Aiva, September 05, 2008, 12:21:47 AM

Previous topic - Next topic

Aiva

I am trying to create process (open an .exe) from a specified directory, I tried to do it with CreateProcess API but I only got it to launch process from the same directory, by specifying filename, open child process using command line, from same directory as well, and that's it. I am sure there is some fast and easy way to do this but I just can't find it.

BlackVortex

CreateProcess can handle full paths. My debugger uses GetOpenFileName and then uses the lpstrFile member of the returned structure.

From MSDN :
QuoteThe string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. This parameter must include the file name extension; no default extension is assumed.

Aiva

CreateProcess "can" handle full path names , the problem is once it launches new process it (the process) crashes(when launching from different dir than the launched file is, if launching it from the same dir everything works), and GetOpenFileName requires user to navigate to the file and press ok, which I really don't need, since I'm looking for something what can launch it with single button click, it does not do anything with the file and new process should not be child process it should be separate.

BlackVortex

Must be some programming error, cause my debug-loader creates processes all over the place.

I'm using these parameters :
invoke CreateProcess,dword ptr [target_name],0,0,0,FALSE,DEBUG_PROCESS,0,0,offset startinfo,offset pi

The startupinfo structure is actually the calling process's startupinfo, I've used GetStartupInfo to fill it   :wink
Maybe there's some problem there, or with the commandline that you're passing, or with the working directory that you set, etc.

EDIT:  What about ShellExecute, I've never used it but maybe it's more useful for you ?

sinsi

Do you mean you want to start 'c:\programs\myprog.exe' and have its directory asĀ  'c:\programs'? If so, look at a parameter of CreateProcess -
Quote
lpCurrentDirectory
[in] Pointer to a null-terminated string that specifies the full path to the current directory for the process. The string can also specify a UNC path.
If this parameter is NULL, the new process will have the same current drive and directory as the calling process. (This feature is provided primarily for shells that need to start an application and specify its initial drive and working directory.)
Light travels faster than sound, that's why some people seem bright until you hear them.

Aiva

Well i have looked this up veeery extensively and the only thing I found that could be wrong is that if commandline parameter is read only memory it can cause access violation. I am trying to test this now ,but I  ran into some nasty string issues, which I'm looking up as i write this, need to copy long string to a buffer and it reports constant too big error so I cant move them directly to/from register or push/pop. I have done nothing much with strings other than messageboxes or separate buffers.

Other than that everything else seems fine, Yes i have tried using the shell proc, somewhere on this forum is a complete one don't have a link to it. Yes i know that startupinfo passes from the calling process, i tried that aswell but it doesn't work, here is the call:


.DATA
Filename db 'C:\Program Files\subdir\subdir2\target.exe',0
.CODE
invoke CreateProcess,NULL,addr Dir,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,addr StartupInfo,ADDR hProcess
or             invoke CreateProcess,addr Filename,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL, addr StartupInfo, addr hProcess

these make no difference if they hold the same path to a file I want to open, lets say C:\programs\subdir\subdir3\target.exe


invoke GetStartupInfo,ADDR StartupInfo   not included as it made no difference whatsoever.

These calls open some programs, but don't some other, for example when i tried it on some games they crashed, some didn't, no idea why, when I tried them on some smaller programs results were as much interesting  :bg some opened some crashed one reported error.

QuoteDo you mean you want to start 'c:\programs\myprog.exe' and have its directory as  'c:\programs'? If so, look at a parameter of CreateProcess
This means that target.exe and my program is in the same dir and as I said if they are in the same dir everything works, but if I try to launch it with my program from different dir results are unpredictable.