Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: VB Script to compare with a reg key

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: VB Script to compare with a reg key
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 2 3 [4]
Login
Message << Older Topic   Newer Topic >>
 RE: VB Script to compare with a reg key - 2/20/2008 8:09:37 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
The script still ends and does not copy over any files.

(in reply to ebgreen)
 
 
Post #: 61
 
 RE: VB Script to compare with a reg key - 2/20/2008 8:14:42 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
What does it say it is comparing? Did you get rid of the On Error resume 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 #: 62
 
 RE: VB Script to compare with a reg key - 2/20/2008 8:18:00 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
When i get rid of the on error resume next I get the error invalid root in registry key

When I keep it, it says that I am comparing NONE to 2/20/08

(in reply to ebgreen)
 
 
Post #: 63
 
 RE: VB Script to compare with a reg key - 2/20/2008 8:20:50 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
What line does the error occur on?

_____________________________

"... 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 #: 64
 
 RE: VB Script to compare with a reg key - 2/20/2008 8:22:03 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Line 20 Char 1

(in reply to ebgreen)
 
 
Post #: 65
 
 RE: VB Script to compare with a reg key - 2/20/2008 8:28:30 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
You're killing me here. I am not sitting in front of your computer looking at the code that you are running. What line is line 20? If I copy and paste the last code that you posted, line 20 is a blank line. You have to give me information or there is no way we will ever figure out the 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 #: 66
 
 RE: VB Script to compare with a reg key - 2/20/2008 8:30:03 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
 I am sorry about that

This is the line here

