Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: 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 >> RE: I need help, please help,
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2] 3   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: I need help, please help, - 2/5/2008 5:20:42 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
How have you been displaying things all along?

Use MsgBox.


MsgBox "For drive " & Disk.DeviceID & " the drive type is " & 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 #: 21
 
 RE: I need help, please help, - 2/5/2008 5:28:09 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
I took the usb code out of the script and ran the usb code by itself and it works properly.  So I got it to display the right drive. When I add the code for the msg box prompt before the usb drive it does it but then it does not move on to the usb section.  So I guess the question is how do I get it so move on after you hit the okay button after the first dialog box?

(in reply to ebgreen)
 
 
Post #: 22
 
 RE: I need help, please help, - 2/5/2008 5:30:03 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Post what you are currently running.

_____________________________

"... 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 ebgreen)
 
 
Post #: 23
 
 RE: I need help, please help, - 2/5/2008 5:50:40 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Okay,  this is the prompt section



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
strmbox ="."
end if



This is the usb section




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 " & Disk.DeviceID)

end if


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


they work fine apart, but when you add them together then do not work.

(in reply to ebgreen)
 
 
Post #: 24
 
 RE: I need help, please help, - 2/5/2008 6:20:46 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Is there code in between? Please post the code exactly as you are running it. Either way, remove the On Error Resume Next command.

_____________________________

"... 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 #: 25
 
 RE: I need help, please help, - 2/5/2008 6:33:40 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
I do not know how to make it go to the next section so I put them together.  I know that is not a good idea, but I get an error when I do this.


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 " & Disk.DeviceID)
   end if


Next

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

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Believe it or not, all I had to do is define the variable.  Code is posted below.


Option Explicit
'Dim objWMIService, objItem, colItems
Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys
strMbox = "."

strMbox = msgBox("Please enter your usb key and press the enter key to continue")

If strMbox = 1 Then

   strmbox ="."

end if

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 " & Disk.DeviceID)
   end if


Next

Time for the next section

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


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
I do believe it since you have Option Explicit which is good programming practice for VBS. So when you removed the global On Error Resume next which is bad programming practice, an error showed up that told you what was wrong.

_____________________________

"... 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 #: 28
 
 RE: I need help, please help, - 2/5/2008 7:10:51 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
I have pieced all together and I receive some major issues.  I do know that parts of the script are working correctly.    I just get errors when I run it.



Option Explicit

   Dim objWMIService, objItem, colItems
   Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys

function getParent()
   fPath="\\bluewater\departments$\Information Technology\test\"
   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oFolder = oFSO.GetFolder(fPath)
   set oSubfolders = oFolder.Subfolders



'*****************************************************************************************************




strMbox = "."

strMbox = msgBox("Please enter your usb key and press the enter key to continue")

If strMbox = 1 Then

   strmbox ="."

end if


'*****************************************************************************************************

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 " & Disk.DeviceID)
   end if




'******************************************************************************************************

for each oSubfolders in oSubfolders
       filePath=GetNewestFile(oSubfolders)
       if(instr(filePath, sToday)) then
           fileName = re.replace(GetFilenameFromPath(filePath),"")
           oFSO.CopyFile filePath , "\\bluewater\departments$\Information Technology\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



(in reply to ebgreen)
 
 
Post #: 29
 
 RE: I need help, please help, - 2/5/2008 7:11:40 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
What are the errors? What line do the errors occur on? What do the errors say?

_____________________________

"... 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 #: 30
 
 RE: I need help, please help, - 2/5/2008 7:24:03 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
sorry about that,  I have new code for the file transfer section. The last piece of this code.  I do not receive any errors now, however I check to see if the file has been copied over to the usb key and it has not.


Option Explicit
'Dim objWMIService, objItem, colItems
Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\")

UsbKey=strID
'UsbKey="C:\FolderB\"

strMbox = "."

strMbox = msgBox("Please enter your usb key and press the enter key to continue")

If strMbox = 1 Then

   strmbox ="."

end if

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 " & Disk.DeviceID)
   end if


Next


For Each file in objFolderA.Files
If dateDiff("d", file.DateCreated, Date) < 2 Then 'copy file if it's "2 days old"
   objFSO.CopyFile file.Path, UsbKey
