如何将xp文件信息(路径和文件名)传递给vb编写的无窗体的exe文件,谢谢用vb创建了一个无窗体的ok.exe程序用来读取xp下任意txt文件的路径,但在windows下读取文件有问题(即无法用 “点任意txt-->>点鼠标右键-->>打开方式-->>选择ok.exe文件-->>确定”的方法来运行).只能在cmd下运行“c:\ok.exe c:\某某.txt”, 或开始菜单运行里运行:“c:\ok.exe c:\某某.txt”,或直接将某某.txt拖到ok.exe文件上也能运行。代码如下,估计是“FileName = Command$”这句错了,如何修改实现在windows下的直接调用?谢谢 代码如下:
Sub Main()
FileName = Command$
lujing = GetTargetPath(FileName)
MsgBox (lujing)
End subFunction GetTargetPath(ByVal LinkName As String)
On Local Error Resume Next
Dim Obj As Object
Set Obj = CreateObject("WScript.Shell") Dim Shortcut As Object
Set Shortcut = Obj.CreateShortcut(LinkName)
GetTargetPath = Shortcut.TargetPath
Shortcut.SaveEnd Function
Sub Main()
FileName = Command$
lujing = GetTargetPath(FileName)
MsgBox (lujing)
End subFunction GetTargetPath(ByVal LinkName As String)
On Local Error Resume Next
Dim Obj As Object
Set Obj = CreateObject("WScript.Shell") Dim Shortcut As Object
Set Shortcut = Obj.CreateShortcut(LinkName)
GetTargetPath = Shortcut.TargetPath
Shortcut.SaveEnd Function
“运行时错误‘5’;无效的工程调用或参数”,我估计是windows下的默认设置是只要通过打开方式打开就直接打开其指向的文件,所以虽然是对lnk文件操作但,结果是对其指向的具体文件操作,才导致这种错误,谢谢各位热心的高手,谢谢
“L F 覈<O襛?讼@g?探眧襛?4 k P郞??i⒇ +00? /C:\ < 2 4 ?? out.txt & 锞???籜 o u t . t x t 9 - 8 o珛? C:\out.txt . . \ . . \ . . \ o u t . t x t C : \ ` 燲 7jun ?聛刄F悼蔹? 晛箴2櫵?▇ [;??聛刄F悼蔹? 晛箴2櫵?▇ [;? ”这就说明,打开文件是lnk文件本身。用ok.exe打不开的原因是信息传递问题。
On Local Error Resume Next
Dim Obj As Object
Set Obj = CreateObject("WScript.Shell") Dim Shortcut As Object
Set Shortcut = Obj.CreateShortcut(LinkName)
GetTargetPath = Shortcut.TargetPath
End Function另外注册表是这样写的
REM lnk.reg 文件内容
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\lnkfile\shell\OK\command]
@="c:\\ok %1"
supergreenbean超级绿豆的指导。谢谢