Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|