请问,shellexecute()怎么使用(100分)

  • 主题发起人 主题发起人 huafann
  • 开始时间 开始时间
H

huafann

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在想用它来执行A盘下的DEMO.BAT,<br>应该怎么写呢<br>用WINEXEC('A:/DEMO.BAT',SW_SHOW)不行,是不时WINEXEC只能用于EXE文件呀.
 
深入浅出ShellExecute <br><br>作者:徐景周<br><br><br><br>Q: 如何打开一个应用程序?<br><br>ShellExecute(this-&gt;m_hWnd,"open","calc.exe","","", SW_SHOW );<br><br>或<br><br>ShellExecute(this-&gt;m_hWnd,"open","notepad.exe",<br><br>"c:/MyLog.log","",SW_SHOW );<br><br><br><br><br><br>Q: 如何打开一个同系统程序相关连的文档?<br><br>ShellExecute(this-&gt;m_hWnd,"open",<br><br>"c:/abc.txt","","",SW_SHOW );<br><br><br><br>Q: 如何打开一个网页?<br><br>ShellExecute(this-&gt;m_hWnd,"open",<br><br>"http://www.google.com","","", SW_SHOW );<br><br><br><br>Q: 如何激活相关程序,发送EMAIL?<br><br>ShellExecute(this-&gt;m_hWnd,"open",<br><br>"mailto:nishinapp@yahoo.com","","", SW_SHOW );<br><br><br><br>Q: 如何用系统打印机打印文档?<br><br>ShellExecute(this-&gt;m_hWnd,"print",<br><br>"c:/abc.txt","","", SW_HIDE);<br><br><br><br>Q: 如何用系统查找功能来查找指定文件?<br><br>ShellExecute(m_hWnd,"find","d:/nish",<br><br>NULL,NULL,SW_SHOW);<br><br><br><br>Q: 如何启动一个程序,直到它运行结束?<br><br>SHELLEXECUTEINFO ShExecInfo = {0};<br><br>ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);<br><br>ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;<br><br>ShExecInfo.hwnd = NULL;<br><br>ShExecInfo.lpVerb = NULL;<br><br>ShExecInfo.lpFile = "c:/MyProgram.exe"; <br><br>ShExecInfo.lpParameters = ""; <br><br>ShExecInfo.lpDirectory = NULL;<br><br>ShExecInfo.nShow = SW_SHOW;<br><br>ShExecInfo.hInstApp = NULL; <br><br>ShellExecuteEx(&amp;ShExecInfo);<br><br>WaitForSingleObject(ShExecInfo.hProcess,INFINITE);<br><br>或:<br><br>PROCESS_INFORMATION ProcessInfo; <br><br>STARTUPINFO StartupInfo; //入口参数<br><br>ZeroMemory(&amp;StartupInfo, sizeof(StartupInfo));<br><br>StartupInfo.cb = sizeof StartupInfo ; //分配大小<br><br>if(CreateProcess("c:/winnt/notepad.exe", NULL, <br><br>NULL,NULL,FALSE,0,NULL,<br><br>NULL,&amp;StartupInfo,&amp;ProcessInfo))<br><br>{ <br><br>WaitForSingleObject(ProcessInfo.hProcess,INFINITE);<br><br>CloseHandle(ProcessInfo.hThread);<br><br>CloseHandle(ProcessInfo.hProcess);<br><br>} <br><br>else<br><br>{<br><br>MessageBox("The process could not be started...");<br><br>}<br><br><br><br><br><br>Q: 如何显示文件或文件夹的属性?<br><br>SHELLEXECUTEINFO ShExecInfo ={0};<br><br>ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);<br><br>ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;<br><br>ShExecInfo.hwnd = NULL;<br><br>ShExecInfo.lpVerb = "properties";<br><br>ShExecInfo.lpFile = "c:/"; //也可以是文件<br><br>ShExecInfo.lpParameters = ""; <br><br>ShExecInfo.lpDirectory = NULL;<br><br>ShExecInfo.nShow = SW_SHOW;<br><br>ShExecInfo.hInstApp = NULL; <br><br>ShellExecuteEx(&amp;ShExecInfo);<br><br>
 
你的也可以改为:<br>WINEXEC('[red]start[/red] A:/DEMO.BAT',SW_SHOW)
 
uses shellapi;
 
可能没有比'007_L'更完整的回答了!
 
谁是007_L?
 
JamesBond_L,已经非常完整了。<br>至于执行DOS下面的批处理文件,还是使用CreateProcess比较好。以下是<br>我软件自动升级的一段代码,全部给你了:<br>procedure SoftUpdate; &nbsp;//删除程序<br>&nbsp; var<br>&nbsp; &nbsp; BatchFile: TextFile;<br>&nbsp; &nbsp; BatchFileName: string;<br>&nbsp; &nbsp; ProcessInfo: TProcessInformation;<br>&nbsp; &nbsp; StartUpInfo: TStartupInfo;<br>&nbsp; begin<br>&nbsp; &nbsp; BatchFileName := ExtractFilePath(ParamStr(0)) + '_deleteme.bat';<br><br>&nbsp; &nbsp; AssignFile(BatchFile, BatchFileName);<br>&nbsp; &nbsp; Rewrite(BatchFile);<br><br>&nbsp; &nbsp; Writeln(BatchFile, ':try');<br>&nbsp; &nbsp; writeln(BatchFile, 'ren "'+ExtractFilePath(ParamStr(0))+'chwiseljgfc.exe "'+' "chwiseljgfc_old.exe"');<br>&nbsp; &nbsp; Writeln(BatchFile, 'del "' + ParamStr(0) + '"');<br>&nbsp; &nbsp; Writeln(BatchFile, 'if exist "' + ParamStr(0) + '"' + ' goto try');<br>&nbsp; &nbsp; writeln(BatchFile,':try1');<br>&nbsp; &nbsp; writeln(BatchFile, 'ren "'+ExtractFilePath(ParamStr(0))+'_chwiseljgfc.exe "'+' "chwiseljgfc.exe"');<br>&nbsp; &nbsp; writeln(BatchFile,'if exists " '+ExtractFilePath(ParamStr(0))+'_chwiseljgfc.exe '+'"'+'goto try1');<br>&nbsp; &nbsp; Writeln(BatchFile, 'del %0');<br>&nbsp; &nbsp; CloseFile(BatchFile);<br>&nbsp; &nbsp; FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);<br>&nbsp; &nbsp; StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; &nbsp; StartUpInfo.wShowWindow := SW_HIDE;<br><br>&nbsp; &nbsp; if CreateProcess(nil, PChar(BatchFileName), nil, nil,<br>&nbsp; &nbsp; &nbsp; False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,<br>&nbsp; &nbsp; &nbsp; ProcessInfo) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; CloseHandle(ProcessInfo.hThread);<br>&nbsp; &nbsp; &nbsp; CloseHandle(ProcessInfo.hProcess);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>
 
to JamesBond_L:<br>&nbsp; if &nbsp;JamesBond = 007 then<br>&nbsp; &nbsp; JamesBond_L = 007_L
 
哈哈~~厲害~~<br>chnplzh﹐你給我那個干嗎﹖
 
后退
顶部