关于ShellExecute()命令的使用(100分)

  • 主题发起人 主题发起人 tt520
  • 开始时间 开始时间
T

tt520

Unregistered / Unconfirmed
GUEST, unregistred user!
1、ShellExecute(handle,"open","notepad.exe","c:/MyLog.log","",SW_SHOW );<br>2、ShellExecute(handle,"open","wordpad.exe","c:/MyLog.log","",SW_SHOW );<br>3、ShellExecute(handle,"open","c:/My.exe","c:/MyLog.log","",SW_SHOW );<br><br>在win2000 server中<br>执行命令(1)时,通过<br>执行命令(2)时,出现错误提示“找不到文件”XP下可以通过<br>执行命令(3)时,不能通过,也没有什么 提示<br><br>又特别地<br>&nbsp; 第3句改为 ShellExecute(handle,"open","c:/My.exe","c:/My Log.log","",SW_SHOW );<br>“My Love.mp3”分开有空格怎么办???<br>
 
其实不用exe文件参数,windows会自动找到log文件关联的执行程序的。去掉试试。
 
我执行这行代码的目的就是要避开“windows”系统的关联,让文件用我指定的程序打开,可是<br>XP下都可以通过,Windows 2000下(2)(3)都有问题。<br>还有就是文件名中间有空格怎么办呢,加“”也不行呀
 
有谁接触过这方面的问题,帮帮忙忙沙[:(][:(][:(]
 
关于ShellExecute函数:<br>&nbsp; &nbsp; 在ShellAPI单元中,ShellExecute函数的定义为:<br><br>function ShellExecute(hWnd: HWND; Operation, FileName, Parameters,<br>&nbsp; Directory: PChar; ShowCmd: Integer): HINST; stdcall;<br><br>作用:打开或打印一个指定的文件;<br>参数说明:<br>&nbsp; &nbsp; hWnd hwnd, &nbsp; //指向父窗口的句柄;<br>&nbsp; &nbsp; Operation: PChar, &nbsp; //指向一个null结尾的串以指明要执行的操作;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 可以是"open","print","explore",NULL;<br>&nbsp; &nbsp; FileName: PChar, &nbsp; &nbsp;//指向文件名或文件夹名串;<br>&nbsp; &nbsp; Parameters: PChar, &nbsp;//指向一个null结尾的串以指明可执行文件的参数;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 如果FileName参数为文档,此参数应为NULL;<br>&nbsp; &nbsp; Directory: PChar, &nbsp; //指向一个null结尾的串以指明默认目录;<br>&nbsp; &nbsp; ShowCmd: Integer &nbsp; &nbsp;//文件在打开时是否显示;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 如果FileName参数为文档,此参数应为0;<br><br>
 
<br>1. ShellExecute(handle, 'open', 'notepad.exe', 'c:/MyLog.log', '', SW_SHOW);<br>2. ShellExecute(handle, 'open', 'wordpad.exe', 'c:/MyLog.log', '', SW_SHOW);<br>3. 没法试;<br><br>有空格的:<br>&nbsp; &nbsp; ShellExecute(handle, 'open','notepad.exe','c:/My Log.log','',SW_SHOW);<br><br>注:以上代码在WIN98SE和WIN2000(Pro、Server)、WINXP上都通过。<br><br>
 
要避开Windows的关联,试试winexec函数
 
to thx1180 and &nbsp;所有的高手:<br>&nbsp; &nbsp;1. ShellExecute(handle, 'open', 'notepad.exe', 'c:/My love.log', '', SW_SHOW);<br>&nbsp; &nbsp; &nbsp; 此种情况下,的确都能通过<br>&nbsp; &nbsp;2. ShellExecute(handle, 'open', 'wordpad.exe', 'c:/My love.log', '', SW_SHOW);<br>&nbsp; &nbsp; &nbsp; 此种情况下,运行出错,提示为:“无法找到该文件,请验证给出的文件名或路径是否正确” &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; 如果我上述命令改为:<br>&nbsp; &nbsp; &nbsp; ShellExecute(handle, 'open', 'winamp.exe', 'c:/My love.mp3', '', SW_SHOW);<br>&nbsp; &nbsp; &nbsp; winamp的播放列表里出现:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;My.mp3<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;love.mp3<br>&nbsp; &nbsp; &nbsp; 即除了记事本以外,其它不支持文件名中有空格,怎么办,怎么办,怎么办???<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; 经过试验发现,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileName: PChar, &nbsp; &nbsp;//指向文件名或文件夹名串,中间可以包含空格;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters: PChar, &nbsp;//指向一个null结尾的串以指明可执行文件的参数;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 如果FileName参数为文档,此参数应为NULL;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 无论是路径还是文件名,中间都不能包含空格(现<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 在只发现“记事本”可以例外)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 如何才能让此处也可以包含空格呢??
 
以下调用方式可以通过:<br>&nbsp; ShellExecute(handle, 'open', 'wordpad.exe', '"c:/My love.log"', '', SW_SHOW);<br>&nbsp; ShellExecute(handle, 'open', 'C:/Program Files/WINAMP/Winamp.exe', '"D:/MEDIAS/da dao.mp3"', '', SW_SHOW);<br>即将Parameters部分的参数用双引号括起来。<br><br>其实这个问题的出现和应用程序如何处理命令行参数有关,<br>如果用ParamStr(1)获取第一个命令行参数,一般情况下是以空格<br>分隔多个参数,如果一个参数中本身含有空格,应该用双引号将这个<br>参数括起来。
 
[:)][:)]原来我引号加错了位置,谢谢大家了。[:)][:)]
 
那要是这样怎么办?<br>cmd.exe <br>执行 attrib path +s<br>其中path是变量<br>怎么做!!<br>急!!!<br>
 
问题解决<br>d :='c:/4';<br>path:='/c attrib "'+d+'" +s';<br>ShellExecute(handle, 'open','cmd.exe', pchar(path),'', SW_SHOW);<br>
 
to xlongbuilder<br>&nbsp; 能不能说说你使用的参数的意义!
 
在一个文件夹中<br>放一个deskdop.ini<br>后用这个命令就可以该文件夹的图标
 
后退
顶部