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   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: VB Script to compare with a reg key - 2/19/2008 6:12:17 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
Quick update.   I took your advice and removed on error resume next.

It can not open registry key.

(in reply to dmp_92)
 
 
Post #: 21
 
 RE: VB Script to compare with a reg key - 2/19/2008 6:23:49 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
That would be a problem. What exactly is the error and which line does it 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 #: 22
 
 RE: VB Script to compare with a reg key - 2/19/2008 6:34:37 AM   
  dmp_92

 

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

Char: 1

Error: unable to open registry key "HKEY_LOCAL_MACHINE\SOFTWARE\EMERGENCY PLANNING\FILE"
Code: 80070002

(in reply to ebgreen)
 
 
Post #: 23
 
 RE: VB Script to compare with a reg key - 2/19/2008 6:43:56 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Which line is line 15 in your code. Line 15 in what I have copied and pasted out of this thread should not give 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 #: 24
 
 RE: VB Script to compare with a reg key - 2/19/2008 6:54:12 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
This is my line 15

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

(in reply to ebgreen)
 
 
Post #: 25
 
 RE: VB Script to compare with a reg key - 2/19/2008 6:56:35 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I think we need to see all of your code. Specifically how is Verfiy being populated?

_____________________________

"... 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 #: 26
 
 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

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

(in reply to dmp_92)
 
 
Post #: 28
 
 RE: VB Script to compare with a reg key - 2/19/2008 7:13:19 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
The program is not returning any errors now which is good.  But the first check is not working properly because if the file has not been modified or changed then the script needs to end.

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

(in reply to dmp_92)
 
 
Post #: 30
 
 RE: VB Script to compare with a reg key - 2/19/2008 8:00:59 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
I have put the wscript.echo in the script below.

Nothing comes up, so I guess it has nothing to compare it to.

WScript.Echo

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

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

(in reply to dmp_92)
 
 
Post #: 32
 
 RE: VB Script to compare with a reg key - 2/19/2008 8:18:19 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
It is comparing date vs date and time.   I see now.  How do I add the time along with the date for the variable date ()

(in reply to ebgreen)
 
 
Post #: 33
 
 RE: VB Script to compare with a reg key - 2/19/2008 8:54:52 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I think that is the wrong solution. Think about what you are trying to compare and 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

(in reply to dmp_92)
 
 
Post #: 34
 
 RE: VB Script to compare with a reg key - 2/20/2008 12:45:54 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
If I write it out it might help me out.  I am trying to compare all files in a directory by date stamp to the date stamp in the registry.  If the date stamp in the directory is more current then the date stamp in the registry then files should be copied other wise end script.

(in reply to ebgreen)
 
 
Post #: 35
 
 RE: VB Script to compare with a reg key - 2/20/2008 12:59:01 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
WScript.Echo "I am comparing " & LastRunDate & " TO " & Date()

LastRunDate looks at the registry date and time stamp and date() only looks at the date no time stamp.

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

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

(in reply to gdewrance)
 
 
Post #: 38
 
 RE: VB Script to compare with a reg key - 2/20/2008 1:43:58 AM   
  dmp_92

 

Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
No it will not so how do I change it from date time hour sec to just date?

(in reply to ebgreen)
 
 
Post #: 39
 
 RE: VB Script to compare with a reg key - 2/20/2008 1:45:45 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
You already know how to get just the date. You already even do it. Read your code and understand what it is doing.

_____________________________

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