Discussion:
Script runs every time
(too old to reply)
Andy K
2014-12-13 23:26:23 UTC
Permalink
This vbs script is supposed to only run once a day, but it runs everytime.

Anyone know how to fix it ?

Thanks,
Andy


'******************************************************************************
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v5.0
'* Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()


'******************************************************************************
'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'******************************************************************************
Sub VBMain()
Dim objShell
Dim ExitCode

' The following function call ensures that this script only runs once a day
If HasRunToday Then
WScript.Quit
End If

Set objShell = WScript.CreateObject("WScript.Shell")

' Do the backup
ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE> ""C:\masm32\SOURCE\Reflect\My Backup.xml""")

' done
Set objShell = nothing
wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'* Optionaly logs output to file
'*
'* Input: strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
Dim objShell
Dim objExecObject
Dim iReturnCode

strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
Set objShell = WScript.CreateObject("WScript.Shell")
iReturnCode = objShell.Run(strCmdLine, 1, true)

if iReturnCode = 2 then
' Handle XML validation error

elseif iReturnCode = 1 then
' Handle backup error
elseif iReturnCode = 0 then
' Everything OK
end if
Backup = iReturnCode
Set objShell = nothing
End Function

'******************************************************************************
'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'******************************************************************************
Function HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell

Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" & WScript.ScriptFullName & "\LastRun"

'Check if script has run today
ON ERROR RESUME NEXT
LastRunDate = objShell.RegRead(RegScriptKey)
If LastRunDate = cstr(Date) Then
HasRunToday = true
Else
objShell.RegWrite RegScriptKey, Date,"REG_SZ"
HasRunToday = false
End If
Set objShell = nothing
End Function


'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'* -full Full backup
'* -inc Incremental backup
'* -diff Differential backup
'*
'* Input: None
'* Output: the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
Dim i

for i = 0 to Wscript.Arguments.Count - 1
If Wscript.Arguments(i) = "-full" OR _
Wscript.Arguments(i) = "-inc" OR _
Wscript.Arguments(i) = "-diff" Then
GetBackupTypeParameter = Wscript.Arguments(i)
Exit Function
End If
Next

GetBackupTypeParameter = ""

End Function
Todd Vargo
2014-12-14 03:22:53 UTC
Permalink
Post by Andy K
This vbs script is supposed to only run once a day, but it runs everytime.
Anyone know how to fix it ?
Thanks,
Andy
<snip>
Post by Andy K
'******************************************************************************
'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'******************************************************************************
Function HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" & WScript.ScriptFullName & "\LastRun"
'Check if script has run today
ON ERROR RESUME NEXT
LastRunDate = objShell.RegRead(RegScriptKey)
If LastRunDate = cstr(Date) Then
HasRunToday = true
Else
objShell.RegWrite RegScriptKey, Date,"REG_SZ"
HasRunToday = false
End If
Set objShell = nothing
End Function
<snip>

Here is a crazy idea, disable the OERN and see what error presents
itself. Most likely you don't have permission to assess/create the
registry key.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Dave "Crash" Dummy
2014-12-14 14:08:18 UTC
Permalink
Post by Andy K
This vbs script is supposed to only run once a day, but it runs everytime.
Anyone know how to fix it ?
Thanks,
Andy
'******************************************************************************
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v5.0
'* Modify to add your own functionality if required
'*
<snipped>

I use Macrium Reflect 5.3 to automatically backup my system once a week,
and I have no such script nor any such registry entry. Everything is
contained in a XML file. What did you do to get that script?
--
Crash

Money may not buy happiness, but it can sure defray a lot of unhappiness.
Andy K
2014-12-14 21:00:06 UTC
Permalink
Post by Dave "Crash" Dummy
Post by Andy K
This vbs script is supposed to only run once a day, but it runs everytime.
Anyone know how to fix it ?
Thanks,
Andy
'******************************************************************************
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v5.0
'* Modify to add your own functionality if required
'*
<snipped>
I use Macrium Reflect 5.3 to automatically backup my system once a week,
and I have no such script nor any such registry entry. Everything is
contained in a XML file. What did you do to get that script?
--
Crash
Money may not buy happiness, but it can sure defray a lot of unhappiness.
Macrium lets you take your existing My Backup.xml file and create
a VBS script.

I then put it into my Start Menu.

Andy
Dave "Crash" Dummy
2014-12-14 22:40:13 UTC
Permalink
Post by Andy K
Post by Dave "Crash" Dummy
Post by Andy K
This vbs script is supposed to only run once a day, but it runs everytime.
Anyone know how to fix it ?
Thanks,
Andy
'******************************************************************************
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v5.0
'* Modify to add your own functionality if required
'*
<snipped>
I use Macrium Reflect 5.3 to automatically backup my system once a week,
and I have no such script nor any such registry entry. Everything is
contained in a XML file. What did you do to get that script?
--
Crash
Money may not buy happiness, but it can sure defray a lot of unhappiness.
Macrium lets you take your existing My Backup.xml file and create
a VBS script.
I then put it into my Start Menu.
Okay, I didn't know that. I don't have that option with the free version.
--
Crash

"When you want to fool the world, tell the truth."
~ Otto von Bismarck ~
Andy K
2014-12-14 20:56:49 UTC
Permalink
Post by Andy K
This vbs script is supposed to only run once a day, but it runs everytime.
Anyone know how to fix it ?
Thanks,
Andy
'******************************************************************************
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v5.0
'* Modify to add your own functionality if required
'*
'*
'******************************************************************************
OPTION EXPLICIT
' call the main function
Call VBMain()
'******************************************************************************
'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'******************************************************************************
Sub VBMain()
Dim objShell
Dim ExitCode
' The following function call ensures that this script only runs once a day
If HasRunToday Then
WScript.Quit
End If
Set objShell = WScript.CreateObject("WScript.Shell")
' Do the backup
ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE> ""C:\masm32\SOURCE\Reflect\My Backup.xml""")
' done
Set objShell = nothing
wscript.quit(ExitCode)
End Sub
'******************************************************************************
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'* Optionaly logs output to file
'*
'* Input: strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
Dim objShell
Dim objExecObject
Dim iReturnCode
strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)
' Run the backup or image
Set objShell = WScript.CreateObject("WScript.Shell")
iReturnCode = objShell.Run(strCmdLine, 1, true)
if iReturnCode = 2 then
' Handle XML validation error
elseif iReturnCode = 1 then
' Handle backup error
elseif iReturnCode = 0 then
' Everything OK
end if
Backup = iReturnCode
Set objShell = nothing
End Function
'******************************************************************************
'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'******************************************************************************
Function HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" & WScript.ScriptFullName & "\LastRun"
'Check if script has run today
ON ERROR RESUME NEXT
LastRunDate = objShell.RegRead(RegScriptKey)
If LastRunDate = cstr(Date) Then
HasRunToday = true
Else
objShell.RegWrite RegScriptKey, Date,"REG_SZ"
HasRunToday = false
End If
Set objShell = nothing
End Function
'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'* -full Full backup
'* -inc Incremental backup
'* -diff Differential backup
'*
'* Input: None
'* Output: the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
Dim i
for i = 0 to Wscript.Arguments.Count - 1
If Wscript.Arguments(i) = "-full" OR _
Wscript.Arguments(i) = "-inc" OR _
Wscript.Arguments(i) = "-diff" Then
GetBackupTypeParameter = Wscript.Arguments(i)
Exit Function
End If
Next
GetBackupTypeParameter = ""
End Function
The script does work.

