Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


I need help, please help,

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,56229
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> I need help, please help,
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2 3   next >   >>
Login
Message << Older Topic   Newer Topic >>
 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
 
 
Post #: 1
 
 RE: I need help, please help, - 2/4/2008 1:42:06 AM   
  ebgreen


Posts: 4595
Score: 29
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

(in reply to dmp_92)
 
 
Post #: 2
 
 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

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: I need help, please help, - 2/5/2008 1:32:41 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Okay, let's start off with the third section IF no removable usb device found then go to end my code is

If strType = ********  nothing  ****** then
goto :EOF


How do I fill in that nothing part?

(in reply to dmp_92)
 
 
Post #: 4
 
 RE: I need help, please help, - 2/5/2008 1:44:36 AM   
  ebgreen


Posts: 4595
Score: 29
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

(in reply to dmp_92)
 
 
Post #: 5
 
 RE: I need help, please help, - 2/5/2008 2:15:25 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Okay this is what I have and I got it working.

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


How do I make it so that when you click okay you go to the USB section of the code

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: I need help, please help, - 2/5/2008 2:19:05 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Sorry my mistate, That code was for the 2nd section for the button.  Still working on the other one.  Will post shortly.

(in reply to dmp_92)
 
 
Post #: 7
 
 RE: I need help, please help, - 2/5/2008 2:20:20 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Will this code work?


If strType = "." then
goto :EOF
End IF

(in reply to dmp_92)
 
 
Post #: 8
 
 RE: I need help, please help, - 2/5/2008 2:40:55 AM   
  ebgreen


Posts: 4595
Score: 29
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

(in reply to dmp_92)
 
 
Post #: 9
 
 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

(in reply to ebgreen)
 
 
Post #: 10
 
 RE: I need help, please help, - 2/5/2008 3:05:06 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Look at the documentation for InputBox and use it instead of MsgBox.

_____________________________

"... 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

(in reply to dmp_92)
 
 
Post #: 11
 
 RE: I need help, please help, - 2/5/2008 3:14:58 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
If I change the command from msgbox to inputbox then the user has an option to write something down.  They only need to hit okay for it to work.

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: I need help, please help, - 2/5/2008 3:17:04 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
I thought that you wanted them to tell you what the drive letter was?

_____________________________

"... 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

(in reply to dmp_92)
 
 
Post #: 13
 
 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



(in reply to ebgreen)
 
 
Post #: 14
 
 RE: I need help, please help, - 2/5/2008 3:34:33 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Change this:

strType = arrDriveType(Disk.DriveType)

to this:

strType = Disk.DriveType

_____________________________

"... 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

(in reply to dmp_92)
 
 
Post #: 15
 
 RE: I need help, please help, - 2/5/2008 3:40:36 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Okay, I have changed it.

This is what I have now.

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" ("strtype")) 
end if

If strMbox = 1 Then
strMbox ="."
End If
Next
End If

I don't think that what I have entered is correct for this section here

strMbox = msgbox("USB drive letter is" ("strtype")) 

(in reply to ebgreen)
 
 
Post #: 16
 
 RE: I need help, please help, - 2/5/2008 3:49:20 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
strMbox = msgbox("USB drive letter is" & Disk.DeviceID) 

_____________________________

"... 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

(in reply to dmp_92)
 
 
Post #: 17
 
 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

(in reply to ebgreen)
 
 
Post #: 18
 
 RE: I need help, please help, - 2/5/2008 4:12:48 AM   
  ebgreen


Posts: 4595
Score: 29
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

(in reply to dmp_92)
 
 
Post #: 19
 
 RE: I need help, please help, - 2/5/2008 5:13:26 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
How do I get it to display the drive type?

(in reply to ebgreen)
 
 
Post #: 20
 
 
Page:   [1] 2 3   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> I need help, please help, Page: [1] 2 3   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts