Announcement

Collapse
No announcement yet.

VBS Script that searches for usb key and compares files

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS Script that searches for usb key and compares files

    Hello,

    I need a little bit of help with my VBS script. What this script is suppose to do is check if you are apart of a group membership if so then prompt to put in your usb key. Once you click ok it will scan for the usb key, if it does not find one then end if it does then get the drive letter. Once it knows what drive letter is then it can find files that are hardcoded in the script and check against the usb key. If the files on the network share or more current copy over the files to the usb key and date stamp it.

    This is what I have so far. Any help would be appriciated. I think I am almost done, but I know I will need some additional help.


    Code:
    If (IsMember(objUser, "TEST") = True) Then   ' Change the group name (TEST) to the proper group name
    
    ' **************************** Enter variables and hard code the path to where the files are located ***************************
    
    
    function getParent()
    	fPath="\\bluewater\departments$\test\"
    	Set oFSO = CreateObject("Scripting.FileSystemObject")
    	Set oFolder = oFSO.GetFolder(fPath)
    	set oSubfolders = oFolder.Subfolders
    
    
    ' ****************************************  Prompt to enter USB key  ***********************************
    
    
    InputBox ("Please enter your usb key and press the enter key to continue")
    
    
    
    ' ******************************************* The code below will find the usb device  *************************************
    
    
    On Error Resume Next
     
    strComputer = "."
     
     
    arrDriveType = array("Unknown",_
    		     "No Root Directory",_
    		     "Removable Disk",_
    		     "Local Disk",_
    		     "Network Drive",_
    		     "Compact Disk",_
    		     "RAM Disk")
     
    set WMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    set colDisks = WMI.ExecQuery("Select * from Win32_LogicalDisk")
     
    For Each Disk in ColDisks
    	strType = arrDriveType(Disk.DriveType)
    	strID = Disk.DeviceID
    	strSys = Disk.SystemName
     
    	If strType = "Removable Disk" then
     
                  objFilesystem.CopyFile "\\bluewater\departments$\test\*.*", strID & "\" 
     
    	End If
    
    ' ********************* IF no removable usb device found then go to end   ********************************************
    
    
    If strType = ********  nothing  ****** then
    goto :EOF
    
    
    ' *************************  The code below will replace the files  **************************************
    
    	
    	for each oSubfolders in oSubfolders
    		filePath=GetNewestFile(oSubfolders)
    		if(instr(filePath, sToday)) then
    			fileName = re.replace(GetFilenameFromPath(filePath),"")
    			oFSO.CopyFile filePath , "\\bluewater\departments$\test\" & fileName , OverwriteExisting
    		else
    			 Set objTextFile = oFSO.OpenTextFile _
    (fPath & "exception" & date() & ".txt", ForAppending, True)
    objTextFile.WriteLine("output data")
    objTextFile.Close
    		end if
    	next 
    end function
    
    
    EOF
    end
    Last edited by Dumber; 5th February 2008, 15:58. Reason: Wrapped code tags arround the script

  • #2
    Re: VBS Script that searches for usb key and compares files

    This is what I have so far. Just need a bit of help.

    I do not know what command I can use to call the usb drive letter name once it finds it. It is section 3.

    Code:
    
    
    
    If (IsMember(objUser, "TEST") = True) Then   ' Change the group name (TEST) to the proper group name
    
    ' **************************** Enter variables and hard code the path to where the files are located ***************************
    
    
    function getParent()
    	fPath="\\bluewater\departments$\test\"
    	Set oFSO = CreateObject("Scripting.FileSystemObject")
    	Set oFolder = oFSO.GetFolder(fPath)
    	set oSubfolders = oFolder.Subfolders
    
    
    ' ****************************************  Prompt to enter USB key  ***********************************
    
    
    Option Explicit
    Dim strComputer, strMbox
    'On Error Resume Next
    strMbox = "."
    strMbox = MsgBox("Please enter your usb key and press the enter key to continue")
    If strMbox = 1 Then
    strMbox ="."
    End If
       
    
    
    ' ******************************************* The code below will find the usb device  *************************************
    
    
    On Error Resume Next
     
    strComputer = "."
     
     
    arrDriveType = array("Unknown",_
    		     "No Root Directory",_
    		     "Removable Disk",_
    		     "Local Disk",_
    		     "Network Drive",_
    		     "Compact Disk",_
    		     "RAM Disk")
     
    set WMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    set colDisks = WMI.ExecQuery("Select * from Win32_LogicalDisk")
     
    For Each Disk in ColDisks
    	strType = arrDriveType(Disk.DriveType)
    	strID = Disk.DeviceID
    	strSys = Disk.SystemName
     
    If strType = "Removable Disk" then
    
    strMbox = MsgBox("USB drive letter is") 
    end if
    
    If strMbox = 1 Then
    strMbox ="."
    End If
    Next
    
    ' ********************* IF no removable usb device found then go to end   ********************************************
    
    
    If strType = "." then
    goto :EOF
    End IF
    
    ' *************************  The code below will replace the files  **************************************
    
    	
    	for each oSubfolders in oSubfolders
    		filePath=GetNewestFile(oSubfolders)
    		if(instr(filePath, sToday)) then
    			fileName = re.replace(GetFilenameFromPath(filePath),"")
    			oFSO.CopyFile filePath , "\\bluewater\departments$\test\" & fileName , OverwriteExisting
    		else
    			 Set objTextFile = oFSO.OpenTextFile _
    (fPath & "exception" & date() & ".txt", ForAppending, True)
    objTextFile.WriteLine("output data")
    objTextFile.Close
    		end if
    	next 
    end function
    
    
    EOF
    
    End if
    
    end
    Last edited by Dumber; 5th February 2008, 17:06. Reason: Again wrapped code tags arround the script.

    Comment


    • #3
      Re: VBS Script that searches for usb key and compares files

      dmp_92,

      Next time use the code tags arround the script
      Marcel
      Technical Consultant
      Netherlands
      http://www.phetios.com
      http://blog.nessus.nl

      MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
      "No matter how secure, there is always the human factor."

      "Enjoy life today, tomorrow may never come."
      "If you're going through hell, keep going. ~Winston Churchill"

      Comment

      Working...
      X