I do not know why it did not work for a while.
Todd Vargo
2014-12-15 03:35:32 UTC
Permalink
On 12/14/2014 3:56 PM, Andy K wrote:> On Saturday, December 13, 2014
Post by Andy K
Post by Andy K
This vbs script is supposed to only run once a day, but it runs everytime.
Anyone know how to fix it ?
Thanks,
Andy
<snip>
Post by Andy K
The script does work.
I do not know why it did not work for a while.
Thanks for providing this feedback. Chalk it up to the Windows behavior
randomizer.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Andy K
2014-12-22 00:22:24 UTC
Permalink
Post by Todd Vargo
On 12/14/2014 3:56 PM, Andy K wrote:> On Saturday, December 13, 2014
Post by Andy K
Post by Andy K
This vbs script is supposed to only run once a day, but it runs
everytime.
Post by Andy K
Post by Andy K
Anyone know how to fix it ?
Thanks,
Andy
<snip>
Post by Andy K
The script does work.
I do not know why it did not work for a while.
Thanks for providing this feedback. Chalk it up to the Windows behavior
randomizer.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Thanks Todd.

Is "Windows behavior randomizer" an actual event ?

The script writes a value in the registry to show it has been run.

But even when it has been run once for the day, it still wants to run the backup a second time.

Maybe there is a batch file method of running the image backup program ?
R.Wieser
2014-12-15 10:54:21 UTC
Permalink
Andy,
Post by Andy K
The script does work.
If it works you would not have a problem with it. Either you are wasting
your own and our time, or you have not told us everything ...
Post by Andy K
I do not know why it did not work for a while.
There you go, thats what you did not tell us. :-\

Bottom line: You have provided us with a problem without giving us all the
relevant details -- those have to be pried outof you, one bit at a time ...
In the mean time we are looking for a problem that might well not be in what
you gave us.

Do you think that would be aceptible when someone asks you for help ?

But to continue with the problem:
If it worked before and works now, don't you think it could be something
*outside* the script that might be the actual problem ? Like maybe a
registry-access permission problem as Todd Vargo mentioned ?

And to go with Todds suggestion: remove the "ON ERROR RESUME NEXT" line. If
registry access is the problem you will than know the moment it happens
again. I almost would suggest to actually *catch* that error and show it to
the user asking him ow to progress, but in this case/script it it would not
add anything of value (aborting is the only choice).

The second thing I would suggest is to create a log-file (of sorts) and
start writing intermediate results of the script into it (as well as a few
"waypoints"). Like, for example, the current and the time read from the
registry, as well as the "do"/"don't do" choice made based upon those times.
That allows you to see, when the script fails, how far it could progress
(and thus where the problem is possibly located).

Regards,
Rudy Wieser
Post by Andy K
Post by Andy K
This vbs script is supposed to only run once a day, but it runs everytime.
Anyone know how to fix it ?
Thanks,
Andy
'***************************************************************************
***
Post by Andy K
Post by Andy K
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v5.0
'* Modify to add your own functionality if required
'*
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
OPTION EXPLICIT
' call the main function
Call VBMain()
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Sub VBMain()
Dim objShell
Dim ExitCode
' The following function call ensures that this script only runs once a day
If HasRunToday Then
WScript.Quit
End If
Set objShell = WScript.CreateObject("WScript.Shell")
' Do the backup
ExitCode = Backup ("""C:\Program
Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE>
""C:\masm32\SOURCE\Reflect\My Backup.xml""")
Post by Andy K
Post by Andy K
' done
Set objShell = nothing
wscript.quit(ExitCode)
End Sub
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'* Optionaly logs output to file
'*
'* Input: strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Function Backup(Byref strCmdLine)
Dim objShell
Dim objExecObject
Dim iReturnCode
strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>",
GetBackupTypeParameter)
Post by Andy K
Post by Andy K
' Run the backup or image
Set objShell = WScript.CreateObject("WScript.Shell")
iReturnCode = objShell.Run(strCmdLine, 1, true)
if iReturnCode = 2 then
' Handle XML validation error
elseif iReturnCode = 1 then
' Handle backup error
elseif iReturnCode = 0 then
' Everything OK
end if
Backup = iReturnCode
Set objShell = nothing
End Function
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Function HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" &
WScript.ScriptFullName & "\LastRun"
Post by Andy K
Post by Andy K
'Check if script has run today
ON ERROR RESUME NEXT
LastRunDate = objShell.RegRead(RegScriptKey)
If LastRunDate = cstr(Date) Then
HasRunToday = true
Else
objShell.RegWrite RegScriptKey, Date,"REG_SZ"
HasRunToday = false
End If
Set objShell = nothing
End Function
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'* -full Full backup
'* -inc Incremental backup
'* -diff Differential backup
'*
'* Input: None
'* Output: the parameter
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Function GetBackupTypeParameter
Dim i
for i = 0 to Wscript.Arguments.Count - 1
If Wscript.Arguments(i) = "-full" OR _
Wscript.Arguments(i) = "-inc" OR _
Wscript.Arguments(i) = "-diff" Then
GetBackupTypeParameter = Wscript.Arguments(i)
Exit Function
End If
Next
GetBackupTypeParameter = ""
End Function
The script does work.
I do not know why it did not work for a while.
Andy K
2014-12-22 00:18:31 UTC
Permalink
Post by R.Wieser
Andy,
Post by Andy K
The script does work.
If it works you would not have a problem with it. Either you are wasting
your own and our time, or you have not told us everything ...
Post by Andy K
I do not know why it did not work for a while.
There you go, thats what you did not tell us. :-\
Bottom line: You have provided us with a problem without giving us all the
relevant details -- those have to be pried outof you, one bit at a time ...
In the mean time we are looking for a problem that might well not be in what
you gave us.
Do you think that would be aceptible when someone asks you for help ?
If it worked before and works now, don't you think it could be something
*outside* the script that might be the actual problem ? Like maybe a
registry-access permission problem as Todd Vargo mentioned ?
And to go with Todds suggestion: remove the "ON ERROR RESUME NEXT" line. If
registry access is the problem you will than know the moment it happens
again. I almost would suggest to actually *catch* that error and show it to
the user asking him ow to progress, but in this case/script it it would not
add anything of value (aborting is the only choice).
The second thing I would suggest is to create a log-file (of sorts) and
start writing intermediate results of the script into it (as well as a few
"waypoints"). Like, for example, the current and the time read from the
registry, as well as the "do"/"don't do" choice made based upon those times.
That allows you to see, when the script fails, how far it could progress
(and thus where the problem is possibly located).
Regards,
Rudy Wieser
Post by Andy K
Post by Andy K
This vbs script is supposed to only run once a day, but it runs
everytime.
Post by Andy K
Post by Andy K
Anyone know how to fix it ?
Thanks,
Andy
'***************************************************************************
***
Post by Andy K
Post by Andy K
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by
Reflect v5.0
Post by Andy K
Post by Andy K
'* Modify to add your own functionality if required
'*
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
OPTION EXPLICIT
' call the main function
Call VBMain()
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Sub VBMain()
Dim objShell
Dim ExitCode
' The following function call ensures that this script only runs once a
day
Post by Andy K
Post by Andy K
If HasRunToday Then
WScript.Quit
End If
Set objShell = WScript.CreateObject("WScript.Shell")
' Do the backup
ExitCode = Backup ("""C:\Program
Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE>
""C:\masm32\SOURCE\Reflect\My Backup.xml""")
Post by Andy K
Post by Andy K
' done
Set objShell = nothing
wscript.quit(ExitCode)
End Sub
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'* Optionaly logs output to file
'*
'* Input: strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Function Backup(Byref strCmdLine)
Dim objShell
Dim objExecObject
Dim iReturnCode
strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>",
GetBackupTypeParameter)
Post by Andy K
Post by Andy K
' Run the backup or image
Set objShell = WScript.CreateObject("WScript.Shell")
iReturnCode = objShell.Run(strCmdLine, 1, true)
if iReturnCode = 2 then
' Handle XML validation error
elseif iReturnCode = 1 then
' Handle backup error
elseif iReturnCode = 0 then
' Everything OK
end if
Backup = iReturnCode
Set objShell = nothing
End Function
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Function HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" &
WScript.ScriptFullName & "\LastRun"
Post by Andy K
Post by Andy K
'Check if script has run today
ON ERROR RESUME NEXT
LastRunDate = objShell.RegRead(RegScriptKey)
If LastRunDate = cstr(Date) Then
HasRunToday = true
Else
objShell.RegWrite RegScriptKey, Date,"REG_SZ"
HasRunToday = false
End If
Set objShell = nothing
End Function
'***************************************************************************
***
Post by Andy K
Post by Andy K
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'* -full Full backup
'* -inc Incremental backup
'* -diff Differential backup
'*
'* Input: None
'* Output: the parameter
'*
'***************************************************************************
***
Post by Andy K
Post by Andy K
Function GetBackupTypeParameter
Dim i
for i = 0 to Wscript.Arguments.Count - 1
If Wscript.Arguments(i) = "-full" OR _
Wscript.Arguments(i) = "-inc" OR _
Wscript.Arguments(i) = "-diff" Then
GetBackupTypeParameter = Wscript.Arguments(i)
Exit Function
End If
Next
GetBackupTypeParameter = ""
End Function
The script does work.
I do not know why it did not work for a while.
Rudy,