End If
Next

Set objFSO=Nothing

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


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Scripts run in a sequential fashion. They start at the first line, then the next, then the next, etc. The exception to this is flow control statements. Things like If - Then, For -Next, etc. So in your script, at the top before any thing has had a chance to really happen, you have:

UsbKey=strID

At this point strID contains nothing. So your statement says "Make UsbKey contain nothing". You never do anything else for the rest of the script to assign a value to UsbKey. So when the script gets to:

objFSO.CopyFile file.Path, UsbKey

You are telling it to "Copy the file to nothing" it just assumes that you are crazy and goes on about it's business since it doesn't know how to copy a file to nothing.


You need to think about what your script is doing. At what point in the code do you know what the drive letter for the USB key is? At that point then you need to set UsbKey to contain the path where you want the file copied.

_____________________________

"... 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 #: 32
 
 RE: I need help, please help, - 2/5/2008 7:37:47 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
You are completely right!  As you can tell I am very new to this.  Where would I put that last statement?  Can I put it anywhere?  I know what the code is doing.  How do I tell it to hold the information after it has found it?

(in reply to ebgreen)
 
 
Post #: 33
 
 RE: I need help, please help, - 2/5/2008 7:39:48 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Well, answer the question. Where in the script do you know what the drive letter for the USB drive is?

_____________________________

"... 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 #: 34
 
 RE: I need help, please help, - 2/5/2008 7:42:15 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
After this section

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 " & Disk.DeviceID)
   end if

UsbKey=strID

I would add it to the end.  I have tried this and it does not copy it over.

(in reply to ebgreen)
 
 
Post #: 35
 
 RE: I need help, please help, - 2/5/2008 7:52:23 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
You are close. The only time that you know which drive is the usb drive is when this:

If strType = "Removable Disk" then


Evaluates to true. So you need to do your assignment inside the If - Then block Like this:

  If strType = "Removable Disk" then

      strMbox = MsgBox("USB drive letter is " & Disk.DeviceID)
      UsbKey = strId
  end if


However, if tou do that the copy still won't work. strID at that point would hold the drive letter of the usb key. So it hold's something like "V:". Obviously then when you get to this line:

objFSO.CopyFile file.Path, UsbKey

You would be telling it to copy the file to V:. But where on V:. The script does not know anything that you don't tell it or that it isn't told to find out on it's own. So to make the copy command correct, you would need to use this code for the assignment:

  If strType = "Removable Disk" then

      strMbox = MsgBox("USB drive letter is " & Disk.DeviceID)
      UsbKey = strId & "\FolderB\"
  end if

Now you have told it exactly where to copy the file.

_____________________________

"... 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 #: 36
 
 RE: I need help, please help, - 2/5/2008 8:01:56 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
So far so good.  I do not get an error after I made the changes you had suggested but I do not see the files copied over as well.

(in reply to ebgreen)
 
 
Post #: 37
 
 RE: I need help, please help, - 2/5/2008 8:10:45 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Ok, let's work on some basic trouble shooting. The command that isn't doing what we expect is this:


  objFSO.CopyFile file.Path, UsbKey


So let's see if that command is even being called (since it is inside an If - Then block it may not be) and if it is called exactly what the cammand being executed looks like. The quick and dirty way to do that is to stick a message box in there with the command like this:

For Each file in objFolderA.Files
If dateDiff("d", file.DateCreated, Date) < 2 Then 'copy file if it's "2 days old"
   MsgBox "objFSO.CopyFile " & file.Path & ", " & UsbKey
   objFSO.CopyFile file.Path, UsbKey
End If
Next

_____________________________

"... 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 #: 38
 
 RE: I need help, please help, - 2/5/2008 8:16:12 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
The folder was not created on the usb key so I changed up the location of the usb key to the root and it works.  Thank you for all your help!!

(in reply to ebgreen)
 
 
Post #: 39
 
 RE: I need help, please help, - 2/5/2008 8:23:30 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
No problem.

_____________________________

"... 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 #: 40
 
 
Page:  <<   < prev  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 >> RE: I need help, please help, Page: <<   < prev  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