Board logo

标题: vbs中cmd 判断自身所在目录 [打印本页]

作者: QOIQoc     时间: 2009-4-11 11:00    标题: vbs中cmd 判断自身所在目录

vbs 判断自身所在目录是否为 %CommonProgramFiles% ,如果不是则删除自身,下面代码为什么复制到%CommonProgramFiles%之后再运行就把自身删除了呢? 还有其他方法吗?

代码:
set s=wscript.createobject("wscript.shell")
s.run "cmd /c if not ""%cd%""==""%CommonProgramFiles%"" copy /Y " & Chr(34) & WScript.ScriptFullName & Chr(34) & " ""%CommonProgramFiles%\cc.vbs"" ",0
s.run "cmd /c if not ""%cd%""==""%CommonProgramFiles%"" del /f /q " & Chr(34) & WScript.ScriptFullName & " ",0
wscript.quit
[ Last edited by QOIQoc on 2009-4-11 at 11:01 ]
作者: newxso     时间: 2009-4-12 01:12

Set WshShell = CreateObject("Wscript.Shell")
Set WshEnv=WshShell.Environment("Process")

strFolder = WshEnv("CommonProgramFiles")
curFolder = WshShell.CurrentDirectory

if not strFolder = curFolder then
   CreateObject("Scripting.FileSystemObject").GetFile(WScript.ScriptFullName).Delete
end if