You spend a lot of time criticizing me.

Are you perfect and never make mistakes ?

Give me a break.

There are plenty of people who enjoy helping without the criticism.
Todd Vargo
2014-12-22 02:13:15 UTC
Permalink
<snip>
Post by Andy K
Post by R.Wieser
If it worked before and works now, don't you think it could be something
*outside* the script that might be the actual problem ? Like maybe a
registry-access permission problem as Todd Vargo mentioned ?
And to go with Todds suggestion: remove the "ON ERROR RESUME NEXT" line. If
registry access is the problem you will than know the moment it happens
again. I almost would suggest to actually *catch* that error and show it to
the user asking him ow to progress, but in this case/script it it would not
add anything of value (aborting is the only choice).
The second thing I would suggest is to create a log-file (of sorts) and
start writing intermediate results of the script into it (as well as a few
"waypoints"). Like, for example, the current and the time read from the
registry, as well as the "do"/"don't do" choice made based upon those times.
That allows you to see, when the script fails, how far it could progress
(and thus where the problem is possibly located).
Regards,
Rudy Wieser
<snip>
Post by Andy K
Rudy,
You spend a lot of time criticizing me.
Are you perfect and never make mistakes ?
Give me a break.
There are plenty of people who enjoy helping without the criticism.
Please consider judicial pruning of quoted msg. Still waiting to find
out if disabling OERN helped identify the problem.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
R.Wieser
2014-12-22 09:33:30 UTC
Permalink
Andy,
Post by Andy K
You spend a lot of time criticizing me.
Are you perfect and never make mistakes ?
Yes, I'm perfect. Almost that is. I only have a single flaw, and that I
"just know" that I am. :-)

No, I'm making mistakes. Just like you(?). And when I'm pointed towards
one I'm not below admitting to them and apologizing (as I've done in the
past). What about you ?
Post by Andy K
Give me a break.
There are plenty of people who enjoy helping without the criticism.
Yes, in my previous reply I was criticizing you. Not because I want to push
you down, but because I want to make you aware of what you do and its
implications.

If I would just answer your questions I would be supporting you in your
ways, causing you to believe that what(ever) you do is acceptable. It
isn't. And that could result in people starting to ignore you, leaving you
without the help you need. Is that what you aim for ?

But yes, your offhandish "oh, I forgot some important information, quite
likely nullifying all the effort you guys have put into trying to find the
cause of my problem" irritated me, which I expressed in my previous reply.
Deal with it. Just like I now have to deal with yours.

Regards,
Rudy Wieser

P.s.
Someone once said "A good question is worth 50% of the answer". And thats
for more than one reason ...

P.p.s.
Have you found the problem ? What was it ?
Post by Andy K
Post by R.Wieser
Andy,
Post by Andy K
The script does work.
If it works you would not have a problem with it. Either you are wasting
your own and our time, or you have not told us everything ...
Post by Andy K
I do not know why it did not work for a while.
There you go, thats what you did not tell us. :-\
Bottom line: You have provided us with a problem without giving us all the
relevant details -- those have to be pried outof you, one bit at a time ...
In the mean time we are looking for a problem that might well not be in what
you gave us.
Do you think that would be aceptible when someone asks you for help ?
If it worked before and works now, don't you think it could be something
*outside* the script that might be the actual problem ? Like maybe a
registry-access permission problem as Todd Vargo mentioned ?
And to go with Todds suggestion: remove the "ON ERROR RESUME NEXT" line.
If
Post by Andy K
Post by R.Wieser
registry access is the problem you will than know the moment it happens
again. I almost would suggest to actually *catch* that error and show it to
the user asking him ow to progress, but in this case/script it it would not
add anything of value (aborting is the only choice).
The second thing I would suggest is to create a log-file (of sorts) and
start writing intermediate results of the script into it (as well as a few
"waypoints"). Like, for example, the current and the time read from the
registry, as well as the "do"/"don't do" choice made based upon those times.
That allows you to see, when the script fails, how far it could progress
(and thus where the problem is possibly located).
Regards,
Rudy Wieser
Post by Andy K
Post by Andy K
This vbs script is supposed to only run once a day, but it runs
everytime.
Post by Andy K
Post by Andy K
Anyone know how to fix it ?
Thanks,
Andy
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by
Reflect v5.0
Post by Andy K
Post by Andy K
'* Modify to add your own functionality if required
'*
'*
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
OPTION EXPLICIT
' call the main function
Call VBMain()
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
Sub VBMain()
Dim objShell
Dim ExitCode
' The following function call ensures that this script only runs once a
day
Post by Andy K
Post by Andy K
If HasRunToday Then
WScript.Quit
End If
Set objShell = WScript.CreateObject("WScript.Shell")
' Do the backup
ExitCode = Backup ("""C:\Program
Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE>
""C:\masm32\SOURCE\Reflect\My Backup.xml""")
Post by Andy K
Post by Andy K
' done
Set objShell = nothing
wscript.quit(ExitCode)
End Sub
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'* Optionaly logs output to file
'*
'* Input: strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
Function Backup(Byref strCmdLine)
Dim objShell
Dim objExecObject
Dim iReturnCode
strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>",
GetBackupTypeParameter)
Post by Andy K
Post by Andy K
' Run the backup or image
Set objShell = WScript.CreateObject("WScript.Shell")
iReturnCode = objShell.Run(strCmdLine, 1, true)
if iReturnCode = 2 then
' Handle XML validation error
elseif iReturnCode = 1 then
' Handle backup error
elseif iReturnCode = 0 then
' Everything OK
end if
Backup = iReturnCode
Set objShell = nothing
End Function
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
Function HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" &
WScript.ScriptFullName & "\LastRun"
Post by Andy K
Post by Andy K
'Check if script has run today
ON ERROR RESUME NEXT
LastRunDate = objShell.RegRead(RegScriptKey)
If LastRunDate = cstr(Date) Then
HasRunToday = true
Else
objShell.RegWrite RegScriptKey, Date,"REG_SZ"
HasRunToday = false
End If
Set objShell = nothing
End Function
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'* -full Full backup
'* -inc Incremental backup
'* -diff Differential backup
'*
'* Input: None
'* Output: the parameter
'*
'***************************************************************************
Post by Andy K
Post by R.Wieser
***
Post by Andy K
Post by Andy K
Function GetBackupTypeParameter
Dim i
for i = 0 to Wscript.Arguments.Count - 1
If Wscript.Arguments(i) = "-full" OR _
Wscript.Arguments(i) = "-inc" OR _
Wscript.Arguments(i) = "-diff" Then
GetBackupTypeParameter = Wscript.Arguments(i)
Exit Function
End If
Next
GetBackupTypeParameter = ""
End Function
The script does work.
I do not know why it did not work for a while.
Rudy,
You spend a lot of time criticizing me.
Are you perfect and never make mistakes ?
Give me a break.
There are plenty of people who enjoy helping without the criticism.
Todd Vargo
2014-12-23 23:53:53 UTC
Permalink
On 12/22/2014 4:33 AM, R.Wieser wrote:
<judicial pruning>
Post by R.Wieser
But yes, your offhandish "oh, I forgot some important information, quite
likely nullifying all the effort you guys have put into trying to find the
cause of my problem" irritated me, which I expressed in my previous reply.
Deal with it. Just like I now have to deal with yours.
Nice job with that full quoted top posting. I do not see the quoted
sentence above in any of Andy's posts. That is something you made up to
feel justified about climbing up on your soapbox.

