请问如何判断 ShellExecute 执行是否成功?

WORKPLUS 2006-07-05 09:30:06
ShellExecute 返回为 * void ,如何判断,执行 ShellExecute 成功或者失败?
...全文
1144 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueDeepOcean 2006-07-22
  • 打赏
  • 举报
回复
ShellExecute(Application->Handle,
"open",
AnsiString("D:\\Documents and Settings\\Administrator\\桌面\\Hack.txt").c_str(),
NULL,
NULL,
SW_SHOW);
switch(GetLastError())
{
case 0:
ShowMessage("0");
break;
case ERROR_FILE_NOT_FOUND:
ShowMessage("ERROR_FILE_NOT_FOUND");
break;
case ERROR_PATH_NOT_FOUND:
ShowMessage("ERROR_PATH_NOT_FOUND");
break;
case ERROR_BAD_FORMAT:
ShowMessage("ERROR_BAD_FORMAT");
break;
case SE_ERR_ACCESSDENIED:
ShowMessage("SE_ERR_ACCESSDENIED");
break;
case SE_ERR_ASSOCINCOMPLETE:
ShowMessage("SE_ERR_ASSOCINCOMPLETE");
break;
case SE_ERR_DDEBUSY:
ShowMessage("SE_ERR_DDEBUSY");
break;
case SE_ERR_DDEFAIL:
ShowMessage("SE_ERR_DDEFAIL");
break;
case SE_ERR_DDETIMEOUT:
ShowMessage("SE_ERR_DDETIMEOUT");
break;
case SE_ERR_DLLNOTFOUND:
ShowMessage("SE_ERR_DLLNOTFOUND");
break;
/*case SE_ERR_FNF:
ShowMessage("SE_ERR_FNF");
break;*/
case SE_ERR_NOASSOC:
ShowMessage("SE_ERR_NOASSOC");
break;
case SE_ERR_OOM:
ShowMessage("SE_ERR_OOM");
break;
/*case SE_ERR_PNF:
ShowMessage("SE_ERR_PNF");
break;*/
case SE_ERR_SHARE:
ShowMessage("SE_ERR_SHARE");
break;
}
xiaoshi0 2006-07-20
  • 打赏
  • 举报
回复
妖哥说的对

Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise.

如果返回值大于32就说明成功了,如果小于等于32则说明失败。
BlueDeepOcean 2006-07-19
  • 打赏
  • 举报
回复
上面的有些问题:"c:\\a.txt"应当为:AnsiString("c:\\a.txt").c_str()

还可以写成:
Application->Handle = ShellExecute(Application->Handle,"open",AnsiString("c:\\a.txt").c_str(),NULL,NULL,SW_SHOW);
if (Application->Handle)
ShowMessage("a");
else
ShowMessage("b");

由于ShellExecute又你的应用程序触发,因此返回结果始终为true,它不同于调用DLL过程。但愿里和它一样。
BlueDeepOcean 2006-07-19
  • 打赏
  • 举报
回复
HINSTANCE hInstance = ShellExecute(Application->Handle,"open","c:\\a.txt",NULL,NULL,SW_SHOW);

if (hInstance)
ShowMessage("OK!");
else
ShowMessage("Bad!");
sanyou98 2006-07-19
  • 打赏
  • 举报
回复
up
jiangshx 2006-07-10
  • 打赏
  • 举报
回复
偶想看中文的答案,^_^
ccrun.com 2006-07-08
  • 打赏
  • 举报
回复
If the function fails, the return value is an error value that is less than or equal to 32
lother 2006-07-08
  • 打赏
  • 举报
回复
上面的够详细
jaffy 2006-07-06
  • 打赏
  • 举报
回复
都答过了,路过.
柯本 2006-07-06
  • 打赏
  • 举报
回复
ShellExecute错误码:
0 The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_BAD_FORMAT The .exe file is invalid (non-Microsoft Win32® .exe or error in .exe image).
SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid.
SE_ERR_DDEBUSY The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL The DDE transaction failed.
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND The specified dynamic-link library (DLL) was not found.
SE_ERR_FNF The specified file was not found.
SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
SE_ERR_OOM There was not enough memory to complete the operation.
SE_ERR_PNF The specified path was not found.
SE_ERR_SHARE A sharing violation occurred.


海嵌 2006-07-05
  • 打赏
  • 举报
回复
HINSTANCE ShellExecute(
HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);


Return Values

If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application.

1,222

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