Solved

Script Does Not Work

Posted on 2008-06-13
2
434 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now