Author |
Topic: Sample File Copy VB Script (Read 2800 times) |
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
Sample File Copy VB Script
« Thread started on: Oct 11th, 2005, 2:47pm » |
|
'********************************************* 'Script Name: 'Author: Paul Valentino 'Version: 1.0 'Description '
'Turn on explicit variables Option Explicit
'Define Variables Dim WshNtwk, objFso, WshShell, WshSysEnv, strFavFld, strMyDoc, strNotes6Id DIM StrNotes4Data, strNotes4Doc, strNotes6dsk, strNotes6Data, strNewFolder
Set WshNtwk = WScript.CreateObject("wscript.network") Set objFso = wscript.CreateObject("scripting.filesystemobject") Set WshShell = WScript.CreateObject("WScript.Shell")
'Main Section GetMyDocs() GetFavorites() GetNotes6() GetNotes4 TerminateScript()
'Functions Section
Function GetFavorites() If (objFso.FolderExists("C:\paul") = TRUE) Then objFso.copyfolder "C:\paul2", "favorites", "True" Else Msgbox("Favorites Floder does not exit at I:\ie\Favorites") & Vbcrlf &_ ("Please located user's favorites and place them in the correct foler on the swing space") If (objFso.FolderExists("favorites") = False) Then set strNewFolder = objFso.CreateFolder("favorites") End If End If End Function
Function Getnotes6() If (objFso.FolderExists("notes65") = False) Then set strNewFolder = objFso.CreateFolder("notes65") End If objFso.CopyFile "I:\LotusNotes6\*.id","notes65", "True" objFso.copyfile "C:\apps_pub\nott6510\lotus\notes\data\*.ndk" , "notes65" , "True" objFso.copyfile "C:\apps_pub\nott6510\Lotus\notes\Data\*.nsf" , "notes65" , "True"
End Function
Function GetNotes4 If (objFso.FolderExists("notesna") = False) Then set strNewFolder = objFso.CreateFolder("notesna") End If If (objFso.FolderExists("notesna\data") = False) Then set strNewFolder = objFso.CreateFolder("notesna\data") End If If (objFso.FolderExists("notesna\data\doc") = False) Then set strNewFolder = objFso.CreateFolder("notesna\data\doc") End If If (objFso.FolderExists("I:\notesna\data") = TRUE) Then objFso.copyfile "I:\notesna\data\*.id", "notesna\data", "True" objFso.copyfile "I:\notesna\data\*.nsf", "notesna\data", "True" Else Msgbox("Notes v4 folder does not exit at I:\notesna\data") & Vbcrlf &_ ("Please located user's Notes v4 if available and place them in the ")&_ ("correct foler on the swing space") End If
If (objFso.FolderExists("I:\notesna\data\doc") = TRUE) Then objFso.copyfile "I:\notesna\data\doc\*.nsf", "notesna\data\doc", "True" Else Msgbox("Notes v4 doc folder does not exit at I:\notesna\data") & Vbcrlf &_ ("Please located user's Notes v4 if available and place them in the ")&_ ("correct foler on the swing space") End If End Function
Function GetMyDocs() objFso.CopyFolder WshShell.SpecialFolders("MyDocuments") , "MyDocs", "True" End Function Function TerminateScript() 'MsgBox("Done") wscript.quit End Function
|
|
Logged
|
|
|
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
Re: Main Discovery Script
« Reply #1 on: Oct 11th, 2005, 2:48pm » |
|
'*********************************************Depends upon copyfiles, export printers, export drives 'Script Name: 'Author: Paul Valentino 'Version: 1.0 'Description '
'Turn on explicit variables Option Explicit
'Define Variables Dim WshShell, return
Set WshShell = WScript.CreateObject("WScript.Shell")
'Main Section return = WshShell.run ("wscript ExportDrives.Vbs",1, TRUE) return = WshShell.run ("wscript ExportPrinters.vbs",1, TRUE) return = WshShell.run ("wscript copyfiles.Vbs",1, TRUE)
TerminateScript()
'Functions Section
Function TerminateScript() MsgBox("Done") wscript.quit End Function
|
|
|
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
Export Drives to drives.txt
« Reply #2 on: Oct 11th, 2005, 2:50pm » |
|
'********************************************* 'Script Name:Export Network Drives to drives.txt 'Author: Paul Valentino 'Version: 1.0 'Description '
'Turn on explicit variables Option Explicit
'Define Variables Dim objDrive, objPrinter, objNetwork, intNetworkDrive, i Dim objFso, objFileHandle, strFileName Set objFso = wscript.CreateObject("scripting.filesystemobject") strFileName = "drives.txt"
Set objNetwork = WScript.CreateObject("WScript.Network") Set objDrive = objNetwork.EnumNetworkDrives
'Main Section OpentextFile()
WriteTextOutput()
CloseTextFile()
TerminateScript()
'Functions Section Function OpentextFile() 'if exits, opne in appent mode, otherwise create new If (objFso.FileExists(strFileName)) Then Set objFileHandle = objFso.OpenTextFile(strFileName , 2) Else Set objFileHandle = objFso.OpenTextFile(strFileName , 2,"True") End If End Function
Function WritetextOutput() For i = 0 To objDrive.Count - 1 Step 2 intNetworkDrive = IntnetworkDrive +1 objFileHandle.WriteLine objDrive.Item(i) objFileHandle.WriteLine objDrive.Item(i+1) Next End Function
Function CloseTextFile() 'close file objFileHandle.close() End Function
Function TerminateScript() 'msgbox "Done" wscript.quit End Function
|
|
Logged
|
|
|
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
Export Printers to Printers.txt
« Reply #3 on: Oct 11th, 2005, 2:51pm » |
|
'********************************************* 'Script Name:Export printers printers.txt 'Author: Paul Valentino 'Version: 1.0 'Description '
'Turn on explicit variables Option Explicit
'Define Variables Dim objDrive, objPrinter, objNetwork, intPrinters, i Dim objFso, objFileHandle, strFileName, WshNtwk Set objFso = wscript.CreateObject("scripting.filesystemobject")
Set objNetwork = WScript.CreateObject("WScript.Network") Set objPrinter = objNetwork.EnumPrinterConnections Set WshNtwk = WScript.CreateObject("wscript.network")
'Main Section BuildFileName()
OpentextFile()
WriteTextOutput()
CloseTextFile()
TerminateScript()
'Functions Section
Function BuildFilename 'strFileName = wshntwk.username & "." & wshntwk.computername & ".printers.txt" strFileName = "printers.txt" End Function
Function OpentextFile() 'if exits, opne in appent mode, otherwise create new If (objFso.FileExists(strFileName)) Then Set objFileHandle = objFso.OpenTextFile(strFileName , 2) Else Set objFileHandle = objFso.OpenTextFile(strFileName , 2,"True") End If End Function
Function WritetextOutput() For i = 0 to objPrinter.Count - 1 Step 2 intPrinters = intPrinters +1 objFileHandle.WriteLine objPrinter.Item(i) objFileHandle.WriteLine objPrinter.Item(i+1) Next End Function
Function CloseTextFile() 'close file objFileHandle.close() End Function
Function TerminateScript() 'msgbox "Done" wscript.quit End Function
|
|
Logged
|
|
|
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
Map Drives
« Reply #4 on: Oct 11th, 2005, 2:53pm » |
|
'********************************************* 'Script Name:MapDrives 'Author: Paul Valentino 'Version: 1.0 'Description map drives in drives.txt not done by logon script '
'Turn on explicit variables Option Explicit
'Define Variables Dim objFso, objFilehandle,intCounter,i Dim objDrive, objPrinter, objNetwork, intNetworkDrive
Dim astrOldDriveLetter() Redim astrOldDriveLetter(0)
Dim astrOldDriveUNC() Redim astrOldDriveUNC(0)
Dim astrCurentDrvLtr() Redim astrCurentDrvLtr(0)
Set objFso = wscript.CreateObject("scripting.filesystemobject") Set objFileHandle = objFso.OpentextFile("drives.txt",1)
Set objNetwork = WScript.CreateObject("WScript.Network") Set objDrive = objNetwork.EnumNetworkDrives
'Main Section
GetCurrentDrives()
ReadOldDrives()
MapDrives()
TerminateScript()
'Functions Section
Function GetCurrentDrives 'this function creates an array of the current drive letters intCounter = 0 For i = 0 To objDrive.Count - 1 Step 2 intNetworkDrive = IntnetworkDrive +1 astrCurentDrvLtr(intCounter) = objDrive.Item(i) 'msgbox astrCurentDrvLtr(intCounter) un rem to check array contents intCounter = intCounter + 1 Redim Preserve astrCurentDrvLtr(intCounter) Next End Function
Function ReadOldDrives 'this function populates an array of the old drive letters and mappings
intCounter=0
Do While objFileHandle.AtEndOfStream = False astrOldDriveLetter(intCounter) = objFilehandle.readLine() astrOldDriveUNC(intCounter) = objFilehandle.readLine() 'msgbox astrOldDriveArray(intCounter,0) & " - " &_ 'astrOldDriveArray(intCounter,1) & " " & intcounter'un rem to check array contents intCounter = intCounter + 1 Redim Preserve astrOldDriveLetter(intCounter) Redim Preserve astrOldDriveUNC(intCounter) Loop
objFileHandle.Close
End Function
Function MapDrives
Dim OldArrayLen, NewArrayLen, OldIndex, NewIndex, Map
OldIndex = 0 NewIndex = 0 OldArrayLen = ubound(astrOldDriveLetter) NewArrayLen = ubound(astrCurentDrvLtr) Map = True
For OldIndex = 0 To oldArrayLen map = True For NewIndex = 0 To NewArrayLen If astrOldDriveLetter(OldIndex) = astrCurentDrvLtr(NewIndex) Then Map=False Next If astrOldDriveUNC(Oldindex) = "\\automall\swing" then Map = false If map = True Then objnetwork.MapnetworkDrive astrOldDriveLetter(OldIndex), astrOldDriveUNC(OldIndex), True End if Next
End Function
Function TerminateScript() msgbox "Done" wscript.quit End Function
|
|
Logged
|
|
|
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
Migrate Printers
« Reply #5 on: Oct 11th, 2005, 2:57pm » |
|
'********************************************* 'Script Name:Migrate Printers 'Author: Paul Valentino 'Version: 1.0 'Description migrate printers based on the translation table of ptable.txt '
'Turn on explicit variables Option Explicit
'Define Variables Dim objFso, objFilehandle,objfilehandle2,objFileError,intCounter,i,printer Dim objNetwork, intNetworkDrive,astrPrinter, strFileName, strErrorName, WshNtwk
Dim astrOldPrintPort() Redim astrOldPrintPort(0)
Dim astrOldPrintUNC() Redim astrOldPrintUNC(0)
dim astrPTableOld() redim astrPTableOld(0)
dim astrPTableNew() redim astrPTableNew(0)
Set objFso = wscript.CreateObject("scripting.filesystemobject")
Set objFileHandle2 = objFso.OpentextFile("ptable.txt",1) Set objNetwork = WScript.CreateObject("WScript.Network") Set WshNtwk = WScript.CreateObject("wscript.network")
'Main Section
BuildFileName()
Set objFileHandle = objFso.OpentextFile(strFileName,1)
ReadOldPrinters()
ReadPTable()
MapPrinters()
TerminateScript()
'Functions Section
Function BuildFilename 'strFileName = wshntwk.username & "." & wshntwk.computername & ".printers.txt" 'strErrorName = wshntwk.username & "." & wshntwk.computername & ".printer_errors.txt" strFileName = "printers.txt" strErrorName = "errors.txt"
End Function
Function ReadOldPrinters 'this function populates an array of the old Printer ports and UNCs
intCounter=0
Do While objFileHandle.AtEndOfStream = False astrOldPrintPort(intCounter) = objFilehandle.readLine() astrOldPrintUNC(intCounter) = objFilehandle.readLine() 'msgbox(astrOldPrintPort(intCounter) & vbcrlf & astrOldPrintUNC(intCounter)) intCounter = intCounter + 1 Redim Preserve astrOldPrintPort(intCounter) Redim Preserve astrOldPrintUNC(intCounter) Loop
objFileHandle.Close
End Function
Function ReadPTable 'This Function reads the translation table ptable.txt'
intCounter = 0 Do While objFileHandle2.AtEndOfStream = False printer = objFilehandle2.readline() astrPrinter = split(printer, "," ,-1 ,1) astrPTableOld(intcounter) = astrPrinter(0) astrPTableNew(intcounter) = astrPrinter(1) 'msgbox(astrPTableOld(intCounter) & vbcrlf & astrPTableNew(intCounter)) intCounter = intCounter + 1 redim preserve astrPTableOld(intcounter) redim preserve astrPTableNew(intcounter) Loop End Function
Function MapPrinters
Dim OldArrayLen, OldIndex, NewIndex, UNC, DoTranslate, PTable, PTableLen
UNC = "\\" OldIndex = 0 OldArrayLen = ubound(astrOldPrintUNC) PTableLen = ubound(astrPtableold) msgbox "Please click 'OK' to start mapping printer, depending on number of printers"&_ " this might take a couple of minutes" For OldIndex = 0 to (oldArrayLen -1) If Left(astrOldPrintUNC(OldIndex),2) = UNC Then Dotranslate = false for PTable = 0 to (PTableLen -1) if UCase(astroldprintunc(OldIndex)) = UCase(astrPTableOld(PTable)) then DoTranslate = true 'msgbox (astrOldPrintUNC(oldIndex)) & " maps to " & astrPTableNew(PTable) objNetwork.AddWindowsPrinterConnection astrPTableNew(PTable) end if next if DoTranslate = false then 'msgbox astrOldPrintUNC(oldIndex) & " has no translate" 'if exits, opne in appent mode, otherwise create new If (objFso.FileExists(strErrorName)) Then Set objFileError = objFso.OpenTextFile(strErrorName , 8) Else Set objFileError = objFso.OpenTextFile(strErrorName , 2,"True") End If objFileError.writeline astrOldPrintUNC(oldIndex) & " has no translation" objFileError.close() end if end if Next
End Function
Function TerminateScript() msgbox "Done" wscript.quit End Function
|
|
Logged
|
|
|
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
Copy Files Back
« Reply #6 on: Oct 11th, 2005, 2:58pm » |
|
'********************************************* 'Script Name: 'Author: Paul Valentino 'Version: 1.0 'Description '
'Turn on explicit variables Option Explicit
'Define Variables Dim WshNtwk, objFso, WshShell, WshSysEnv, strFavFld, strMyDoc, strNotes65, strNotes4 Dim strNewFolder
Set WshNtwk = WScript.CreateObject("wscript.network") Set objFso = wscript.CreateObject("scripting.filesystemobject") Set WshShell = WScript.CreateObject("WScript.Shell")
'Main Section
objFso.CopyFolder "favorites" , WshShell.SpecialFolders("Favorites"), "True" objFso.CopyFile "notes65\*.*", "C:\Program Files\Lotus\Notes\data\", "True" objFso.CopyFolder "notesna\data", "C:\Program Files\Lotus\Notes\data\citi", "True" objFso.CopyFolder "MyDocs" , "I:\My Documents local", "True"
TerminateScript()
'Functions Section
Function TerminateScript() MsgBox("Done") wscript.quit End Function
|
|
Logged
|
|
|
|
Paul Valentino
Administrator
    
member is offline


Gender: 
Posts: 46
|
 |
ptable.txt required for migrate printers
« Reply #7 on: Oct 11th, 2005, 3:01pm » |
|
**************************** * Enter printer info in format below ****************************
\\OLDSERVER\OLDPRINTER,\\NEWSERVER\NEWPRINTER
|
|
Logged
|
|
|
|
|