Login | |
|
 |
I need help, please help, - 2/1/2008 3:47:03 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
Original message moved by ebgreen Reason : Moved to proper forum Hello VB script masters, I do not have much experience with VB scripting but I am ask to do some stuff in VB. I can post my code and if you could please help me out. This VB script will check to see if the person is apart of a group membership and if they are the program will look at a file that will be manualy updated or it could write a file with the date somewhere. If the date is more current then it will prompt the user to enter the usb key and hit okay, search for a removeable usb drive and copy all the files that are more current from the hard coded directory to the root of the usb device. I have created some new code for this project but I do require some help. If (IsMember(objUser, "TEST") = True) Then function getParent() fPath="\\bluewater\departments$\test\" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(fPath) set oSubfolders = oFolder.Subfolders *************** If file is not as current then end program ********************************************** *************** If file is more current then look for 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 ******************************************** InputBox("Press okay to continue") 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 end
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/4/2008 1:42:06 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
I'm having a hard time understanding your goals for the script. How about you just ask a specific question about one very specific issue that you are having with writing the script.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/4/2008 2:29:50 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
Okay, I have pieced my script together but it looks horrible. A couple of things. The first thing would be the prompt for the USB key. I think that is right but I am not sure. The section "IF no removable usb device found then go to end" I need some help with that and finally the section "The code below will replace the files" how does it know where to put the information on the usb drive letter. One last thing, I have not figured out how to put a date stamp on the files that get copied to the usb key. Thanks in advance for all your help. 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 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 end
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 1:44:36 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
I think we need to start with basic construction and syntax first. Move the function out of the If - Then block. An If - Then block properly ends with an End If statement not just End.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 2:40:55 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
VBScript does not (happily) support Goto statements. As for flow control, you have two options. First you can put the USB code directly in the If - Then block: If strMBox = 1 Then 'Put your code here End If The other option is to put the code into a Sub or fucntion then call it in the If - Then block. If strMBox = 1 Then DoUSBCode End If Sub DoUSBCode() 'Put your code here End IF
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 3:03:28 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
Okay, I am going with your option number 1. This is what I got. In the part below where it says strMbox = MsgBox("USB drive letter is") "What do I put here?" I am trying to test it so it tells me the drive letter. So I know it is working. Option Explicit 'Dim objWMIService, objItem, colItems 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 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 End If
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 3:20:28 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
I am sorry if you had misunderstood me. I need the users to do little to nothing. Click okay is good. Part of the script will find and search out the drive letter when the usb key is plugged into the PC. For testing purposes, I am trying to see what that drive letter is. I will paste the little code that works but it does not tell me what the drive letter is. Option Explicit 'Dim objWMIService, objItem, colItems 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 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 End If
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 3:54:10 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
I have entered it, the code runs but then it doesn't display anything. Maybe it has something to do with If strType = "Removable Disk" then Option Explicit 'Dim objWMIService, objItem, colItems 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 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 = Disk.DriveType strID = Disk.DeviceID strSys = Disk.SystemName If strType = "Removable Disk" then strMbox = msgbox("USB drive letter is" & Disk.DeviceID) end if If strMbox = 1 Then strMbox ="." End If Next End If
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 4:12:48 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
You are probably right. While it is looping through all the drives have it display the drive type for each one as a test and look at what is displayed to make sure it matches exactly what you are looking for.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|