Login | |
|
 |
RE: VB Script to compare with a reg key - 2/19/2008 7:00:28 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
Option Explicit Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file, USBFound, varToday, Verify, LastRunDate, WshShell 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\" LastRunDate = WshShell.RegRead(Verify & "File") If LastRunDate = cstr(Date) 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 If DateDiff("n", file.DateLastModified, Now) =< 60 Then objFSO.CopyFile file.Path, UsbKey End If WshShell.RegWrite "HKLM\Software\Emergency Planning\File\", Now() MsgBox "All files have sucessfully copied" Next Set objFSO=Nothing
|
|
| |
|
|
|
 |
RE: VB Script to compare with a reg key - 2/19/2008 7:09:55 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
To get the default value (which is what you chose to use to store the date) you need a final \. So change this: LastRunDate = WshShell.RegRead(Verify & "File") to this: LastRunDate = WshShell.RegRead(Verify & "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
|
|
| |
|
|
|
 |
RE: VB Script to compare with a reg key - 2/19/2008 7:24:49 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
Use WScript.Echo to show you what is stored and what you are comparing to. They will not be that same for any day. Look at them and you will see why.
_____________________________
"... 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/19/2008 8:07:04 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
You need to spend some time reading the docs for the commands that you are using. WScript.Echo displays what you tell it to so just WScript.Echo by itself would display nothing. Right before this line: If LastRunDate = cstr(Date) Then Put this line: WScript.Echo "I am comparing " & LastRunDate & " TO " & Date() Then you will see what is actually being compared. See if they look equal to you.
_____________________________
"... 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 1:12:14 AM
|
|
 |
|
| |
gdewrance
Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
|
How about wscript.echo cdate(now)
_____________________________
"You start coding. I'll go find out what they want."
|
|
| |
|
|
|
 |
RE: VB Script to compare with a reg key - 2/20/2008 1:37:45 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
So when you store the run time in the registry, you are storing the date, hour, minute, and seconds. Then when it runs later you want to check to see if it has run today. So at the later run time, will it ever match the previous run time down to the second?
_____________________________
"... 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
|
|
| |
|
|
|
|
|