Save MSDOS Script to File


Author
Message
RayGK
RayGK
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 5, Visits: 12
Hi
This is a very basic question from me as a novice user which I’m sure has a simple answer.
My operating system is windows 10
I’m running ‘one click’ image backups from a .bat file created from the program itself.
It works very well but after execution the MSDOS window closes automatically.
As I do not watch the backup process, it would be good to have a text file created during execution confirming the results or simply stop the MSDOS window from closing at the end.
So please recommending addition switches or steps that I should incur [prate in the .bat file to allow this to happen
The batch file I’m using is as follows

"@echo off
REM ******************************************************************************
REM *
REM *
REM * Module Name: My Backup.bat
REM *
REM * Abstract:  This is a template MSDOS batch file generated by Reflect v6
REM *      Modify to add your own functionality if required
REM *
REM *
REM ******************************************************************************

:again
"C:\Program Files\Macrium\Reflect\ReflectBin.exe" -e -w -full "K:\OneDrive\Ray\zSoftware\Macrium Reflect [Image Backup]\Macrium\My Backup.xml" -g

if ERRORLEVEL 3 goto busy
if ERRORLEVEL 2 goto validation_error
if ERRORLEVEL 1 goto backup_error
if ERRORLEVEL 0 goto ok

:busy
REM Will never get here if '-w' switch is used
echo A backup or restore operation is in progress
goto again

:backup_error
REM User cancelling a backup or any other error
echo A Backup error has occured
goto end


:validation_error
REM Command line or XML syntax errors
echo A validation error has occured
goto end


:ok
echo ok!
stop
goto end

:end"

Thanks for help.
Ray

Edited 11 October 2019 10:39 AM by RayGK
dbminter
dbminter
Macrium Evangelist
Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)Macrium Evangelist (7.7K reputation)
Group: Forum Members
Posts: 4.8K, Visits: 52K
Add a Pause command to the end of your .BAT file.  You could put a Pause at the end that would wait for you to press any key to continue and tells you as such as part of the Pause command output.

Edited 11 October 2019 3:40 PM by dbminter
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
If you want the window to stay open, you can add "pause" to the end of the script.  That will cause it to prompt you to press a key to continue before it closes, but that will also mean that if you ever run the script in the background, e.g. as a scheduled task, the task will never close on its own.  The better option is the text output, and Reflect has a way to achieve that, but you'll need to use a PowerShell script rather than a batch file.  Macrium actually recommends using PowerShell or VBS whenever possible and discourages batch files due to some limitation(s) with batch files, although I can't remember the exact details.  Anyhow, here is the KB article about getting text output.  If you need any help customizing your PowerShell script, let me know and I've be happy to help.

Side note: I've always hated batch files because the default double-click action in Windows is to execute them, which is dangerous.  With PowerShell scripts, the default is to open them in Notepad for viewing/editing; if you want to run them, you have to right-click and choose Run.  I once tried changing the default double-click action for batch files to "Edit", but then I realized some installers no longer worked properly because partway through their routine I'd see a batch file pop up in Notepad on my desktop rather than running as it should have.  Sigh....

Edited 12 October 2019 3:01 PM by jphughan
RayGK
RayGK
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 5, Visits: 12
jphughan - 11 October 2019 3:41 PM
If you want the window to stay open, you can add "pause" to the end of the script.  That will cause it to prompt you to press a key to continue before it closes, but that will also mean that if you ever run the script in the background, e.g. as a scheduled task, the task will never close on its own.  The better option is the text output, and Reflect has a way to achieve that, but you'll need to use a PowerShell script rather than a batch file.  Macrium actually recommends using PowerShell or VBS whenever possible and discourages batch files due to some limitation(s) with batch files, although I can't remember the exact details.  Anyhow, here is the KB article about getting text output.  If you need any help customizing your PowerShell script, let me know and I've be happy to help.

Side note: I've always hated batch files because the default double-click action in Windows is to execute them, which is dangerous.  With PowerShel scriptsl, the default is to open them in Notepad for viewing/editing; if you want to run them, you have to right-click and choose Run.  I once tried changing the default double-click action for batch files to "Edit", but then I realized some installers no longer worked properly because partway through their routine I'd see a batch file pop up in Notepad on my desktop rather than running as it should have.  Sigh....

Thanks for offering to help me out with this and so quickly too.
Inserting the 'pause' statement in the batch file worked but I took on board your comments and created a PowerShell script file.
Running the script file without modification worked perfectly but after I added '-noconsole' and
'-RedirectStandardOutput L:\Macrium Image Backup\Log.txt' it failed.
Unfortunately I can't see where I've gone wrong and upon execution, having accepted Windows modification confirmation, the script exits after less than a second so I can’t see any error messages.
I’ve attached the script file if you’d be kind enough to take a look.
I’m running Windows 10
My PC has an SSD C Drive where the O/S and programs, etc are stored a K drive where I store data which is synced to OneDrive
The L drive is a portable hard drive for backups
Thanks for your help and look forward to hearing from you.
Ray