FWIW, less than 24 hours after making the original post Andy provided
the following information...

"The script does work.

I do not know why it did not work for a while."

...which is far from what you have mis-translated it to mean.

In the spirit of Christmas, stop being a hum-bug.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
R.Wieser
2014-12-24 11:34:40 UTC
Permalink
Todd,
Post by Todd Vargo
Nice job with that full quoted top posting.
1) Tell me how I could have done that significantly shorter. The OPs message
was just 4 short lines.
2) I quoted the relevant parts I responded to, nothing more.
3) I think that the method I'm using is called "interleaving".
4) What you think is the bottom of a top posting is actually the origional
message in full -- which I state directly above it, so the reader knows he
can stop doing so.

Do you really want to start a flame-war over top/bottom/interleaved/whatever
personal preference ? 'Cause I think that both top and bottom postings are
for the dogs (bottom-posting even more so than top).

So, why the remark ? Just you could start with a "You did it *wrong*"
statement ?
Post by Todd Vargo
I do not see the quoted sentence above in any of Andy's posts.
Thats right. That is because it isn't copy-pasted. Not everything between
quotes is a copy-paste you know. FYI, its purpose was to convey what I felt
Dave, between the lines, said.
Post by Todd Vargo
FWIW, less than 24 hours after making the original post Andy
provided the following information...
Yes, and ? I was caught in those 24 hours, trying to figure out what
could go wrong in the script Dave posted. Wasted time & energy.

And to be honest, I did not see Dave respond in any way to your "disable the
OERN" suggestion, and that also irked me.
Post by Todd Vargo
In the spirit of Christmas, stop being a hum-bug.
LOL. I told Dave off, just as you are now doing to me. How is it that yours
is acceptable, but mine is not ? Go look in the mirror bub, and slap
yourself silly by not living according to your own suggestions to others.

The least you could have done is to have waited till after christmas ...

Regards,
Rudy Wieser
Post by Todd Vargo
<judicial pruning>
Post by R.Wieser
But yes, your offhandish "oh, I forgot some important information, quite
likely nullifying all the effort you guys have put into trying to find the
cause of my problem" irritated me, which I expressed in my previous reply.
Deal with it. Just like I now have to deal with yours.
Nice job with that full quoted top posting. I do not see the quoted
sentence above in any of Andy's posts. That is something you made up to
feel justified about climbing up on your soapbox.
FWIW, less than 24 hours after making the original post Andy provided
the following information...
"The script does work.
I do not know why it did not work for a while."
...which is far from what you have mis-translated it to mean.
In the spirit of Christmas, stop being a hum-bug.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Todd Vargo
2014-12-26 21:42:17 UTC
Permalink
On 12/24/2014 6:34 AM, R.Wieser wrote:

Rudy,
Post by R.Wieser
Post by Todd Vargo
FWIW, less than 24 hours after making the original post Andy
provided the following information...
Yes, and ? I was caught in those 24 hours, trying to figure out what
could go wrong in the script Dave posted. Wasted time & energy.
I responded within 4 hours with the obvious suggestion. It took me less
than 5 minutes to run the relevant code section and found no problems
with it. If you spent more than 5 minutes, that was your choice, not his
fault.
Post by R.Wieser
And to be honest, I did not see Dave respond in any way to your "disable the
OERN" suggestion, and that also irked me.
I don't expect him to. Dave is not the OP. And it don't irk me one bit
if Andy never posts back. I am not emotionally tied to his script issues.
Post by R.Wieser
Post by Todd Vargo
In the spirit of Christmas, stop being a hum-bug.
LOL. I told Dave off, just as you are now doing to me. How is it that yours
is acceptable, but mine is not ? Go look in the mirror bub, and slap
yourself silly by not living according to your own suggestions to others.
The least you could have done is to have waited till after christmas ...
I don't know why you feel the need to "tell anyone off". You made a
grave error, I pointed your attention to it (as you requested), but you
refuse to acknowledge your own mistakes (as you claimed that you do).
Sadly, the demise of your character is your own doing.
R.Wieser
2014-12-28 12:37:07 UTC
Permalink
Todd,
Post by Todd Vargo
If you spent more than 5 minutes, that was your choice,
not his fault.
<advocate of the devil>
So spending less than 5 minutes *isn't* my own choice ?
</advocate of the devil>
:-D

I must say thats a nice try to "shift the blame" there. A bit obvious
though, and I'm afraid that that kind of "reasoning" doesn't go well with
the majority of people.

Or do you really think its only the action of the last person in the whole
line of decisions the one that should be considered ? I'm sure that will
go well with your girlfriend/wife/any female when she gets unprovoked
robbed/mugged/etc and you tell her its her own fault for having made the
choice to step outof the house instead of not having stayed in ...

But, although it was my choice to attempt to help him, it definitily was his
choice to post an incomplete question. Would I even have considered to help
if the question was not asked/posted ? You know, cause-and-effect ?
Post by Todd Vargo
I don't expect him to. Dave is not the OP.
My apologies, I (ofcourse) ment Andy, as he's the OP.
(see how simple it is to acknowledge and apologize for the slip-up ? And
yes, I did just kick myself for making that mistake)
Post by Todd Vargo
And it don't irk me one bit if Andy never posts back
That is why I did not mention it to Andy. It is your problem, not mine.
But that that kind of behaviour -- getting help but not responding to it --
definitily irks me. Combine it with other mistakes and it reaches my limit
quite fast.
Post by Todd Vargo
I don't know why you feel the need to "tell anyone off".
Well, I don't think I did, but *you* do feel that need yourself. Otherwise
you would not have responded like you did. :-)

