首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++中路径的有关问题

2013-01-28 
C++中路径的问题SHELLEXECUTEINFO siZeroMemory(&si, sizeof(si))si.cbSize sizeof(si)si.fMask SE

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 目录下直接运行,当前路径就是进程路径。

热点排行