Attachments
My Backup ps1.txt (2 views, 10.00 KB)
RayGK
RayGK
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 5, Visits: 12
RayGK - 12 October 2019 11:37 AM
jphughan - 11 October 2019 3:41 PM
If you want the window to stay open, you can add "pause" to the end of the script.  That will cause it to prompt you to press a key to continue before it closes, but that will also mean that if you ever run the script in the background, e.g. as a scheduled task, the task will never close on its own.  The better option is the text output, and Reflect has a way to achieve that, but you'll need to use a PowerShell script rather than a batch file.  Macrium actually recommends using PowerShell or VBS whenever possible and discourages batch files due to some limitation(s) with batch files, although I can't remember the exact details.  Anyhow, here is the KB article about getting text output.  If you need any help customizing your PowerShell script, let me know and I've be happy to help.

Side note: I've always hated batch files because the default double-click action in Windows is to execute them, which is dangerous.  With PowerShel scriptsl, the default is to open them in Notepad for viewing/editing; if you want to run them, you have to right-click and choose Run.  I once tried changing the default double-click action for batch files to "Edit", but then I realized some installers no longer worked properly because partway through their routine I'd see a batch file pop up in Notepad on my desktop rather than running as it should have.  Sigh....

Thanks for offering to help me out with this and so quickly too.
Inserting the 'pause' statement in the batch file worked but I took on board your comments and created a PowerShell script file.
Running the script file without modification worked perfectly but after I added '-noconsole' and
'-RedirectStandardOutput L:\Macrium Image Backup\Log.txt' it failed.
Unfortunately I can't see where I've gone wrong and upon execution, having accepted Windows modification confirmation, the script exits after less than a second so I can’t see any error messages.
I’ve attached the script file if you’d be kind enough to take a look.
I’m running Windows 10
My PC has an SSD C Drive where the O/S and programs, etc are stored a K drive where I store data which is synced to OneDrive
The L drive is a portable hard drive for backups
Thanks for your help and look forward to hearing from you.
Ray


Sorry; wrong version of the psi file. Correct one now attached.
Attachments
My Backup ps1.txt (3 views, 10.00 KB)
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
If you want to see the output, the easiest way is to open PowerShell Console and start the script from there. Since you’ll be using Reflect, open it with elevated privileges (Run as Administrator). Note that unlike a batch file where you’d type “script.bat”, for PowerShell you have to call a script by typing “.\script.ps1”. However, from reading your script I’m guessing that the culprit might be this line near the top:

$strXmlFilePath = "K:\OneDrive\Ray\zSoftware\Macrium Reflect [Image Backup]\Macrium\My Backup.xml";

You have brackets in your folder path, and brackets are special characters in PowerShell, so that might be preventing that variable from being set correctly, which would in turn prevent Reflect from being directed to that XML file. Assuming you don’t want to rename that actual folder and generate a new script file, you can try changing the double quotes around the XML file path to single quotes, since single quotes in PowerShell mean to take the string literally rather than try to interpret any variables or special characters inside. But I can’t test that at the moment, so if that doesn’t fix it, please post the error output you see in PowerShell Console. Good luck!
Edited 12 October 2019 3:26 PM by jphughan
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
One more thing: If when running your script in PowerShell Console you see an error that script execution isn’t allowed, open an elevated PowerShell Console and type “Set-ExecutionPolicy Unrestricted”. You’ll only have to do that once. It is possible launch PowerShell in a way that allows it to run a script while bypassing the execution policy, but running scripts “manually” requires that your execution policy be configured to allow it — so that might be your issue too.
Edited 12 October 2019 3:14 PM by jphughan
RayGK
RayGK
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 5, Visits: 12
jphughan - 12 October 2019 3:11 PM
One more thing: If when running your script in PowerShell Console you see an error that script execution isn’t allowed, open an elevated PowerShell Console and type “Set-ExecutionPolicy Unrestricted”. You’ll only have to do that once. It is possible launch PowerShell in a way that allows it to run a script while bypassing the execution policy, but running scripts “manually” requires that your execution policy be configured to allow it — so that might be your issue too.

I'm really sorry but I'm going to have to give this up.
To me, PowerShell is about as user fiendly as Fortran 66 was!
I've run PoerShell as administrator and have set “Set-ExecutionPolicy Unrestricted” to All
But having spent 2 or 3 hours on YouTube tutorials I managed to get to the drive L: and folder macrium reflect>macrium
However, I can't even run the script "my backup.ps1"
Googling the problem wasn't much help and logical commands like 'run' or "execute" don't work.
Sorry; I'll just stick with the batch file. It's simple and it works with 'pause' so at least I can be sure the file has executed properly.

jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
I think with a bit of persistence you’d find that PowerSbell is both quite friendly, easier to read/understand, and vastly more powerful than a batch file. If you want to run a script, you just change to the directory to the correct location by entering “cd X:\wherever” just like Commamd Prompt, and then you enter “.\MyScript.ps1”. The dot and backslash at the beginning are important, which is why I called this difference out in the third sentence of my earlier post.
Edited 13 October 2019 11:04 AM by jphughan
RayGK
RayGK
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 5, Visits: 12
Finally, it's all working fine!
Whats been tripping me up all along, is spaces in file and folder names.
Once I had eliminated those, and in one instance just enclosed the path name in double quotes, all worked fine.
Thanks for sticking with me on this and asorry for not re-reading your information on executing a script in powershell.
Ray
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Login

Explore
Messages
Mentions
Search