读书人

C++中路径的有关问题

发布时间: 2013-01-28 11:49:56 作者: rapoo

C++中路径的问题



SHELLEXECUTEINFO si;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SEE_MASK_NOCLOSEPROCESS;
si.lpVerb = _T("open");
CString strbatpath;
strbatpath="shutdown.bat";
si.lpFile = strbatpath;
si.nShow = SW_HIDE;

ShellExecuteEx(&si);
HANDLE m_hInstallProcess;
m_hInstallProcess=si.hProcess;
WaitForSingleObject(si.hProcess,INFINITE);
CloseHandle(si.hProcess);


strbatpath中shutdown.bat是我写的一个批处理文件 strbatpath="shutdown.bat";我这样的写法,应该在当前路径下吧?这样写有偶什么问题吗?为什么我这样写了 在执行批处理的时候没有反应?
我把strbatpath="shutdown.bat";换成"D:\\....."的写法就OK
请教一下……
shutdown.bat里很简单,就一个关机命令
[解决办法]
GetCurrentDirectory
The GetCurrentDirectory function retrieves the current directory for the current process.

DWORD GetCurrentDirectory(
DWORD nBufferLength, // size, in characters, of directory buffer
LPTSTR lpBuffer // pointer to buffer for current directory
);



SetCurrentDirectory
The SetCurrentDirectory function changes the current directory for the current process.

BOOL SetCurrentDirectory(
LPCTSTR lpPathName // pointer to name of new current directory
);


[解决办法]
楼主的问题是当前路径获取有问题,代码没有问题,如果在VS环境测试环境下,运行进程的当前路径是指系统的工程路径,并非debug路径;如果在windows 目录下直接运行,当前路径就是进程路径。

读书人网 >C++

热点推荐