For what I did ? Yeah, I told Andy what I thought of his "post first,
think/fix later" method *and why*. So he could possibly learn from it. And
than I continued with some suggestion to how to find the cause of his
problem, intending to help him find his scripts problem.

If it was only my intention to "tell him off" I would have stopped before
the "and why" part, don't you think so ?

Oh, by the way: "Please consider judicial pruning of quoted msg"*. Both the
">> In the spirit of" and "> The least you" lines of your quote are not
referenced (directly or otherwise) in your lines/response below it.

*that phrase is your own. Do I need to spell it out for you ? (Also look
at your your other message that day, 16 minutes later,
m77vmb$9nf$***@news.albasani.net, which has been handled anything but
judicial).
Post by Todd Vargo
You made a grave error,
Huh ?

You might have seen one, but apart from making the, as far as I can see and
tried to explain, wrong assumption that I was top-posting I do not see any
"error" I might have made, and much less a "grave" one. So, which one, if
any, are you talking about ?

As for violating the spirit of christmas ? Thats your thing, not mine.

Also, demanding it goes against most everything that your saviour, who's
birthday you claim to want to honor, tried to teach you, in effect making
your demand a simple abuse of his name for your own good ... I hope you
still go to confession each sunday, otherwise you will have something to,
when your time comes, explain to St Peter, the gatekeeper of heaven. :-)
Post by Todd Vargo
(as you requested),
I didn't. Read that line again, but now *carefully*. All I said is that
*when* I'm pointed to it. :-)
Post by Todd Vargo
but you refuse to acknowledge your own mistakes (as you claimed that you
do).

Well pardon me, but I do not drop to my knees and beg for mercy on the first
claim of someone that I did something wrong. I do want to make sure that I
actually made a mistake, and not that it was a misinterpretation of
something I am/was doing.

And, for the record, neither do you. Otherwise you would have done so in
response to my rebuttal, in which I mentioned you being wrong a few times.
So, pot and kettle again ? :-)
Post by Todd Vargo
Sadly, the demise of your character is your own doing.
Yep, the demise of ones character can only be done by one himself. It
cannot be changed by someone claiming that it is happening -- no matter how
much they wish it to be.


And by the way: Its always funny how, when I write a response rebutting made
claims (accusations), most noone, including you, responds to any of them ...
I wonder why ...

Oh, before you say that all of it is nonsense not worth of any response,
take in mind that I could have classified your own, in my eyes quite
bungled, accusations as such, and left it at that. Something I'm quite sure
would not amuse you.

But than again, I get the feeling that you would have simply taken it as a
sign that the other could not respond, and thus you where right.

Regards,
Rudy Wieser

P.s.
I have seen your name in the newsgroups for the longest time, and have
respect for your apparent knowledge. But either you let your some emotion
in the way of, or I simply gave you to much credit in regard to your
wisdom/intelligence.


<sarcasm>
### For any blondes in the reading audience: You can stop reading now. ###

The below is just, as indicated on the line starting with "--", the
origional message I was responding to in the above, and the place I took all
the above quotes from.

Its purpose is to allow someone to check if the quotes are not used
out-of-context by me and possibly get a gist of the posters
between-the-lines message.

It might also be helpfull to anyone in the future not having read the full
thread this message is a part of, to get a bit of a feeling of what its
about.
</sarcasm>
Post by Todd Vargo
Rudy,
Post by R.Wieser
Post by Todd Vargo
FWIW, less than 24 hours after making the original post Andy
provided the following information...
Yes, and ? I was caught in those 24 hours, trying to figure out what
could go wrong in the script Dave posted. Wasted time & energy.
I responded within 4 hours with the obvious suggestion. It took me less
than 5 minutes to run the relevant code section and found no problems
with it. If you spent more than 5 minutes, that was your choice, not his
fault.
Post by R.Wieser
And to be honest, I did not see Dave respond in any way to your "disable the
OERN" suggestion, and that also irked me.
I don't expect him to. Dave is not the OP. And it don't irk me one bit
if Andy never posts back. I am not emotionally tied to his script issues.
Post by R.Wieser
Post by Todd Vargo
In the spirit of Christmas, stop being a hum-bug.
LOL. I told Dave off, just as you are now doing to me. How is it that yours
is acceptable, but mine is not ? Go look in the mirror bub, and slap
yourself silly by not living according to your own suggestions to others.
The least you could have done is to have waited till after christmas ...
I don't know why you feel the need to "tell anyone off". You made a
grave error, I pointed your attention to it (as you requested), but you
refuse to acknowledge your own mistakes (as you claimed that you do).
Sadly, the demise of your character is your own doing.
Todd Vargo
2014-12-22 02:29:38 UTC
Permalink
On 12/21/2014 7:22 PM, Andy K wrote:> On Sunday, December 14, 2014
Post by Andy K
Post by Todd Vargo
On 12/14/2014 3:56 PM, Andy K wrote:> On Saturday, December 13, 2014
Post by Andy K
Post by Andy K
This vbs script is supposed to only run once a day, but it runs
everytime.
Post by Andy K
Post by Andy K
Anyone know how to fix it ?
Thanks,
Andy
<snip>
Post by Andy K
The script does work.
I do not know why it did not work for a while.
Thanks for providing this feedback. Chalk it up to the Windows behavior
randomizer.
Thanks Todd.
Is "Windows behavior randomizer" an actual event ?
No, its more of a "Ghost in the Machine".
Post by Andy K
The script writes a value in the registry to show it has been run.
Is this a verified statement, or are you just stating the intent of the
code?
Post by Andy K
But even when it has been run once for the day, it still wants to run
the backup a second time.

Yes, that is going to be the case if the code did not create/update the
regkey.
Post by Andy K
Maybe there is a batch file method of running the image backup program ?
Possibly but that is beyond my interest and time constraints, sorry.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Mayayana
2014-12-29 03:04:06 UTC
Permalink
I don't know anything about Macrium, but I wonder
about Todd's point. Did you check to see whether
the Registry value is getting written and read back
successfully?

Two possible issues there:

1) WScript.Shell has become
undependable in later Windows version. I use WMI
Registry calls if I want to be sure it will work.

2) I would use a different path. Just make up something
unique, like
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\dailyRun\LastRun"

instead of

RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" &
WScript.ScriptFullName & "\LastRun"

