Batch or Script to backup NK2 file to network location

Hello -
I need either a batch or script that will run as a login script on a Windows 7 computer.  It needs to backup just the *.NK2 file that is located under the currently logged in user.  Then I need for it to backup to \\SERVER NAME\%Userprofile%\NK2.  We have a server that stores each users profile data.  Each user already has a profile folder created.  I would like to make sure that the NK2 file is copied into their folder on the server.  Your help is greatly appreciated!!!
MO_ITSDAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abelenkiyCommented:
@echo off
set drive=
for /f "tokens=2" %%a in ('net use * \\SERVER\%username% /persistent:no 2^>NUL ^| findstr "Drive"') do set drive=%%a

if "%drive%"=="" (
  echo Could not map to server.
  pause
  goto :EOF
)
echo Drive: %drive%
md %drive%:\nk2
copy "c:\documents and settings\%username%\application data\microsoft\outlook\*.nk2" %drive%\nk2
net use %drive% /del >NUL 2>&1



reference: http://mundy.net.au/Scripting/map-a-drive-using-the-first-available-drive-letter-batch-script
0
MO_ITSDAuthor Commented:
Tried the batch with Outlook closed and it seems like the screen locks up and never backs up the file.
Capture.JPG
0
abelenkiyCommented:
change
md %drive%:\nk2
to
md %drive%\nk2


0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

MO_ITSDAuthor Commented:
Ok, I got the path problem worked out and it is copying one of the nk2 files out to the correct network location.  Now I have another problem.  I have about 6 nk2 files and it is only copying one of them.  Also, the name of the file on the server is being named nk2 with nothing more.  I would like to have a copy of the file from one location to the other.  Any ideas?
Capture.JPG
0
MO_ITSDAuthor Commented:
After doing several tests I noticed that I had about 10 new mapped drives.  Is this batch file supposed to disconnect the mapped drive when it is complete?
0
abelenkiyCommented:
Change copy "c:\documents and settings\%username%\application data\microsoft\outlook\*.nk2" %drive%\nk2
to
C:
cd "c:\documents and settings\%username%\application data\microsoft\outlook"
copy *.nk2 %drive%\nk2\

the net use %drive% /del >NUL 2>&1 command should have taken the drives out.
If it does not change is to net use %drive% /d and nothing else.
0
MO_ITSDAuthor Commented:
Works great.  I did have to add echo y | to the end so that it would confirm closing the connection.  Just one more thing.  How do I set the batch file to run in the background and not show up for the users?  I thought that @echo off would do that, but I was wrong.  Thanks!!
0
MO_ITSDAuthor Commented:
I take that back.  I added Net Use %drive% /d and it is not deleting the mapped drive.  Each time that it is ran the batch file just adds another mapped drive.
0
abelenkiyCommented:
I will tell you honestly you're better off using autoitscript.com instead of windows batch files.
There is a function called FileCopy(@AppDataDir & "\microsoft\outlook\*.nk2", "\\server\" & @username & "\nk2", 9)
9 creates folder structure if its not there and overwrites existing files.
Or to make things simpler:
FileCopy("c:\documents and settings\" & @UserName & "\application data\microsoft\outlook\*.nk2", "\\server\" & @UserName & "\nk2", 9)
No need to map drives, etc...
The script can be compiled into a standalone executable. Very powerful and completely free scripting environment.
0
MO_ITSDAuthor Commented:
I downloaded AUTOIT and cannot locate the filecopy.  There were several .exe's that were installed.  Any idea which one that I open?
0
abelenkiyCommented:
download the scite editor as well.
use that.
http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe
http://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe

Create a new file with a .au3 extension and start working on it. dont work with a blank unsaved file, the commands will not come up.
0
MO_ITSDAuthor Commented:
Ok, I got it to work.  It just didn't create the directory first.  It worked on mine because I had the NK2 directory created.  I took the file to another user and it didn't work because the directory was not created.  I have never ran an exe in a login script.  Are exe files an option or will I probably have to run it through a batch file?  Thank you for your help!!
0
abelenkiyCommented:
Check out my blog site for some script samples of stuff i have done in the past.
http://nyitsupport.blogspot.com
Also take a look at autoit forums, great source of information for future scripts and stuff you may need on your network.
0
abelenkiyCommented:
You can run the .exe just point to it.
Add a trailing \ in the destination possibly?

FileCopy("c:\documents and settings\" & @UserName & "\application data\microsoft\outlook\*.nk2", "\\server\" & @UserName & "\nk2\", 9)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MO_ITSDAuthor Commented:
Worked like a charm after adding the \ at the end of the line.  Thank you very much for your time!  This will help us out a lot.
0
abelenkiyCommented:
Glad to help. This answer also earned me a free membership :)
I hope you get into autoitscript scripting. There is so much you can do very simply.
There was also a vbscript to autoitscript converter somewhere online. Not sure if it is recent.
Basically i got sick of vbscript and batch files, and got into autoitscript. There was an article about it in Windows IT Pro magazine a few years ago. I have not looked back at batch files since.
0
MO_ITSDAuthor Commented:
Good.  I'm glad that I could help you with the free membership.  Thanks again for helping me!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.