Login | |
|
 |
VB Script to compare with a reg key - 2/15/2008 1:19:20 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
Hello, I have a script that works but needs to be modified. The modification needs to happen where it checks for the date stamp. I will try to put the logic together for you. If a file gets updated then copy it over to the usb key. Also place a datestamp file in a reg key. The next time the script runs it needs to check that reg key for the date stamp if updated and copy the new files over. If this doesn't make any sence, please let me know and I will try to clarify it for you. Code below: Option Explicit 'Dim objWMIService, objItem, colItems Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file, USBFound Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject") Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\") 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) 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 Next Set objFSO=Nothing
|
|
| |
|
|
|
 |
RE: VB Script to compare with a reg key - 2/16/2008 6:30:47 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
What is your question? You stated what you are trying to do, but do you have a particular question?
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: VB Script to compare with a reg key - 2/19/2008 12:32:42 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
This is a section of code I have been trying to work on. I need this to check for a paticular reg key. If there is no reg key or if the date stamp on the reg key is greater then the date stamp on the file then I need the script to continue other wise end script. Option Explicit 'Dim objWMIService, objItem, colItems Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file, USBFound Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject") Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\") '****************** check to see if the files are more current ************************************************ ' For Each file in objFolderA.Files ' Check for reg key "HKEY_LOCAL_MACHINE\SOFTWARE\EMERGENCY PLANNING" for date stamp ' if no reg key found on computer then continue with script ' if reg key is more current then file then ' WScript.Quit
|
|
| |
|
|
|
 |
RE: VB Script to compare with a reg key - 2/19/2008 3:45:35 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
Well if you really want the key to be created then putting On Error Resume Next in will not address the problem. As a matter of fact it is a bad idea. If you had have said that you had On Error Resume next already I would have told you to remove it.
_____________________________
"... 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 5:26:00 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
A registry key does not hold data inherently. Think of it as a table in a database (since the regitry is a database). Until you put rows into the table, the table can exist without having any real data in it. For the registry, once you have a key created, you would need to use RegWrite to write a Name - Value pair to the key to hold the date. Note, what I said about keys is not entirely correct since every key has one Name - Value pair when it is created. The Name is "Default" and the value is empty. So you could use that for the date if you want, but I am not a fan of using Default. I prefer to create a Name - Value pair where the Name is more meaningful than Default.
_____________________________
"... 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 5:54:06 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
This will put the date and time into the default value: 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\", Now() '"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 If you just want the date, let me know.
_____________________________
"... 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 6:10:09 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
That's exactly what I needed. When I put it all together there is one issue. It doesn't do the inital check for the date stamp or reg key to see if it is there or what is more current. Here is the entire code: 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") Set WshShell = CreateObject("Wscript.Shell") varToday = Weekday(Date) Verify = "HKEY_LOCAL_MACHINE\SOFTWARE\EMERGENCY PLANNING\File" 'Check if scan has run today and if so exit On Error Resume Next 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
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|