Maybe WScript.ScriptFullName is messing it
up. You're trying to create a number of subkeys
unnecessarily by using the path as a unique
value. You may also be getting "~" into the string.
That may not be a legal character. I don't know.
But there's really no reason to ask for trouble
by making such a long list of subkeys.
--
-
"Andy K" <***@gmail.com> wrote in message news:5ba21dc3-3268-4d57-ad7c-***@googlegroups.com...
| This vbs script is supposed to only run once a day, but it runs everytime.
|
| Anyone know how to fix it ?
|
| Thanks,
| Andy
|
|
|
'******************************************************************************
| '*
| '*
| '* Module Name: My Backup.vbs
| '*
| '* Abstract: This is a template VB Script file generated by Reflect
v5.0
| '* Modify to add your own functionality if required
| '*
| '*
|
'******************************************************************************
|
| OPTION EXPLICIT
|
| ' call the main function
| Call VBMain()
|
|
|
'******************************************************************************
| '* Sub: VBMain
| '*
| '* Purpose: This is main function to start execution
| '*
| '* Input: None
| '*
| '* Output: None
| '*
|
'******************************************************************************
| Sub VBMain()
| Dim objShell
| Dim ExitCode
|
| ' The following function call ensures that this script only runs once a
day
| If HasRunToday Then
| WScript.Quit
| End If
|
| Set objShell = WScript.CreateObject("WScript.Shell")
|
| ' Do the backup
| ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w
<BACKUP_TYPE> ""C:\masm32\SOURCE\Reflect\My Backup.xml""")
|
| ' done
| Set objShell = nothing
| wscript.quit(ExitCode)
| End Sub
|
|
|
'******************************************************************************
| '* Function: Backup
| '*
| '* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
| '* Optionaly logs output to file
| '*
| '* Input: strCmdLine Command Line Arguments
| '* Output: Exit Code
| '*
|
'******************************************************************************
| Function Backup(Byref strCmdLine)
| Dim objShell
| Dim objExecObject
| Dim iReturnCode
|
| strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)
|
| ' Run the backup or image
| Set objShell = WScript.CreateObject("WScript.Shell")
| iReturnCode = objShell.Run(strCmdLine, 1, true)
|
| if iReturnCode = 2 then
| ' Handle XML validation error
|
| elseif iReturnCode = 1 then
| ' Handle backup error
| elseif iReturnCode = 0 then
| ' Everything OK
| end if
| Backup = iReturnCode
| Set objShell = nothing
| End Function
|
|
'******************************************************************************
| '* Function: HasRunToday
| '*
| '* Purpose: determines if this script has run today
| '*
| '*
| '* Input: None
| '* Output: true if has run today false otherwise
| '*
|
'******************************************************************************
| Function HasRunToday
| Dim RegScriptKey
| Dim LastRunDate
| Dim objShell
|
| Set objShell = WScript.CreateObject("WScript.Shell")
| RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" &
WScript.ScriptFullName & "\LastRun"
|
| 'Check if script has run today
| ON ERROR RESUME NEXT
| LastRunDate = objShell.RegRead(RegScriptKey)
| If LastRunDate = cstr(Date) Then
| HasRunToday = true
| Else
| objShell.RegWrite RegScriptKey, Date,"REG_SZ"
| HasRunToday = false
| End If
| Set objShell = nothing
| End Function
|
|
|
'******************************************************************************
| '* Function: GetBackupTypeParameter
| '*
| '* Purpose: determines the backup type from command line parameter
| '* -full Full backup
| '* -inc Incremental backup
| '* -diff Differential backup
| '*
| '* Input: None
| '* Output: the parameter
| '*
|
'******************************************************************************
| Function GetBackupTypeParameter
| Dim i
|
| for i = 0 to Wscript.Arguments.Count - 1
| If Wscript.Arguments(i) = "-full" OR _
| Wscript.Arguments(i) = "-inc" OR _
| Wscript.Arguments(i) = "-diff" Then
| GetBackupTypeParameter = Wscript.Arguments(i)
| Exit Function
| End If
| Next
|
| GetBackupTypeParameter = ""
|
| End Function
|
Andy K
2014-12-29 21:02:39 UTC
Permalink
Post by Mayayana
I don't know anything about Macrium, but I wonder
about Todd's point. Did you check to see whether
the Registry value is getting written and read back
successfully?
1) WScript.Shell has become
undependable in later Windows version. I use WMI
Registry calls if I want to be sure it will work.
2) I would use a different path. Just make up something
unique, like
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\dailyRun\LastRun"
instead of
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" &
WScript.ScriptFullName & "\LastRun"
Maybe WScript.ScriptFullName is messing it
up. You're trying to create a number of subkeys
unnecessarily by using the path as a unique
value. You may also be getting "~" into the string.
That may not be a legal character. I don't know.
But there's really no reason to ask for trouble
by making such a long list of subkeys.
--
-
| This vbs script is supposed to only run once a day, but it runs everytime.
|
| Anyone know how to fix it ?
|
| Thanks,
| Andy
|
|
|
'******************************************************************************
| '*
| '*
| '* Module Name: My Backup.vbs
| '*
| '* Abstract: This is a template VB Script file generated by Reflect
v5.0
| '* Modify to add your own functionality if required
| '*
| '*
|
'******************************************************************************
|
| OPTION EXPLICIT
|
| ' call the main function
| Call VBMain()
|
|
|
'******************************************************************************
| '* Sub: VBMain
| '*
| '* Purpose: This is main function to start execution
| '*
| '* Input: None
| '*
| '* Output: None
| '*
|
'******************************************************************************
| Sub VBMain()
| Dim objShell
| Dim ExitCode
|
| ' The following function call ensures that this script only runs once a
day
| If HasRunToday Then
| WScript.Quit
| End If
|
| Set objShell = WScript.CreateObject("WScript.Shell")
|
| ' Do the backup
| ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w
<BACKUP_TYPE> ""C:\masm32\SOURCE\Reflect\My Backup.xml""")
|
| ' done
| Set objShell = nothing
| wscript.quit(ExitCode)
| End Sub
|
|
|
'******************************************************************************
| '* Function: Backup
| '*
| '* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
| '* Optionaly logs output to file
| '*
| '* Input: strCmdLine Command Line Arguments
| '* Output: Exit Code
| '*
|
'******************************************************************************
| Function Backup(Byref strCmdLine)
| Dim objShell
| Dim objExecObject
| Dim iReturnCode
|
| strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)
|
| ' Run the backup or image
| Set objShell = WScript.CreateObject("WScript.Shell")
| iReturnCode = objShell.Run(strCmdLine, 1, true)
|
| if iReturnCode = 2 then
| ' Handle XML validation error
|
| elseif iReturnCode = 1 then
| ' Handle backup error
| elseif iReturnCode = 0 then
| ' Everything OK
| end if
| Backup = iReturnCode
| Set objShell = nothing
| End Function
|
|
'******************************************************************************
| '* Function: HasRunToday
| '*
| '* Purpose: determines if this script has run today
| '*
| '*
| '* Input: None
| '* Output: true if has run today false otherwise
| '*
|
'******************************************************************************
| Function HasRunToday
| Dim RegScriptKey
| Dim LastRunDate
| Dim objShell
|
| Set objShell = WScript.CreateObject("WScript.Shell")
| RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" &
WScript.ScriptFullName & "\LastRun"
|
| 'Check if script has run today
| ON ERROR RESUME NEXT
| LastRunDate = objShell.RegRead(RegScriptKey)
| If LastRunDate = cstr(Date) Then
| HasRunToday = true
| Else
| objShell.RegWrite RegScriptKey, Date,"REG_SZ"
| HasRunToday = false
| End If
| Set objShell = nothing
| End Function
|
|
|
'******************************************************************************
| '* Function: GetBackupTypeParameter
| '*
| '* Purpose: determines the backup type from command line parameter
| '* -full Full backup
| '* -inc Incremental backup
| '* -diff Differential backup
| '*
| '* Input: None
| '* Output: the parameter
| '*
|
'******************************************************************************
| Function GetBackupTypeParameter
| Dim i
|
| for i = 0 to Wscript.Arguments.Count - 1
| If Wscript.Arguments(i) = "-full" OR _
| Wscript.Arguments(i) = "-inc" OR _
| Wscript.Arguments(i) = "-diff" Then
| GetBackupTypeParameter = Wscript.Arguments(i)
| Exit Function
| End If
| Next
|
| GetBackupTypeParameter = ""
|
| End Function
|
Thanks.

I did not write the script, Macrium Reflect did.

I will look it over and try your suggestions.

If I can not find a fix, there is probably a batch file solution.

Andy
Andy K
2014-12-29 21:36:20 UTC
Permalink
Thanks Mayayana.

Your idea of a different directory worked perfectly. :-)

