I have script that I am try to write that will copy files for back up purposes, I want to be able to use RoboCopy for its functionality, but the script will also need to run on Windows XP. So I thought I would just add the Robocopy.exe to the same folder as the VBScript, and call the command. If I run script with the command directly coding the path it works fine. but I need the script to make the path dynamically assigned. I have tried two diferent methods, (Both in the Code Below), both will fail saying unable to find path.
Any Suggestions?
Option Explicit
'On Error Resume Next
'-------------------------------------------------------------------------------------
'- Set Objects and Variables
'-------------------------------------------------------------------------------------
Dim wshShell, wshProcess
Dim objFSO, objNet, objReg
Dim strTempDest, strSourceData, strSourceNotes, strComputerName, strCurrentPath
Dim strHost, strBitWidth, strValue, strKeyPath, strValueName, strRegKey, strNotes
Dim blNotes, bl64bit, blExist
Dim arrSubKeys
'Set Constants
Const HKEY_LOCAL_MACHINE = &H80000002
'Set Objects
set objFSO = CreateObject ("Scripting.FileSystemObject")
set wshShell = CreateObject ("Wscript.Shell")
Set objNet = CreateObject("WScript.NetWork")
'Set Booleans
DetectOSArchitecture
DetectNotes
'Set Strings
strCurrentPath = objFSO.GetAbsolutePathName(".")
strTempDest = wshShell.ExpandEnvironmentStrings("%temp%")
strComputerName = objNet.ComputerName
If bl64bit = True Then
DetectNotesPathx64
Else
DetectNotesPathx86
End If
'-------------------------------------------------------------------------------------
'- Testing - Remove from Final verion
'-------------------------------------------------------------------------------------
' WScript.Echo "Operating system is 64 bit? " & bl64bit
' WScript.Echo "Notes Path: " & strSourceNotes
' WScript.Echo "Notes Data Path: " & strSourceData
' WScript.Echo "The Temp Directory is: " & strTempDest
' Wscript.echo "Path for Robocopy is: " & strCurrentPath
WScript.echo strCurrentPath & "\RoboCopy.exe " & strSourceData & "Archive " & strTempDest & "\Notes\Data\Archive /mir"
'
'-------------------------------------------------------------------------------------
'- Main Script
'-------------------------------------------------------------------------------------
'Create Destination Folders
' objFSO.CreateFolder strTempDest & "\Notes\"
' objFSO.CreateFolder strTempDest & "\Notes\Data\"
' objFSO.CreateFolder strTempDest & "\Notes\Data\Archive"
'
' objFSO.CopyFile strSourceNotes & "\notes.ini", strTempDest & "\Notes\"
' objFSO.CopyFile strSourceData & "\bookmark.ntf", strTempDest & "\Notes\Data\"
' objFSO.CopyFile strSourceData & "\bookmark.nsf", strTempDest & "\Notes\Data\"
' objFSO.CopyFile strSourceData & "\names.nsf", strTempDest & "\Notes\Data\"
' objFSO.CopyFile strSourceData & "\us.dic", strTempDest & "\Notes\Data\"
' objFSO.CopyFile strSourceData & "\desktop6.ndk", strTempDest & "\Notes\Data\"
' objFSO.CopyFile strSourceData & "\????????.id", strTempDest & "\Notes\Data\"
Dim strArchive, strRoboPath
Dim cmdArchive
strArchive = strSourceData & "\Archive"
strRoboPath = strCurrentPath & "\Robocopy.exe"
cmdArchive = strRoboPath & " " & strArchive & " " & strTempDest & "\Notes\Data\Archive /mir"
WScript.echo AddQuotes(cmdArchive)
wshShell.run AddQuotes(cmdArchive)
wshShell.Run(strCurrentPath & "\RoboCopy.exe " & strSourceData & "Archive " & strTempDest & "\Notes\Data\Archive /mir")
'-------------------------------------------------------------------------------------
'- Functions
'-------------------------------------------------------------------------------------
WScript.Quit
Function DetectNotesPathx86
strSourceNotes = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes\Path")
strSourceData = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes\DataPath")
End Function
Function DetectNotesPathx64
strSourceNotes = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Lotus\Notes\Path")
strSourceData = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Lotus\Notes\DataPath")
End Function
Function DetectOSArchitecture
strValue = wshShell.RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\Identifier")
if (instr(strValue, "64"))Then
bl64bit = True
Else
bl64bit = False
End if
End Function
Function DetectNotes
strComputerName = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\default:StdRegProv")
If bl64bit = True then
strKeyPath = "SOFTWARE\Wow6432Node\Lotus\Notes"
Else
strKeyPath = "SOFTWARE\Lotus\Notes"
End If
strRegKey= "Name"
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strRegKey,strNotes
If IsNull (strNotes) then
WScript.Quit
End If
End Function
Function AddQuotes(strInput)
AddQuotes = Chr(34) & strInput & Chr(34)
End Function