%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%