全部,我正在尝试编写每个用户之间路径不同的应用程序的开头。有没有办法找到应用程序的真实路径(每个用户),然后使用下面的脚本启动程序?
此外,以登录用户身份运行应用程序的最佳方式是什么,即%username%
。我已经尝试过下面的脚本(对于这个问题),但似乎没有用。
on error resume next
theDir = "C:\Users\" & createobject("wscript.shell").expandenvironmentstrings("%username%") & "\AppData\Local\Apps\2.0\ZJVRE3RK.4TQ\VLGML47Q.TPN\2rin..tion_5bfb425a74ceb3d8_0003.0004_c52ddbfe44f7690b"
theCmd = "2RingIPPSClient.exe"
Set objSh = WScript.CreateObject("WScript.Shell")
objSh.CurrentDirectory = theDir
objSh.Run theCmd
答案 0 :(得分:1)
尝试使用递归函数搜索文件,如下所示:
Function FindFile(name, fldr)
For Each f In fldr.Files
If f.Name = name Then
res = f.Path
Exit For
End If
Next
If IsEmpty(res) Then
For Each sf In fldr.SubFolders
res = FindFile(name, sf)
If res <> "" Then Exit For
Next
End If
FindFile = res
End Function
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
cmd = FindFile("2RingIPPSClient.exe", fso.GetFolder(sh.ExpandEnvironmentStrings("%USERPROFILE%\Appdata\Local\2.0")))
If cmd <> "" Then
'do stuff
End If
答案 1 :(得分:0)
您可以尝试使用此vbscript:
Option Explicit
Dim Ws,fso,Location,FileName,Command,Result,ReadFile,Contents
Set Ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Location=Ws.ExpandEnvironmentStrings("%userprofile%\AppData\Local\2.0")
FileName="2RingIPPSClient.exe"
Command = "Cmd /C Where /r "& Location &" "& FileName &" > %Tmp%\Found.txt"
Result = Ws.Run(Command,0,True)
Set ReadFile = fso.OpenTextFile (Ws.ExpandEnvironmentStrings("%Tmp%\Found.txt"), 1)
Contents = ReadFile.ReadLine
'wscript.echo Contents
Ws.run Contents