dim fso
Set M = CreateObject("Wscript.Shell")
set fso=createobject("scripting.filesystemobject")
if fso.FolderExists("1.exe") then
M.run "1.exe"
else
MsgBox("可执行文件不存在!")
end if说明:这段代码执行的结果是,无论1.exe是否存在,都提示不存在,麻烦各位看看!
Set M = CreateObject("Wscript.Shell")
set fso=createobject("scripting.filesystemobject")
if fso.FolderExists("1.exe") then
M.run "1.exe"
else
MsgBox("可执行文件不存在!")
end if说明:这段代码执行的结果是,无论1.exe是否存在,都提示不存在,麻烦各位看看!
Set M = CreateObject("Wscript.Shell")
set fso=createobject("scripting.filesystemobject")
if fso.FileExists("C:\WINDOWS\system32\calc.exe") then
M.run "C:\WINDOWS\system32\calc.exe"
else
MsgBox("可执行文件不存在!")
end if 我用这段代码,可以运行出计算器,你参考后看看吧,还需要路径。
你看下面这个方法错在哪里呢?dim fso
Set M = CreateObject("Wscript.Shell")
set fso=createobject("scripting.filesystemobject")
strPath = M.CurrentDirectory
if fso.FileExists("strPath\calc.exe") then '这样应用路径对么?
M.run "strPath\calc.exe"
else
MsgBox("可执行文件不存在!")
end if
这里面的应该在system32下面,那就对,不是就不对。
strPath 是你当前的路径,也就是你这个文件所在的路径,如果你把它放到system32下面当然可以,或者你把calc.exe放到你当前的路径下。
自己好好看看啊,不了解你的需求,其实很简单的,你在你当前目录创建一个.vbs文件,把上面的代码拷贝过去然后保存,双击就可以运行看效果了。
dim fso
dim strPath
Set M = CreateObject("Wscript.Shell")
set fso=createobject("scripting.filesystemobject")
set strPath = M.CurrentDirectory
if fso.FileExists(strPath+"\calc.exe") then '这样应用路径对么?
M.run strPath+"\calc.exe"
else
MsgBox("可执行文件不存在!")
end if
你这个vbs文件在【C:\program files\新建文件夹】下,所以会那样。