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.
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
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”
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”.
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)