954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB Script Variables

Hi guys,

Can anyone tell me if there is a variable for .vbs files that will allow the code to find the llogged on user?

Ill explain a little better...

I have a code that copys files and folders to a network drive, however it only works when i am logged on due to this piece of the code:

src = "C:\documents and settings\me\Favorites
dest = "z:\"

This code only works when "me" is logged on and i was wondering if there was a variable i could add in there that would look for the logged on username and insert that...

For example a .bat file or a .com file to do the same task has a variable of %USERNAME% or %USERPROFILE%... that allows the code to go to the folder of the logged on user.... so does anyone know if ther is a variabel i could put into the line of code in my .vbs file to allow it to do the same?

if you could post a slice of code that will do this or point me to a resource i can learn from id be most appreciative.

Cheers and thanks in advance...

Phreak
Light Poster
43 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 
dim wsh
set wsh = createobject("WScript.Shell")
login_name = wsh.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name")

src = "C:\documents and settings\" & login_name & "\Favorites"
Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Here is a method to keep using your dos CLI Variables:

Main
Sub Main
Dim wsh, fs, profile
set wsh = createobject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
profile = wsh.ExpandEnvironmentStrings("%UserProfile%")

'Copy Files
fs.CopyFile "C:\WINDOWS\win.ini", "" & profile & "\WINDOWS\", True End Sub

mcgyver201c
Newbie Poster
1 post since May 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You