LastRunDate = WshShell.RegRead(Verify & "File\")

Code is posted below.



Option Explicit
Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file, USBFound, varToday, Verify, LastRunDate, WshShell
Dim objReg, keypath, return, NextSection
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\")
Set WshShell = WScript.CreateObject("WScript.Shell")

'************** Check if scan has run today and if so exit ***************************


Set WshShell = CreateObject("Wscript.Shell")

varToday = Weekday(Date)

Verify = "HKEY_LOCAL_MACHINE\SOFTWARE\EMERGENCY PLANNING\"

'On Error Resume Next
LastRunDate = "NONE"
LastRunDate = WshShell.RegRead(Verify & "File\")

WScript.Echo "I am comparing " & LastRunDate & " TO " & Date()

For Each oFile In objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\").files
Set oLastFile = oFile
Next

dteFileDate = oLastFile.DateLastAccessed

strFileDate = Month(dteFileDate) & "/" & Day(dteFileDate) & "/" & Year(dteFileDate)

If strFileDate = LastRunDate  Then
  WScript.Quit
End If



'If strFileDate = LastRunDate  Then
'    Goto NextSection
'    Else
'    WScript.Quit
'End If




' *************************************************************************************
NextSection


strMbox = "."

strMbox = msgBox("Please insert your Emergency Planning 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)
         UsbKey = strId & "\"
         USBFound = True
   End If

Next

If USBFound = False Then
   MsgBox "No USB drive was found."
   WScript.Quit
End If

For Each file in objFolderA.Files
'If DateDiff("n", file.DateLastModified, Now) =< 60 Then
        objFSO.CopyFile file.Path, UsbKey
'End If


const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
KeyPath = "Software\Emergency Planning\File"
Return = objReg.CreateKey(HKEY_LOCAL_MACHINE, KeyPath)
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\Software\Emergency Planning\File\", date()
'"Hello world!"

'If (Return = 0) And (Err.Number = 0) Then

'Wscript.Echo "HKEY_LOCAL_MACHINE\Software\Emergency Planning\File created"
'Else
'  Wscript.Echo "CreateKey failed. Error = " & Err.Number
'End If


Next

MsgBox "All files have sucessfully copied"

Set objFSO=Nothing

(in reply to ebgreen)
 
 
Post #: 67
 
 RE: VB Script to compare with a reg key - 2/20/2008 8:35:47 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
On Error Resume Next
LastRunDate = WshShell.RegRead(Verify & "File\")
On Error GoTo 0

WScript.Echo "I am comparing " & LastRunDate & " TO " & Date()

For Each oFile In objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\").files
Set oLastFile = oFile
Next

dteFileDate = oLastFile.DateLastAccessed

strFileDate = Month(dteFileDate) & "/" & Day(dteFileDate) & "/" & Year(dteFileDate)

WScript.Echo "I am comparing " & LastRunDate & " TO " & strFileDate

If strFileDate = LastRunDate  AND LastRunDate <> "NONE" Then
WScript.Quit
End If
 
Add the parts in red then tell me what the second comparison statement says. You can actually get rid of the first comparison statement if you want since it is meaningless.


_____________________________

"... 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 #: 68
 
 RE: VB Script to compare with a reg key - 2/21/2008 12:38:23 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
This is the error I get,

Line 122
char 1
error name redefined: hkey_local_machine

Code posted below

Option Explicit
Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file, USBFound, varToday, Verify, LastRunDate, WshShell
Dim objReg, keypath, return, NextSection, oFile, oLastFile, dteFileDate, strFileDate
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\")
Set WshShell = WScript.CreateObject("WScript.Shell")

'************** Check if scan has run today and if so exit ***************************


Set WshShell = CreateObject("Wscript.Shell")

varToday = Weekday(Date)

Verify = "HKEY_LOCAL_MACHINE\SOFTWARE\EMERGENCY PLANNING\"

'On Error Resume Next
'LastRunDate = "NONE"
'LastRunDate = WshShell.RegRead(Verify & "File\")

'WScript.Echo "I am comparing " & LastRunDate & " TO " & Date()

'For Each oFile In objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\").files
'Set oLastFile = oFile
'Next

'dteFileDate = oLastFile.DateLastAccessed

'strFileDate = Month(dteFileDate) & "/" & Day(dteFileDate) & "/" & Year(dteFileDate)

'If strFileDate = LastRunDate  Then
'  WScript.Quit
'End If


On Error Resume Next
LastRunDate = WshShell.RegRead(Verify & "File\")
On Error GoTo 0

WScript.Echo "I am comparing " & LastRunDate & " TO " & Date()

For Each oFile In objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\").files
Set oLastFile = oFile
Next

dteFileDate = oLastFile.DateLastAccessed

strFileDate = Month(dteFileDate) & "/" & Day(dteFileDate) & "/" & Year(dteFileDate)

WScript.Echo "I am comparing " & LastRunDate & " TO " & strFileDate

If strFileDate = LastRunDate  AND LastRunDate <> "NONE" Then
WScript.Quit
End If




'If strFileDate = LastRunDate  Then
'    Goto NextSection
'    Else
'    WScript.Quit
'End If




' *************************************************************************************
'NextSection


strMbox = "."

strMbox = msgBox("Please insert your Emergency Planning 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)
         UsbKey = strId & "\"
         USBFound = True
   End If

Next

If USBFound = False Then
   MsgBox "No USB drive was found."
   WScript.Quit
End If

For Each file in objFolderA.Files
'If DateDiff("n", file.DateLastModified, Now) =< 60 Then
        objFSO.CopyFile file.Path, UsbKey
'End If


const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
KeyPath = "Software\Emergency Planning\File"
Return = objReg.CreateKey(HKEY_LOCAL_MACHINE, KeyPath)
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\Software\Emergency Planning\File\", date()
'"Hello world!"

'If (Return = 0) And (Err.Number = 0) Then

'Wscript.Echo "HKEY_LOCAL_MACHINE\Software\Emergency Planning\File created"
'Else
'  Wscript.Echo "CreateKey failed. Error = " & Err.Number
'End If


Next

MsgBox "All files have sucessfully copied"

Set objFSO=Nothing

(in reply to ebgreen)
 
 
Post #: 69
 
 RE: VB Script to compare with a reg key - 2/21/2008 12:43:35 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
So what you posted is exactly what you are 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 dmp_92)
 
 
Post #: 70
 
 RE: VB Script to compare with a reg key - 2/21/2008 12:51:04 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Yes

(in reply to ebgreen)
 
 
Post #: 71
 
 RE: VB Script to compare with a reg key - 2/21/2008 12:56:24 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
The reason I ask is because the only way to get that error is to have hkey_local_machine defined twice. You do not have it defined twice in the code that you posted. As a matter of fact if I copy and paste the code that you posted it runs without that error.

_____________________________

"... 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 #: 72
 
 RE: VB Script to compare with a reg key - 2/21/2008 1:10:20 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
I just ran it again and I got the same error.  I will post it again the same one that I ran.

Option Explicit
Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file, USBFound, varToday, Verify, LastRunDate, WshShell
Dim objReg, keypath, return, NextSection, oFile, oLastFile, dteFileDate, strFileDate
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\")
Set WshShell = WScript.CreateObject("WScript.Shell")

'************** Check if scan has run today and if so exit ***************************


Set WshShell = CreateObject("Wscript.Shell")

varToday = Weekday(Date)

Verify = "HKEY_LOCAL_MACHINE\SOFTWARE\EMERGENCY PLANNING\"

'On Error Resume Next
'LastRunDate = "NONE"
'LastRunDate = WshShell.RegRead(Verify & "File\")

'WScript.Echo "I am comparing " & LastRunDate & " TO " & Date()

'For Each oFile In objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\").files
'Set oLastFile = oFile
'Next

'dteFileDate = oLastFile.DateLastAccessed

'strFileDate = Month(dteFileDate) & "/" & Day(dteFileDate) & "/" & Year(dteFileDate)

'If strFileDate = LastRunDate  Then
'  WScript.Quit
'End If


On Error Resume Next
LastRunDate = WshShell.RegRead(Verify & "File\")
On Error GoTo 0

WScript.Echo "I am comparing " & LastRunDate & " TO " & Date()

For Each oFile In objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\").files
Set oLastFile = oFile
Next

dteFileDate = oLastFile.DateLastAccessed

strFileDate = Month(dteFileDate) & "/" & Day(dteFileDate) & "/" & Year(dteFileDate)

WScript.Echo "I am comparing " & LastRunDate & " TO " & strFileDate

If strFileDate = LastRunDate  AND LastRunDate <> "NONE" Then
WScript.Quit
End If




'If strFileDate = LastRunDate  Then
'    Goto NextSection
'    Else
'    WScript.Quit
'End If




' *************************************************************************************
'NextSection


strMbox = "."

strMbox = msgBox("Please insert your Emergency Planning 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)
         UsbKey = strId & "\"
         USBFound = True
   End If

Next

If USBFound = False Then
   MsgBox "No USB drive was found."
   WScript.Quit
End If

For Each file in objFolderA.Files
'If DateDiff("n", file.DateLastModified, Now) =< 60 Then
        objFSO.CopyFile file.Path, UsbKey
'End If


const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
KeyPath = "Software\Emergency Planning\File"
Return = objReg.CreateKey(HKEY_LOCAL_MACHINE, KeyPath)
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\Software\Emergency Planning\File\", date()
'"Hello world!"

'If (Return = 0) And (Err.Number = 0) Then

'Wscript.Echo "HKEY_LOCAL_MACHINE\Software\Emergency Planning\File created"
'Else
'  Wscript.Echo "CreateKey failed. Error = " & Err.Number
'End If


Next

MsgBox "All files have sucessfully copied"

Set objFSO=Nothing

(in reply to ebgreen)
 
 
Post #: 73
 
 RE: VB Script to compare with a reg key - 2/21/2008 1:15:24 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
What is weird is that it still writes the files to the usb key and it creates the reg key.

(in reply to dmp_92)
 
 
Post #: 74
 
 RE: VB Script to compare with a reg key - 2/21/2008 1:36:57 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
I have tried this on another computer and I still receive the same error.

(in reply to dmp_92)
 
 
Post #: 75
 
 RE: VB Script to compare with a reg key - 2/21/2008 3:50:10 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
I actually got it working.  There was some code that I had to remove but it is working now.  There is one last thing, I know you have been a great help.  When I add a new file to the folder it will not copy over the file.

Code Below

Option Explicit
Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file, USBFound, varToday, Verify, LastRunDate, WshShell
Dim objReg, keypath, return, NextSection, oFile, oLastFile, dteFileDate, strFileDate
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\")
Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshShell = CreateObject("Wscript.Shell")

varToday = Weekday(Date)

Verify = "HKEY_LOCAL_MACHINE\SOFTWARE\EMERGENCY PLANNING\"

On Error Resume Next
LastRunDate = WshShell.RegRead(Verify & "File\")
On Error GoTo 0

For Each oFile In objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\").files
Set oLastFile = oFile
Next

dteFileDate = oLastFile.DateLastAccessed

strFileDate = Month(dteFileDate) & "/" & Day(dteFileDate) & "/" & Year(dteFileDate)

'WScript.Echo "I am comparing " & LastRunDate & " TO " & strFileDate

If strFileDate = LastRunDate  AND LastRunDate <> "NONE" Then
WScript.Quit
End If

strMbox = "."

strMbox = msgBox("Please insert your Emergency Planning 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)
         UsbKey = strId & "\"
         USBFound = True
   End If

Next

If USBFound = False Then
   MsgBox "No USB drive was found."
   WScript.Quit
End If

For Each file in objFolderA.Files
       objFSO.CopyFile file.Path, UsbKey
    WshShell.RegWrite "HKLM\Software\Emergency Planning\File\", date()
Next

MsgBox "All files have sucessfully copied"

Set objFSO=Nothing

(in reply to dmp_92)
 
 
Post #: 76
 
 RE: VB Script to compare with a reg key - 2/22/2008 2:43:51 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Ok, to figure out what is going on with the copying, take this part:

For Each file in objFolderA.Files
      objFSO.CopyFile file.Path, UsbKey
   WshShell.RegWrite "HKLM\Software\Emergency Planning\File\", date()
Next

and change it to this:

For Each file in objFolderA.Files
      WScript.Echo "COPYING: " & file.Path & " TO " & UsbKey 
      objFSO.CopyFile file.Path, UsbKey 
Next
WshShell.RegWrite "HKLM\Software\Emergency Planning\File\", date()


Basicly move the regwrite out of the loop since there is absolutely no reason to do it more than once. Also show you what files the script is trying to copy. See if the new file shows up in the files that are being 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 #: 77
 
 
Page:  <<   < prev  1 2 3 [4]
 
  

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: VB Script to compare with a reg key Page: <<   < prev  1 2 3 [4]
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