subst command not working through createProcess()

Helo all,

I try to do subst command to map a folder to a drive letter.

I achieved it through command line.

I did same thing via createProcess().

It returns non zero value but the folder not get mapped to that drive letter.

I am using windows2003 and NT.

The part of the code:

STARTUPINFO si;
PROCESS_INFORMATION pi;
int flag, err, i;

GetStartupInfo(&si);
/*
flag = 0;
flag = CREATE_NEW_CONSOLE;
flag = DETACHED_PROCESS;
flag = CREATE_NEW_PROCESS_GROUP;
*/
flag = 0;
DebugLogMessage1(cmd);
if(!CreateProcess(NULL, cmd, NULL, NULL, FALSE, flag,
NULL, NULL, &si, &pi)) {
err = GetLastError();
LogMsg(3, "RunCommand: Could not create process %s error=%d", cmd, err);
return;
}
The DebugLogMessage1(cmd); prints the value of cmd as subst R: C:\PROGRA~1\Syntegra

Please give me the things went wrong in the above program or in the windows settings.


Regards,
Naga
what windows version are you working in? it looks like XP. NTFS?

You may want to look at something called a junction point, it allows you do about the same thing as subst. It is used extensively in Vista but was introduced already in Windows 2000

http://en.wikipedia.org/wiki/NTFS_junction_point

here is an example how to do

http://www.codeproject.com/KB/vista/ReparsePointID.aspx


Thanks for your prompt reply.

We using windwos 2003 server.

This part of code was running in many customer places.

Only some machines face such problem.

So we want rectify the problem in the above code.

Main thing is i can do the same through command line.

Give me some clues.
I tried this on Vista, should work on your OS as well (VS2008/Vista Business)

 
ShellExecute(NULL, NULL, _T("subst.exe"), _T("p: c:\\temp"), NULL, SW_HIDE );


Last edited on
Hi,

Thanks for all who actively discussed on this thread.

I have changed part of the code

Code:
if(!CreateProcess(NULL, cmd, NULL, NULL, FALSE, flag,
NULL, NULL, &si, &pi)) {
err = GetLastError();
LogMsg(3, "RunCommand: Could not create process %s error=%d", cmd, err);
return;
}

To

Code:
CreateProcess(NULL, cmd, NULL, NULL, FALSE, flag,NULL, NULL, &si, &pi);
err = GetLastError();
LogMsg(3, "RunCommand: Could not create process %s error=%d", cmd, err);Then I got the message “RunCommand: Could not create process subst R: "C:\Program Files\Syntegra" error=183”

I used

Code:
ShellExecute(NULL, NULL, "subst.exe", "R: C:\PROGRA~1\Syntegra", NULL, SW_HIDE );

And also used
Code:
DefineDosDevice(0, “R:”, “C:\\PROGRA~1\\Syntegra”);For all I am getting the same error 183(ERROR_ALREADY_EXISTS).

But I am not seeing any R: drive in my “MyComputer” or start->run>r: also states no drive found.

I also tried using the below code.


Code:
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };

Now my only question is how I am getting err 183, even though I am not able to see the drive R: in “MyComputer”. Interestingly I can use “subst” directly in command prompt and I am successful in viewing the dive R: in “MyComputer”.


Regards,
Naga
Subst has nothing to do with junctions points (existed in Win 9x)
CreateProcess is a wrong method
Just use win32 Kern. api for Subst (see news://comp.os.ms-windows.programmer.win32)
Topic archived. No new replies allowed.