⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_57862.htm

📁 vc
💻 HTM
字号:
<p>
序号:57862 发表者:最后一根稻草 发表日期:2003-10-28 16:48:36
<br>主题:对使用xcopy的疑惑
<br>内容:有这样一段程序,我的目的是想将f:\\lu\\xyf.txt的文件拷贝到d:\\xyf.txt这儿,可我运行后发现不管修改d:\\xyf.txt这个参数,最终都是将f:\\lu\\xyf.txt拷贝至程序当前的目录下,我对这儿的两个结构,一个函数理解得不是很透,高手指教,怎样修改?<BR>#include &#34;stdio.h&#34;<BR>#include &#34;windows.h&#34;<BR>int main(int argc, char* argv[])<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;STARTUPINFO si;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_INFORMATION pi;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZeroMemory(&amp;si,sizeof(si));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZeroMemory(&amp;pi,sizeof(pi));<BR>&nbsp;&nbsp;&nbsp;&nbsp;CreateProcess(&#34;f:\\winnt\\system32\\xcopy.exe&#34;,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#34;d:\\xyf.txt f:\\lu\\xyf.txt&#34;,NULL,NULL,FALSE,0,NULL,NULL,&amp;si,&amp;pi);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:wjb 回复日期:2003-10-28 16:53:55
<br>内容:建议:<BR>1.如果是试验CreateProcess函数,不要使用这种例子。<BR>2.如果是实现功能,不要使用这个函数。用CopyFile就可以了。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:最后一根稻草 回复日期:2003-10-29 08:39:15
<br>内容:我找到了一个方法,<BR>#include &#34;stdio.h&#34;<BR>#include &#34;windows.h&#34;<BR>//有关CreateProcess()用法<BR>//若是引用的应用程序是带有命令行参数的话,第一个参数置NULL,第二个参数写出完整的命令行即可。<BR>int main(int argc, char* argv[])<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;STARTUPINFO si;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_INFORMATION pi;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZeroMemory(&amp;si,sizeof(si));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZeroMemory(&amp;pi,sizeof(pi));<BR>&nbsp;&nbsp;&nbsp;&nbsp;CreateProcess(NULL,&#34;f:\\winnt\\system32\\xcopy.exe f:\\lu\\xyf.txt d:\\&#34;,NULL,NULL,FALSE,0,NULL,NULL,&amp;si,&amp;pi);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}<BR>请教高手对CreateProcess()用法的心得贴出来共享。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:redleaf 回复日期:2003-10-29 09:07:51
<br>内容:引用MSDN中的说明<BR><BR>BOOL CreateProcess(<BR>&nbsp;&nbsp;LPCTSTR lpApplicationName,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // name of executable module<BR>&nbsp;&nbsp;LPTSTR lpCommandLine,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// command line string<BR>&nbsp;&nbsp;LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD<BR>&nbsp;&nbsp;LPSECURITY_ATTRIBUTES lpThreadAttributes,&nbsp;&nbsp;// SD<BR>&nbsp;&nbsp;BOOL bInheritHandles,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// handle inheritance option<BR>&nbsp;&nbsp;DWORD dwCreationFlags,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // creation flags<BR>&nbsp;&nbsp;LPVOID lpEnvironment,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// new environment block<BR>&nbsp;&nbsp;LPCTSTR lpCurrentDirectory,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// current directory name<BR>&nbsp;&nbsp;LPSTARTUPINFO lpStartupInfo,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // startup information<BR>&nbsp;&nbsp;LPPROCESS_INFORMATION lpProcessInformation // process information<BR>);<BR>Parameters<BR>lpApplicationName <BR>[in] Pointer to a null-terminated string that specifies the module to execute. <BR>The 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. <BR><BR>The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space-delimited token in the lpCommandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string &#34;c:\program files\sub dir\program name&#34;. This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order: <BR><BR>c:\program.exe files\sub dir\program name<BR>c:\program files\sub.exe dir\program name<BR>c:\program files\sub dir\program.exe name<BR>c:\program files\sub dir\program name.exe <BR><BR>The specified module can be a Win32-based application. It can be some other type of module (for example, MS-DOS or OS/2) if the appropriate subsystem is available on the local computer. <BR><BR>Windows NT/2000: If the executable module is a 16-bit application, lpApplicationName should be NULL, and the string pointed to by lpCommandLine should specify the executable module as well as its arguments. A 16-bit application is one that executes as a VDM or WOW process. <BR><BR>lpCommandLine <BR>[in] Pointer to a null-terminated string that specifies the command line to execute. The system adds a null character to the command line, trimming the string if necessary, to indicate which file was actually used. <BR>Windows NT/2000: The Unicode version of this function, CreateProcessW, will fail if this parameter is a const string. <BR><BR>The lpCommandLine parameter can be NULL. In that case, the function uses the string pointed to by lpApplicationName as the command line. <BR><BR>If both lpApplicationName and lpCommandLine are non-NULL, *lpApplicationName specifies the module to execute, and *lpCommandLine specifies the command line. The new process can use GetCommandLine to retrieve the entire command line. C runtime processes can use the argc and argv arguments. Note that it is a common practice to repeat the module name as the first token in the command line. <BR><BR>If lpApplicationName is NULL, the first white-space – delimited token of the command line specifies the module name. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin (see the explanation for the lpApplicationName parameter). If the file name does not contain an extension, .exe is appended. If the file name ends in a period (.) with no extension, or if the file name contains a path, .exe is not appended. If the file name does not contain a directory path, the system searches for the executable file in the following sequence: <BR><BR>The directory from which the application loaded. <BR>The current directory for the parent process. <BR>Windows 95/98: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory. <BR>Windows NT/2000: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is System32. <BR><BR>Windows NT/2000: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is System. <BR>The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. <BR>The directories that are listed in the PATH environment variable. <BR><BR>...<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:最后一根稻草 回复日期:2003-10-29 12:42:42
<br>内容:不是我舍不得看MSDN,实在英语太差,不怎么看得懂,不过我会努力的,谢谢三楼的热情帮助。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:redleaf 回复日期:2003-10-29 13:15:31
<br>内容:不用客气,其实MSDN中对于API函数的说明还是比较详细的<BR>不妨多看看
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -