哪个环境变量用于文件路径? [英] Which environment variable to use for filepath?

查看:192
本文介绍了哪个环境变量用于文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将变量分配给位于C:驱动器中的Users文件夹中的文件路径。这个文件路径对于每个用户来说是不同的,但是我无法弄清楚要使用的环境变量,以及如何使用VBScript。

I want to assign a variable to a filepath located in the 'Users' folder in the C: Drive. This filepath is different for each user, but I can't figure out exactly which environment variable to use, and how to use it with VBScript.

示例代码: p>

Example Code:

Set wshShell = CreateObject("WScript.Shell")
Set wshSystemEnv = wshShell.Environment("USER")

'The folder where to save the file:
strFolder = "C:\Users\" & wshSystemEnv & "\AppData\Roaming\Microsoft\AddIns"

那么如何使用 wshSystemEnv 文件路径中的变量,它甚至是正确的变量?

So how do I use the wshSystemEnv variable in the filepath, and is it even the right variable?

弹出 strFolder 行是


错误的参数数量或无效的属性分配

Wrong number of arguments or invalid property assignment


推荐答案

使用%APPDATA%环境变量: p>

Use the %APPDATA% environment variable:

Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

appData = wshShell.ExpandEnvironmentStrings("%APPDATA%")

strFolder = fso.BuildPath(appData, "Microsoft\AddIns")

始终使用 BuildPath 方法。

Always build your paths using the BuildPath method.

e因为 wshSystemEnv 是一个对象,不能与这样的字符串连接。

The error you're getting from your code is because wshSystemEnv is an object and cannot be concatenated with strings like that.

环境变量%APPDATA%传统上指向用户(漫游)配置文件中的应用程序数据文件夹。由于Windows Vista Microsoft将该文件夹拆分为仅三个子文件夹其中一个仍然是漫游配置文件的一部分( AppData\Roaming )。另外2个主要是出于同步性能的原因。

The environment variable %APPDATA% traditionally points to the application data folder in the user's (roaming) profile. Since Windows Vista Microsoft split that folder into three subfolders only one of which remains part of roaming profiles (AppData\Roaming). The other 2 remain local mainly for synchronization performance reasons.

%APPDATA%的原因指向漫游子文件夹而不是%USERPROFILE%\AppData 最有可能让它指向父文件夹将需要很多的应用程序供应商由于额外的层次结构(%APPDATA%\application\foo %APPDATA%\\ \\Roaming\application\foo )。

The reason why %APPDATA% points to the Roaming subfolder instead of %USERPROFILE%\AppData is most likely that having it point to the parent folder would have required a lot of application vendors to release updates with modified paths due to the additional level of hierarchy (%APPDATA%\application\foo to %APPDATA%\Roaming\application\foo).

这篇关于哪个环境变量用于文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