I am wondering if "& WScript.ScriptFullName &" was causing the problem ?

Andy
Mayayana
2014-12-29 23:36:53 UTC
Permalink
| Your idea of a different directory worked perfectly. :-)
|
| I am wondering if "& WScript.ScriptFullName &" was causing the problem ?
|

That's what I was thinking. Here's what it returns
for me on a script run from TEMP:

C:\DOCUME~1\[username]\LOCALS~1\Temp\wtemp.vbs

The Macrium script is creating 6 unnecessary levels
of subkeys by using the ScriptFullName value. And some
of those keys have names with ~ or :, which may not
be legal characters in the Registry. I'm surprised they'd
distribute something like that. It's poorly designed.
Andy K
2014-12-30 03:11:00 UTC
Permalink
Post by Mayayana
| Your idea of a different directory worked perfectly. :-)
|
| I am wondering if "& WScript.ScriptFullName &" was causing the problem ?
|
That's what I was thinking. Here's what it returns
C:\DOCUME~1\[username]\LOCALS~1\Temp\wtemp.vbs
The Macrium script is creating 6 unnecessary levels
of subkeys by using the ScriptFullName value. And some
of those keys have names with ~ or :, which may not
be legal characters in the Registry. I'm surprised they'd
distribute something like that. It's poorly designed.
Problems often times make life interesting because they make you do research and work.

If things went smooth all the time, it would get boring.

I will send Macrium some feedback so they can have a fix for their next release.

:-)

Andy
Todd Vargo
2014-12-31 03:02:17 UTC
Permalink
Post by Andy K
Post by Mayayana
| Your idea of a different directory worked perfectly. :-)
|
| I am wondering if "& WScript.ScriptFullName &" was causing the problem ?
|
That's what I was thinking. Here's what it returns
C:\DOCUME~1\[username]\LOCALS~1\Temp\wtemp.vbs
The Macrium script is creating 6 unnecessary levels
of subkeys by using the ScriptFullName value. And some
of those keys have names with ~ or :, which may not
be legal characters in the Registry. I'm surprised they'd
distribute something like that. It's poorly designed.
Problems often times make life interesting because they make you do research and work.
If things went smooth all the time, it would get boring.
I will send Macrium some feedback so they can have a fix for their next release.
:-)
Andy
You should first identify the problem before reporting there is one.
It's a template, read the abstract in the header for instructions.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Todd Vargo
2014-12-31 02:39:55 UTC
Permalink
Post by Mayayana
| Your idea of a different directory worked perfectly. :-)
|
| I am wondering if "& WScript.ScriptFullName &" was causing the problem ?
|
That's what I was thinking. Here's what it returns
C:\DOCUME~1\[username]\LOCALS~1\Temp\wtemp.vbs
The Macrium script is creating 6 unnecessary levels
of subkeys by using the ScriptFullName value. And some
of those keys have names with ~ or :, which may not
be legal characters in the Registry. I'm surprised they'd
distribute something like that. It's poorly designed.
That is interesting how it returns 8.3 convention on your system but
returns the full LFN path on mine.

The extra levels of subkeys may seem unnecessary to you, but may be
important to the author who may have several scripts storing lastrun
data. Personally, I store lastrun data in the script where I can easily
see it without need to chase it out of the registry.

I thought about the aspect of the OP moving the file around or renaming
it being a contributor too but chose to wait for OP to report back
results on disabling OERN. No results, no further interest.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Mayayana
2014-12-31 03:15:33 UTC
Permalink
| The extra levels of subkeys may seem unnecessary to you, but may be
| important to the author who may have several scripts storing lastrun
| data.

In that case the path wouldn't necessarily
be unique. I can't think of any plausible reason
to use an entire file path, creating 6 or so
levels of subkeys, just to track a script. I have
to conclude that the author didn't know what
they were doing. If they were tracking several
scripts it would make more sense, and be more
dependable, to just name a separate value for
each one.
R.Wieser
2014-12-31 11:29:59 UTC
Permalink
Mayayana,
I can't think of any plausible reason to use an entire
file path, creating 6 or so levels of subkeys, just to
track a script.
The only explanation I can come up with myself is that the method/function
itself was written to enable usage of the script it was part of from
different locations (folders), and still keep the stored data seperate for
each of those (duplicate) scripts. Which I think is a good reason.

Remember, the OP mentioned that the script was generated. Its solutions
have to cater to a large range of possible usages.

Regards,
Rudy Wieser
| The extra levels of subkeys may seem unnecessary to you, but may be
| important to the author who may have several scripts storing lastrun
| data.
In that case the path wouldn't necessarily
be unique. I can't think of any plausible reason
to use an entire file path, creating 6 or so
levels of subkeys, just to track a script. I have
to conclude that the author didn't know what
they were doing. If they were tracking several
scripts it would make more sense, and be more
dependable, to just name a separate value for
each one.
Mayayana
2014-12-31 15:20:14 UTC
Permalink
| > I can't think of any plausible reason to use an entire
| > file path, creating 6 or so levels of subkeys, just to
| > track a script.
|
| The only explanation I can come up with myself is that the method/function
| itself was written to enable usage of the script it was part of from
| different locations (folders), and still keep the stored data seperate for
| each of those (duplicate) scripts. Which I think is a good reason.
|

If I run a backup script from the Desktop then
I still want to be able to run another backup the
same day by using a copy of the script in C:\?
I can't see how that could possibly make sense.
Even if it did, using the entire file path as a Registry
path is bad design, because it's creating about 6
levels of superfluous subkeys. And what if the script
were moved? There'd be no way to even look up
the value without doing six levels of key enumeration.

There are more sensible ways to store the path of
the script, as a value or even better, as value data,
if that were necessary.

| Remember, the OP mentioned that the script was generated. Its solutions
| have to cater to a large range of possible usages.
|

In that case the script is even more poorly written
than I thought. It's using hard-coded paths for the
Macrium program. It's using WSCript.Shell Registry
ops, which are undependable in later Windows versions.
It's also using the Registry unnecessarily. Why not
use a text-based config file kept where the XML file
is kept? I don't see any reason not to conclude that
the script author didn't know what they were doing.
Andy K
2014-12-31 23:51:25 UTC
Permalink
Post by Mayayana
| > I can't think of any plausible reason to use an entire
| > file path, creating 6 or so levels of subkeys, just to
| > track a script.
|
| The only explanation I can come up with myself is that the method/function
| itself was written to enable usage of the script it was part of from
| different locations (folders), and still keep the stored data seperate for
| each of those (duplicate) scripts. Which I think is a good reason.
|
If I run a backup script from the Desktop then
I still want to be able to run another backup the
same day by using a copy of the script in C:\?
I can't see how that could possibly make sense.
Even if it did, using the entire file path as a Registry
path is bad design, because it's creating about 6
levels of superfluous subkeys. And what if the script
were moved? There'd be no way to even look up
the value without doing six levels of key enumeration.
There are more sensible ways to store the path of
the script, as a value or even better, as value data,
if that were necessary.
| Remember, the OP mentioned that the script was generated. Its solutions
| have to cater to a large range of possible usages.
|
In that case the script is even more poorly written
than I thought. It's using hard-coded paths for the
Macrium program. It's using WSCript.Shell Registry
ops, which are undependable in later Windows versions.
It's also using the Registry unnecessarily. Why not
use a text-based config file kept where the XML file
is kept? I don't see any reason not to conclude that
the script author didn't know what they were doing.
I sent a message to Macrium detailing the bug and the fix.

