Solved

Script Does Not Work

Posted on 2008-06-13
2
439 Views
Last Modified: 2012-06-22
Can't figure this script out. It runs, returns no errors but does not work. The file does not copy. And yes the file does exists. I am trying to use the variable %USERNAME% in the script.
Option Explicit
Dim objFSO, objShell
Dim strUser
Set objShell = CreateObject("Wscript.Shell")
strUser = objShell.ExpandEnvironmentStrings("%USERNAME%")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If objFSO.FileExists("C:\Documents and Settings\ & strUser & \Application Data\Microsoft\Outlook\ & strUser & .NK2") Then
     objFSO.CopyFile "C:\Documents and Settings\ & strUser & \Application Data\Microsoft\Outlook\ & strUser & .NK2" , "\\servername\ & strUser & \ & strUser & .NK2" , True
 
End If
 
set objFSO = nothing
set strUser = nothing
WScript.Quit

Open in new window

0
Comment
Question by:barrykeel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:gs121
ID: 21781840
You could try this to get the login name....

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"
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"
0
 
LVL 5

Accepted Solution

by:
wtstadd earned 500 total points
ID: 21781846
Looks like you didn't have your " in the correct places.
Option Explicit
Dim objFSO, objShell
Dim strUser
Set objShell = CreateObject("Wscript.Shell")
strUser = objShell.ExpandEnvironmentStrings("%USERNAME%")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If objFSO.FileExists("C:\Documents and Settings\" & strUser & "\Application Data\Microsoft\Outlook\" & strUser & ".NK2") Then
     objFSO.CopyFile "C:\Documents and Settings\" & strUser & "\Application Data\Microsoft\Outlook\" & strUser & ".NK2" , "\\servername\" & strUser & "\" & strUser & ".NK2" , True
 
End If
 
set objFSO = nothing
set strUser = nothing
WScript.Quit

Open in new window

0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question