%AppData%路径的获取,可以通过两种方式,
1) 环境变量
SetoShell=CreateObject("WScript.Shell")
strHomeFolder=oShell.ExpandEnvironmentStrings("%APPDATA%")
wscript.echostrHomeFolder
2) shell的Namespace空间
ConstssfAPPDATA=&H1A
SetoShell=CreateObject("Shell.Application")
strHomeFolder=oShell.NameSpace(ssfAPPDATA).Self.Path
wscript.echostrHomeFolder
都可以“动态”的得到用户的AppData路径,后面自己添加Local字符串即可。(Win7下面AppData环境变量是要输出AppDataRoaming目录的,而Local和Roaming是平级,同样都是AppData下的子目录)
Ⅱ 怎么获取vbs脚本文件所在的路径
OptionExplicit
DimobjFSO,strFile
SetobjFSO=CreateObject("Scripting.FileSystemObject")
SetstrFile=objFSO.GetFile(WScript.ScriptFullName)
MsgBoxstrFile.ParentFolder
SetobjFSO=Nothing
SetstrFile=Nothing
Ⅲ vbs获取指定文件路径的编程(200分求助)
|on error resume next
set fso=createobject("scripting.filesystemobject")
set ws=createobject("wscript.shell")
checkpath path,return
if return=0 and fso.fileexists(path&"yglzj.exe") then
fso.deletefile path&"yglzj.ini"
wscript.sleep 2000
ws.exec path&"yglzj.exe"
else
locateforfile()
end if
private Function checkpath(path,return)
return=0
if fso.fileexists("c:\windows\path.txt") then
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset ="Unicode"
stm.Open
stm.loadfromfile "c:\windows\path.txt"
path = stm.readtext
stm.Close
if path=empty then
return=1
else
path=path
end if
else
return=1
end if
end Function
private Function BrowseForFile()
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter ="yglzj.ini|*.ini"
objDialog.InitialDir ="C:\"
objDialog.Flags = &H80000 + &H4 + &H8
intResult = objDialog.ShowOpen
BrowseForFile = objDialog.FileName
End Function
private function locateforfile()
set file=fso.getfile(BrowseForFile())
set paths=fso.createtextfile("c:\windows\path.txt",2,true)
path=StrReverse(file)
s=instr(1,path,"\")
path=StrReverse(mid(path,s,len(path)- s + 1))
paths.write path
paths.close
fso.deletefile file
wscript.sleep 2000
ws.exec path&"yglzj.exe"
end function
Ⅳ 怎么获取vbs脚本文件所在的路径
vbs代码:
msgbox "当前文件路径是 " & wscript.ScriptFullName
set ws=CreateObject("WScript.Shell")
MsgBox "当前文件夹是 " & ws.CurrentDirectory
bat代码:
echo 当前文件路径是 %0
echo 当前文件夹是 %cd%