‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘VB SCRIPT PRACTICES - FSO SET - 2
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'CONNECTING REMOTE COMPUTER WITH WINDOWS SHELL SCRIPTING AND PERFORMING VARIOUS OPERATIONS
‘While implementing frameworks using QuickTest, we may get a chance to connect Remote Computer and needs to perform like Find System Drive, Create Folder, Create File, Delete Folder, Delete File, Copy Files/Folders, etc. With the help of shell scripting, we can perform all these kind of operations in Network
‘!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
‘**********************************************************************************************************************************
‘Variables Declaration
‘**********************************************************************************************************************************
Dim objFSO
Dim strComputerName ‘Computer Name in the Network
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘CREATE FSO OBJECT
‘Creates FSO Object
‘**********************************************************************************************************************************
Public Function funcCreateFSOObject ()
‘**********************************************************************************************************************************
‘Variables Declaration
‘**********************************************************************************************************************************
Dim objFSO
Dim strComputerName ‘Computer Name in the Network
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘CREATE FSO OBJECT
‘Creates FSO Object
‘**********************************************************************************************************************************
Public Function funcCreateFSOObject ()
‘Create FSO Object
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘PING A COMUPTER IN A NETWORK TO SEE ITS RESPONSE
‘**********************************************************************************************************************************
Public Function funcPingComp ()
‘Creating Shell Scripting Object
Set objShell = Wscript.CreateObject("WScript.Shell")
‘Ping the Computer
Set objExecCMD = objShell.Exec("cmd /c ping -n 3 -w 1000 " & strComputerName)
‘Verifying End of Stream
Do While Not objExecCMD.StdOut.AtEndOfStream
strResponse = objExecCMD.StdOut.ReadLine()
‘If Remote Computer Responded
If Instr(strResponse, "Reply") > 0 Then
WScript.Echo "Computer '" & strComputer & "' Responded."
‘Could not find Host
ElseIf Instr(strResponse , "could not find host") > 0 Then
WScript.Echo "ERROR: Computer '" & strComputer & "' not responding."
Exit Do
‘Unknown Host
ElseIf InStr(strResponse , "Unknown host") > 0 Then
WScript.Echo "ERROR: Computer '" & strComputer & "' not responding."
Exit Do
‘Request Timex Out
ElseIF InStr(strResponse , "Request timed out.") > 0 Then
WScript.Echo "ERROR: Computer '" & strComputer & "' not responding."
Exit Do
End If
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘DETERMINE SYSTEM DRIVE OF REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcDetermineSystemDrive ()
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘DETERMINE SYSTEM DRIVE OF REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcDetermineSystemDrive ()
‘Create FSO Object
Set objFSO = CreateObject (“Scripting.FileSystemObject”)
‘Determine System Drive of Remote Computer
If objFSO.FolderExists("\\" & strComputer & "\C$\WinNT") Then
strRemoteDrive = "C:\"
ElseIf objFSO.FolderExists("\\" & strComputer & "\C$\Windows") Then
strRemoteDrive = "C:\"
ElseIf objFSO.FolderExists("\\" & strComputer & "\D$\Windows") Then
strRemoteDrive = "D:\"
ElseIf objFSO.FolderExists("\\" & strComputer &"\D$\Windows") Then
strRemoteDrive = "D:\"
End If
If strRemoteDrive = "" Then
WScript.Echo "Remote Drive (C$ or D$) not shared"
Else
WScript.Echo "Remote Drive being used: " & strRemoteDrive
End If
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘CREATE A FOLDER IN REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcCreateFolder ()
Dim strFolder = "\\" & strComputer &"\" & strRemoteDrive & "\ QTPAutomation"
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘CREATE A FOLDER IN REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcCreateFolder ()
Dim strFolder = "\\" & strComputer &"\" & strRemoteDrive & "\ QTPAutomation"
‘Create Folder in Remote Computer
If NOT objFSO.FolderExists (strFolder) Then
objFSO.CreateFolder (strFolder)
WScript.Echo strFolder &” Created Successfully as Expected.”
Else
WScript.Echo strFolder &” Folder Already Exists.”
End If
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘DELETE A FOLDER IN REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcDeleteFolder ()
Dim strFolder = "\\" & strComputer & "\" & strRemoteDrive &"\ QTPAutomation"
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘DELETE A FOLDER IN REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcDeleteFolder ()
Dim strFolder = "\\" & strComputer & "\" & strRemoteDrive &"\ QTPAutomation"
‘Delete Folder in Remote Computer
If NOT objFSO.FolderExists (strFolder) Then
WScript.Echo strFolder &” Folder Does NOT Exist.”
Else
objFSO.DeleteFolder (strFolder)
If NOT objFSO.FolderExists (strFolder) Then
WScript.Echo strFolder &” Folder Deleted Successful as Expected.”
End If
End If
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘CREATE A FILE IN REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcCreateFile ()
Dim strFolder = "\\" & strComputer &"\" & strRemoteDrive &"\ QTPAutomation\File1.txt "
‘Create Folder in Remote Computer
If NOT objFSO.FolderExists (strFile) Then
objFSO.CreateFile (strFile)
WScript.Echo strFolder &” File Created Successfully as Expected.”
Else
WScript.Echo strFolder &” File Already Exists.”
End If
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘DELETE A FILE IN REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcDeleteTextFile ()
Dim strFolder = "\\" &strComputer & "\" & strRemoteDrive &"\ QTPAutomation\File1.txt "
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘DELETE A FILE IN REMOTE COMPUTER
‘**********************************************************************************************************************************
Public Function funcDeleteTextFile ()
Dim strFolder = "\\" &strComputer & "\" & strRemoteDrive &"\ QTPAutomation\File1.txt "
‘Delete Folder in Remote Computer
If NOT objFSO.FileExists (strFile) Then
WScript.Echo strFolder &” File Does NOT Exist.”
Else
objFSO.DeleteFolder (strFile)
If NOT objFSO.FileExists (strFile) Then
WScript.Echo strFolder &” File Deleted Successful as Expected.”
End If
End If
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘GET THE CURRENT FOLDER
‘Returns the folder from where you are trying to execute this script
‘**********************************************************************************************************************************
Public Function funcGetCurrentFolder ()
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘GET THE CURRENT FOLDER
‘Returns the folder from where you are trying to execute this script
‘**********************************************************************************************************************************
Public Function funcGetCurrentFolder ()
‘Get Current Folder
strCurrentFolder = objFSO.GetFolder(".")
WScript.Echo strCurrentFolder
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘GET THE PARENT FOLDER
‘Returns the parent folder from where you are trying to execute this script
‘**********************************************************************************************************************************
Public Function funcGetParantFolder ()
‘Get Parent Folder
strParentFolder = objFSO.GetFolder("..")
WScript.Echo strParentFolder
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘COPY FILE FROM LOCAL COMPUTER TO REMOTE COMPUTER
‘Copies file from specified local file to remote computer in specified location
‘**********************************************************************************************************************************
Public Function funcCopyLocalToRemote ()
‘Get Current Folder
objFSO.CopyFIle SourceFilePathFromLocalComputer, DestinationFilePathToRemoteComputer, OverWriteExisting
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘COPY FILE FROM REMOTE COMPUTER TO LOCAL COMPUTER
‘Copies file from remote specified file to local computer in specified location
‘**********************************************************************************************************************************
Public Function funcCopyLocalToRemote ()
‘Get Current Folder
objFSO.CopyFIle DestinationFilePathFromRemoteComputer , SourceFilePathToLocalComputer, OverWriteExisting
End Function
‘**********************************************************************************************************************************
‘!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
No comments:
Post a Comment