-
Jun 16th, 2008, 10:38 AM
#1
Thread Starter
Addicted Member
[RESOLVED] %userprofile% & %systemdrive% options?
Hi All,
I'm trying to figure out if there are any system options in VBscript that I could use similar to what are available through a CMD prompt or through a Batch file.
The ones that I am most commonly looking to use are:
%userprofile%
%systemdrive%
%systemroot%
If the options are not available, how can I create something in VBscript that will automatically locate these areas?
For example I want to find a certain folder in Application Data for the logged in user. In a Batch file I would do something like this.
%userprofile%\Application Data\Folder
How can that be done in VBS?
Thanks in advance!
-
Jun 16th, 2008, 02:37 PM
#2
Re: %userprofile% & %systemdrive% options?
ExpandEnvironmentString
vb Code:
'VBScript Example set WshShell = CreateObject("WScript.Shell") WScript.Echo WshShell.ExpandEnvironmentStrings("%SystemRoot%") WScript.Echo WshShell.ExpandEnvironmentStrings("%WinDir%")
-
Jun 16th, 2008, 02:59 PM
#3
Thread Starter
Addicted Member
Re: %userprofile% & %systemdrive% options?
Ok, so I tried what you show above (modified a little for my code for testing) and I get an error shown below.
Script: File Path
Line: 12
Char: 1
Error: Object Doesn't Supprt this property or method: 'WshShell.ExpandEnvironmentalStrings'
Code: 800A01B6
Source: Microsoft VBScript runtime error
Here is my code. If I remove line 12 it shows the same error but on line 13.
Code:
Dim FilSys, Uname
Dim FDel, UserName
Dim strComputer
Dim UserPath, WinDir, SystemRoot
Set WshShell = Wscript.CreateObject("WScript.Shell")
Set FilSys = CreateObject ("Scripting.FileSystemObject")
Set Uname = CreateObject ("wscript.network")
strComputer = "."
UserName = Uname.UserName
UserPath = WshShell.ExpandEnvironmentalStrings("%UserProfile%")
WinDir = WshShell.ExpandEnvironmentalStrings("%WinDir%")
SystemRoot = WshShell.ExpandEnvironmentalStrings("%SystemRoot%")
FDel = (UserPath & "\Application Data\TEST")
FilSys.DeleteFolder FDel
-
Jun 16th, 2008, 05:23 PM
#4
Thread Starter
Addicted Member
Re: %userprofile% & %systemdrive% options?
Ok... Well I got it to work now... Check out the code below. Not sure why the other way (that was previously provided) didn't work...
Code:
Dim FilSys, Envi
Dim strComputer
Dim UserPath, WinDir, SystemRoot
Set WshShell = Wscript.CreateObject("WScript.Shell")
Set FilSys = CreateObject ("Scripting.FileSystemObject")
Set Envi = WshShell.Environment ("Process")
strComputer = "."
UserPath = Envi("UserProfile")
'WinDir = WshShell.ExpandEnvironmentalStrings("%WinDir%")
'SystemRoot = WshShell.ExpandEnvironmentalStrings("%SystemRoot%")
WinDir = "\Application Data\Test"
'MsgBox (UserPath & WinDir)
FilSys.DeleteFolder (UserPath & WinDir)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|