vbs 高手来看看我这段代码

这段代码保存为.vbs格式双击的情况下,createfile函数执行。拖动文件到该vbs情况下,createfile却不执行。但我试验了 两种情况下都有执行到msgbox, 为何createfile 却不行。哪里出现冲突?好吧,高手都没空。
2026年09月26日 09:00
有2个网友回答
网友(1):

Function createfile(namestr)
    Set fso=CreateObject("scripting.filesystemobject")
    Set objfile1=fso.CreateTextFile("c:\sql.txt",True)
    objfile1.WriteLine namestr
    objfile1.Close
End Function
Set objargs=WScript.Arguments
If objargs.Count=0 Then
    MsgBox "1"
    createfile("")
Else
    MsgBox "2"
    createfile(objargs.Item(0))
End If

可能拖过去的,当前目录发生了改变,改成了绝对路径就行。

两句createfile 参数都一样,即使写了文件也看不出有没写过。


补充:我找着了,我这里写在了这里:C:\Documents and Settings\Administrator

网友(2):

function创建的函数调用时后有参数需要用call调用