Andy
Todd Vargo
2015-01-18 06:29:27 UTC
Permalink
On 12/31/2014 6:51 PM, Andy K wrote:

<snip>
Post by Andy K
I sent a message to Macrium detailing the bug and the fix.
So what was their response?
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
R.Wieser
2015-01-01 12:30:57 UTC
Permalink
Mayayana,
Post by Mayayana
If I run a backup script from the Desktop then
I still want to be able to run another backup the
same day by using a copy of the script in C:\?
What tried to say is that the *function* was written to fit into all kinds
of scripts with their different usages. For instance, I could imagine that
such a script could have used a relative path ("script, do your thing on the
folder you're currently in").

(the discussion of if using a relative path is a good idea is a fully
different one. :-) )
Post by Mayayana
Even if it did, using the entire file path as a Registry
path is bad design, because it's creating about 6
levels of superfluous subkeys.
You already said that, and I somewhat agree. But how else would you create
a unique registry-key for each of the scripts that would be simple copies of
each other (meaning: with no change to the script itself) ?
Post by Mayayana
And what if the script were moved? There'd
be no way to even look up the value without
doing six levels of key enumeration.
Huh? That was exactly my point: by using the full pathname those copies
would be considered seperate entities, which I could well imagine would be
intentional.

If you don't do that and all scripts read/write to the same registry key and
the backup-script is using, as I suggested in the above, a relative path all
backups but for the first-executed script today would be skipped -- that
first script would write todays datestamp, which would cause all other
scripts to think they already had done their work..

Also, if that wasn't the intention of the person who made the
script-generator I would have thought he would just have taken an at
"compile-time" generated fixed path (just like you suggested to Andy)
instead of a variable, runtime generated one.
Post by Mayayana
If I run a backup script from the Desktop then
I still want to be able to run another backup the
same day by using a copy of the script in C:\?
Than I would consider you to be making quite a mistake. Its never a good
idea to have multiple instances of programs/scripts around that are
*supposedly* all doing the same thing. Edit one and forget the others /
edit all but one and you get very interresting (and thoroughly confusing)
results :-\ :-)

In that case I would suggest a single script and for the rest just shortcuts
to that one. Or better yet: put the script at a known, central place and
only use shortcuts.
Post by Mayayana
In that case the script is even more poorly written
than I thought. It's using hard-coded paths for the
Macrium program.
Agreed. Trying to cater to all kinds of situations at one spot, but
ignoring it at another isn't quite what I expect myself (I'm assuming here
that the path to the Macrium program is available in the registry too).
Post by Mayayana
It's using WSCript.Shell Registry ops, which are
undependable in later Windows versions.
Thats (with your previous mentioning of it ofcourse) the first time I've
heard about it. Do you have any links to articles outlining the problem ?
I would not like to be caught unaware by it.

But, its quite possible that those Macrium people are not aware of any such
problem themselves either, and have just used their "it worked alright
before and in the tests we've done on the new OS" code again.
Post by Mayayana
It's also using the Registry unnecessarily. Why not
use a text-based config file kept where the XML file
is kept?
I'm not aware of any standard-available Active-X objects which allow you to
write and parse XML files. That would mean they would need to write (big)
functions for that themselves. Thats simply not cost-effective (and adds
quite a bit to the possible point-of-failures).

And to begin with: why use XML when those, rather simple, scriptable
registry-functions are readily available and a basic OS installation ?
Post by Mayayana
I don't see any reason not to conclude that
the script author didn't know what they were doing.
Hmmm... You might not agree to what the author has produced, but if we may
take Andy's word for the script having run as expected I'm not too quick to
agree with you. *Especially* not because we can only guess to what the
author was thinking when he produced what he did.

Also, think of (sales) managers that want to have the finished result *NOW*.
:-\

Regards,
Rudy Wieser
Post by Mayayana
| > I can't think of any plausible reason to use an entire
| > file path, creating 6 or so levels of subkeys, just to
| > track a script.
|
| The only explanation I can come up with myself is that the
method/function
Post by Mayayana
| itself was written to enable usage of the script it was part of from
| different locations (folders), and still keep the stored data seperate for
| each of those (duplicate) scripts. Which I think is a good reason.
If I run a backup script from the Desktop then
I still want to be able to run another backup the
same day by using a copy of the script in C:\?
I can't see how that could possibly make sense.
Even if it did, using the entire file path as a Registry
path is bad design, because it's creating about 6
levels of superfluous subkeys. And what if the script
were moved? There'd be no way to even look up
the value without doing six levels of key enumeration.
There are more sensible ways to store the path of
the script, as a value or even better, as value data,
if that were necessary.
| Remember, the OP mentioned that the script was generated. Its solutions
| have to cater to a large range of possible usages.
In that case the script is even more poorly written
than I thought. It's using hard-coded paths for the
Macrium program. It's using WSCript.Shell Registry
ops, which are undependable in later Windows versions.
It's also using the Registry unnecessarily. Why not
use a text-based config file kept where the XML file
is kept? I don't see any reason not to conclude that
the script author didn't know what they were doing.
R.Wieser
2014-12-30 10:36:49 UTC
Permalink
Andy,
Post by Andy K
I am wondering if "& WScript.ScriptFullName &" was
causing the problem ?
So am I.

You said that in the begin it worked, than stopped doing so, and than
started working again (presumingly) all by its own. If-and-when nothing
else changed the above can't have been the problem. Unless ofcourse
"aliens!" (thats an "internet meme" reference) :-)
Post by Andy K
Your idea of a different directory worked perfectly. :-)
Huh? The last thing I remember you saying that "it did not work for a
while" (yes Todd, thats a quote), leaving me to believe it worked allright
at the time of your posting. Do you now say it *again* stopped working ?

If I would have known than I would have asked what was changed between the
times it did and than didn't work (as far as I can tell you must have moved
the script around), which would have allowed us to zero-in to the problem
instead of the (educated) guess Mayayana has now made.

Also, you would have found this as the problem when you would have followed
Todds suggestion to disable that "on error goto next" line, allowing you to
see that the registry-key could not be read from/written to, giving you a
specific point-of-failure. Why didn't you (follow his suggestion) ?


I said it before, but here it goes again: "a good question makes up at least
50% of the answer".

And no, none of this is ment to belittle you. The better (more complete)
you formulate your problem, the easier it is for us to figure out what is
going awry (apart from the probability that by doing so you suddenly realize
what the problem is yourself). And that enables you, in the future, to ask
far more complex questions while still having a chance to a usable answer.


Compare it to math: an equation like "x+5=7" is rather easy to solve. Now
replace that "5" with "y", and you get a problem that has so many causes
that noone is even going to attempt to solve it.

Same goes for your questions: the more unknowns you leave in there the the
harder it gets for us, the ones you expect a solution from, to give you an
answer. Upto a point where we, when we read your question, not even bother
to attempt. And that leaves you without the answer you need, stopping
whater you where trying to do in its tracks (shifting to batch scripting
only changes the language, not the chance of running into similar, if not
the same problems ...)

All of the above ofcourse without even considering that you, as you now have
done twice, changed the "calculation" itself "halfway into the fray". And
yes, you can consider that as a stern talking-to. Just imagine your math
teacher giving you an equation to solve and some time later just changing
it, forcing you to start all over again. I don't think you would find that
"fair" either.

Regards,
Rudy Wieser
Post by Andy K
Thanks Mayayana.
Your idea of a different directory worked perfectly. :-)
I am wondering if "& WScript.ScriptFullName &" was causing the problem ?
Andy
Loading...