Nelson
Members-
Posts
25 -
Joined
-
Last visited
Content Type
Forums
News
20th
EduGeek EDIT Conference
Blogs
Everything posted by Nelson
-
Update to this post. Problem has been solved, albeit a little tortuous. I placed the two lines of code into a batch file and compiled to an exe. Calling the exe file produced an active window. So the menu option now reads: call "E:\My Documents\Downloaded\Programs\ViewBulog.exe" Case closed I believe. Many thanks.
-
Good morning I have an interesting but not desperate problem. A few of my utility/backup menus have options to open log files in notepad. These options are preceded by a reg import line which sets the notepad window size to the text file containing the information. Everything works as expected except that when the notepad window opens it is "inactive" i.e. title bar greyed out. Not a problem but this only ocurred after the reg import line had been added. The reg file was exported from HKEY_CURRENT_USER\Software\Microsoft\Notepad I have tried a few "incarnations" of the start command but all result in the same output. Relevant code for the Backup menu .bat file: reg import "E:\My Documents\Downloaded\Programs\notepadsettingsBU.reg" start "" notepad.exe "E:\My Documents\Downloaded\Programs\backuplog.txt" Any pointers would be most appreciated. Kind regards
-
A further update .... I am pretty sure that there is a problem with the compatability between the tutorial examples I have been using to build the ps1 code and the Powershell version that I have on board (V1 on Vista) as my simple GUI menu that I have been working on also works in ISE but not correctly when "run with Powershell". I probably should look out for examples coded for V1 but who can tell !!! At least I can continue with good old VBS !! Again many thanks for your assistance and have a good day.
-
Good morning and many thanks for your resolution, it works very well and certainly cleans up the source code. Also I can now see where I was struggling. I have 3 such menus so can now roll out the amendment easily. As you may have seen, I have been attempting to rebuild these in GUI Powershell, which I have never looked at until now, but unfortunately have met with possible compatitbility problems between the tutorial examples found on the net and my version of Powershell V.1 ... runs in ISE but fails in Powershell. Anyway that is another story and so for now, with your help, will continue using VBS. Many thanks again and have a good day.
-
Many thanks for looking at this. I have duplicated your command line and sadly I still only get the frame showing for the allotted time !! Strangely, if I create a simple menu form (no countdown), all works fine from the command line. Thoughts are a faulty Powershell.exe or incompatible while loop for Powershell v1.0. Anyway it's not a deal breaker as the main project, GUI menu, appears to be fine .......... interesting though ? Thanks again and have a good day.
-
Apologies - I had to break off for a while before I could send you the updated script ... I have added a further line belt and braces, but still only get a blank form plus title and no text for some reason. The form stays on the screen for the five second duration !! Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing [system.Windows.Forms.Application]::EnableVisualStyles(); $delay = 5 $a=Get-Date -Format "dd/MM/yyyy" [system.Media.SystemSounds]::Asterisk.Play() $Counter_Form = New-Object System.Windows.Forms.Form $Counter_Form.Text = "Archive logs" $Counter_Form.Width = 600 $Counter_Form.Height = 200 $Counter_Form.StartPosition = "CenterScreen" $Counter_Form.BackColor = "#ffffff" $Counter_Label = New-Object System.Windows.Forms.Label $Counter_Label.AutoSize = $true $Counter_Label.ForeColor = "Black" $normalfont = New-Object System.Drawing.Font("Segoe UI",10) $Counter_Label.Font = $normalfont $Counter_Label.Left = 50 $Counter_Label.Top = 30 $Counter_Form.Controls.Add($Counter_Label) while ($delay -ge 1) { $Counter_Form.Show() $Counter_Label.Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds" start-sleep 1 $delay -= 1 } $Counter_Form.Close() I'll keep experimenting for now.
-
Many thanks. I must have missed that link. Adding that line has helped - I now get the GUI form plus title up but unfortunately no text !!
-
Thank you .... but I'm afraid same error ... runs in powershell_ise F5 but fails running from command with exactly the same messages. I like your wee quote ... I too used to work in IT back in the day, on the mighty IBM AS/400 ... where did it all go wrong ?
-
Good morning I am just starting out on powershell and have a short script that outputs a countdown timer. The script runs perfectly in powershell_ise using F5, however when run from command line produces errors. After much searching I cannot find anything relevant to this error. Script and error produced as follows: SCRIPT $delay = 5 $a=Get-Date -Format "dd/MM/yyyy" [system.Media.SystemSounds]::Asterisk.Play() $Counter_Form = New-Object System.Windows.Forms.Form $Counter_Form.Text = "Archive logs" $Counter_Form.Width = 600 $Counter_Form.Height = 200 $Counter_Form.StartPosition = "CenterScreen" $Counter_Form.BackColor = "#ffffff" $Counter_Label = New-Object System.Windows.Forms.Label $Counter_Label.AutoSize = $true $Counter_Label.ForeColor = "Black" $normalfont = New-Object System.Drawing.Font("Segoe UI",10) $Counter_Label.Font = $normalfont $Counter_Label.Left = 50 $Counter_Label.Top = 30 $Counter_Form.Controls.Add($Counter_Label) while ($delay -ge 1) { $Counter_Form.Show() $Counter_Label.Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds" start-sleep 1 $delay -= 1 } $Counter_Form.Close() OUTPUT Microsoft Windows [Version 6.0.6002] Copyright © 2006 Microsoft Corporation. All rights reserved. C:\Users\Richard>powershell c:\countdown.ps1 New-Object : Cannot find type [system.Windows.Forms.Form]: make sure the assembly containing this type is loaded. At C:\countdown.ps1:4 char:27 + $Counter_Form = New-Object <<<< System.Windows.Forms.Form + CategoryInfo : InvalidType: ( [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand Property 'Text' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:5 char:15 + $Counter_Form. <<<< Text = "Archive logs" + CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Property 'Width' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:6 char:15 + $Counter_Form. <<<< Width = 600 + CategoryInfo : InvalidOperation: (Width:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Property 'Height' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:7 char:15 + $Counter_Form. <<<< Height = 200 + CategoryInfo : InvalidOperation: (Height:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Property 'StartPosition' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:8 char:15 + $Counter_Form. <<<< StartPosition = "CenterScreen" + CategoryInfo : InvalidOperation: (StartPosition:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Property 'BackColor' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:9 char:15 + $Counter_Form. <<<< BackColor = "#ffffff" + CategoryInfo : InvalidOperation: (BackColor:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound New-Object : Cannot find type [system.Windows.Forms.Label]: make sure the assembly containing this type is loaded. At C:\countdown.ps1:10 char:28 + $Counter_Label = New-Object <<<< System.Windows.Forms.Label + CategoryInfo : InvalidType: ( [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand Property 'AutoSize' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:11 char:16 + $Counter_Label. <<<< AutoSize = $true + CategoryInfo : InvalidOperation: (AutoSize:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Property 'ForeColor' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:12 char:16 + $Counter_Label. <<<< ForeColor = "Black" + CategoryInfo : InvalidOperation: (ForeColor:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound New-Object : Cannot find type [system.Drawing.Font]: make sure the assembly containing this type is loaded. At C:\countdown.ps1:13 char:25 + $normalfont = New-Object <<<< System.Drawing.Font("Segoe UI",10) + CategoryInfo : InvalidType: ( [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand Property 'Font' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:14 char:16 + $Counter_Label. <<<< Font = $normalfont + CategoryInfo : InvalidOperation: (Font:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Property 'Left' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:15 char:16 + $Counter_Label. <<<< Left = 50 + CategoryInfo : InvalidOperation: (Left:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Property 'Top' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:16 char:16 + $Counter_Label. <<<< Top = 30 + CategoryInfo : InvalidOperation: (Top:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At C:\countdown.ps1:17 char:27 + $Counter_Form.Controls.Add <<<< ($Counter_Label) + CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At C:\countdown.ps1:20 char:21 + $Counter_Form.Show <<<< () + CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Property 'Text' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:21 char:18 + $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds" + CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At C:\countdown.ps1:20 char:21 + $Counter_Form.Show <<<< () + CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Property 'Text' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:21 char:18 + $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds" + CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At C:\countdown.ps1:20 char:21 + $Counter_Form.Show <<<< () + CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Property 'Text' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:21 char:18 + $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds" + CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At C:\countdown.ps1:20 char:21 + $Counter_Form.Show <<<< () + CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Property 'Text' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:21 char:18 + $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds" + CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At C:\countdown.ps1:20 char:21 + $Counter_Form.Show <<<< () + CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Property 'Text' cannot be found on this object; make sure it exists and is settable. At C:\countdown.ps1:21 char:18 + $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds" + CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At C:\countdown.ps1:26 char:20 + $Counter_Form.Close <<<< () + CategoryInfo : InvalidOperation: (Close:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull C:\Users\Richard> I am guessing there is a simple explanation to this and I am misunderstanding the application somewhere, but as I said after much googling have been unable to find anything relevant so any assistance would be greatly received. For your info OS is Vista SP2 and Powershell is v1.0. Many thanks
-
First of all, my best wishes to you all this festive season. I have a question on how to perform a line feed/carriage return for a vbs inputbox. I have tried just about every combination of vbCr vbLf etc plus other suggested "code" but all to no avail. Googling information on the inputbox parameters it says that the vbxx command should be used. I have managed to create the menu satisfactorily by merely spacing the text out (which I don't think shows up here) so this is not a desperate situation, merely a question as to why the "vbxx" codes don't work, For your info, machine running Vista SP2 and original code sample obtained via Google ... I did not know how to go about it myself. Code is: @echo off SETLOCAL SET _prompt=%1 ::Create the VBS script with an echo statement: ECHO Wscript.Echo Inputbox("Please select 1. Email backup 2. Document backup 3. Offsite backup 4. System File check %_prompt%","Utilities Menu")>%TEMP%\~input.vbs :s_GetInput :: Run the vbScript and save the output FOR /f "delims=/" %%G IN ('cscript //nologo %TEMP%\~input.vbs') DO set _string=%%G :: Delete the VBS file DEL %TEMP%\~input.vbs if '%_string%'=='1' goto 1 if '%_string%'=='2' goto 2 if '%_string%'=='3' goto 3 if '%_string%'=='4' goto 4 if '%_string%'=='' goto end :1 start "" "E:\My Documents\Downloaded\Programs\Securityemail.exe" goto end :2 start "" "E:\My Documents\Downloaded\Programs\securitycopy.exe" goto end :3 start "" "E:\My Documents\Downloaded\Programs\SecureOffsite.exe" goto end :4 start "" "E:\My Documents\Downloaded\Programs\SFCProc.exe" goto end :end You will see where the new line code would be tidier !! However output using the line spacing produces the required result. It would be interesting to know how to code these line feeds in this situation. Kind regards
-
Many thanks for the info. There appear to a fair few ways around the "problem" which I will look into with interest. For now my start and taskill as explained in a previous answer, plus a disable then enable of mouse for good measure, is working reasonably well. Although not ideal and very messy. Thanks again.
-
Quite so, as you will see I am going to have a look at Visual Studio ... Thank you for your assistance. I meant to add that the closest answer to this poser I found was to use start command to bring up a "wait" window just before the copy command then taskkill that process after the copy has completed. A rather tortuous way round but it actually works (apart of course for that pesky OK button). Procedure was to create a separate vbs for the wait window then a wscript call in an executable called Backupwait.exe can be used in the start command !!! code extract: :copy taskkill /im thunderbird.exe start "" "E:\My documents\downloaded\programs\backupwait.exe" robocopy "e:\my documents\email" d:\ /s /mir /log:"E:\My Documents\downloaded\programs\securityemail.txt" /tee /np removedrive D: -L taskkill /im wscript.exe I'm still going to revamp it all over time in Visual Studio, but for now the above will suffice.Thanks again for all your suggestions.
-
Many thanks for the information. I must admt that I didn't think there was going to be a way of getting over this problem using the batch script, however your suggestion of Visual Studio Community sounds intriguing and would wile away the upcoming winter evenings. It will be good to get back to a bit of coding .... many years since RPG400 and before that Unique 3GL ... those were the days, dumb terminals and massive mainframes !!!! Thanks again and have a good day.
-
As it stands, the procedure runs faultlessly with a user friendly interface and yes, it could all be run maximised. The question is merely if there was a way of coding a "please wait" message to stay on screen while the backup (2-3 mins duration) runs ... purely aesthetic. Thank you for your suggestion.
-
I have a batch file that runs a backup of my system for off-site storage. The process works perfectly however to enhance the procedure would like a message box to show on-screen (Please wait) whilst the backup command itself runs. I have trawled through the net for ideas and found that Autoit may solve this problem, however I am totally lost with how to make it work. Below is the batch code I am using which is executed from a desktop icon run minimised. echo a = msgbox("SECURITY COPY OF E: DRIVE PROCEDURE" ^& vbCrLf ^& vbCrLf ^& " Please ensure USB stick is in place" ^& vbCrLf ^& "Please do not use computer while files copy" ^& vbCrLf ^& vbCrLf ^& " Do you wish to continue?",vbInformation + vbyesno,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 7 goto no if errorlevel 6 goto check1 :no echo msgbox " Operation cancelled" ^& vbCrLf ^& vbCrLf ^& "Press OK to exit program",vbinformation,"Security copy" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" goto end :check1 IF EXIST D:\ GOTO check2 GOTO noexist1 :noexist1 echo a = msgbox(" USB DRIVE IS NOT CONNECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT USB AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check1 if errorlevel 2 goto no :check2 vol D: | find "Security" if not errorlevel 1 goto copy goto noexist2 :noexist2 removedrive D: -L echo a = msgbox(" INCORRECT USB DRIVE HAS BEEN MOUNTED" ^& vbCrLf ^& " VOLUME SECURITY EXPECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT CORRECT VOLUME AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check2 if errorlevel 2 goto no :copy echo set WshShell = WScript.CreateObject("WScript.Shell") > %temp%\tmp.vbs echo WScript.Quit (WshShell.Popup( "DATA FROM E DRIVE NOW BEING COPIED",5 ,"Security copy", 0 + vbinformation + vbsystemmodal)) >> %temp%\tmp.vbs wscript /nologo %temp%\tmp.vbs robocopy e:\ d:\ /s /mir /log:"E:\My Documents\downloaded\programs\securitycopy.txt" /tee /np /XD $Recycle.bin /XD "System Volume Information" /XD "CDRIP" /XD "DVDTEMP" /XD "E:\My Documents\email" removedrive D: -L echo set WshShell = WScript.CreateObject("WScript.Shell") > %temp%\tmp.vbs echo WScript.Quit (WshShell.Popup( " SECURITY COPY OF E: DRIVE COMPLETED" ^& vbCrLf ^& " USB drive has been released"^& vbCrLf ^& vbCrLf ^& "Do you wish to read log before exiting program ?",30 ,"Security copy", 4 + vbInformation + vbSystemModal)) >> %temp%\tmp.vbs wscript /nologo %temp%\tmp.vbs set "exitcode=%errorlevel%" if errorlevel 7 goto end if errorlevel 6 goto log goto end :log start notepad "E:\My Documents\Downloaded\Programs\securitycopy.txt" goto end :end Basically a please wait message needs to be shown while the robocopy is executing, and if it can be done without resorting to Autoit then all the better !!! If not, well it is not a game changer. Many thanks.
-
Computer - Toshiba Satellite P200. I currently have tasks set up in Task Scheduler which a.wake the computer from hibernation at 3.30am, b. Runs an event log clear, c. Restarts the computer. There then follows a differential backup run using Acronis. I will finally always hibernate the machine after doing any work on it. This "cycle" works perfectly EXCEPT for when we suffer a power cut: for example the power goes off at say 7.00pm for 30mins and is restored well before the laptop battery is exhausted which to my thinking would allow ther wake task to work as normal at 3.30am, but sadly it refuses to wake the machine and my only recourse is to press the power button which resumes from hibernation as normal. This is not a "deal breaker" by any stretch of the imagination however there must be something set somewhere when power is lost, that inhibits the task from running, even though there is power. For information the task is a simple cmd.exe /c "exit" program set to wake the computer. There is also no setting in the BIOS to restart after a power outage, which would have been handy !! If anybody has any ideas I would appreciate the knowledge !!
-
Many thanks Steve ... it works very nicely and has made the two programs virtually bombproof !! They have been compiled to .exe now (iExpress) and tested fully. Below is how I've incorporated the code: Initial messages etc :check1 IF EXIST D:\ GOTO check2 GOTO noexist1 :noexist1 echo a = msgbox(" USB DRIVE IS NOT CONNECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT USB AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check1 if errorlevel 2 goto no :check2 vol D: | find "Security" if not errorlevel 1 goto copy goto noexist2 :noexist2 removedrive D: -L echo a = msgbox(" INCORRECT USB DRIVE HAS BEEN MOUNTED" ^& vbCrLf ^& " VOLUME SECURITY EXPECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT CORRECT VOLUME AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check2 if errorlevel 2 goto no :copy Copy program runs, releases drive then displays report Thank you once again and have a good day.
-
I have a couple of batch files that run backup programs ... one for a full offsite and another smaller one to backup documents, both going to USB drive D:. The volumes are OFFSITE and SECURITY. My question, is there an "IF EXIST volume name" statement I can use in the code to test that the correct drive has been inserted. I am using a test for the drive being present, simply IF EXIST D:\ GOTO which works fine and I have tried various modifications i.e. D:OFFSITE, OFFSITE (D:) etc, but nothing works and there is nothing on the web of any help. Any ideas would be gratefully received. Existing code for drive check as follows: :retry IF EXIST D:\ GOTO run GOTO noexist :noexist echo a = msgbox(" USB DRIVE IS NOT CONNECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT USB AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto retry if errorlevel 2 goto no No ends program and run runs the robocopy.
-
Once again thank you ... it works fine. After ages spent trying to get to the bottom of the problem yesterday, nowhere on the net offered this answer !!! The problem is that there is probably too much imfo out there which some of the time is contradictory and largely unintelligable, at least to a non-scripter like myself. So, I can now complete the batch file tasks and thank both yourself an webman for your time and most importantly concise explanations. Have a good day.
-
Many thanks for the code and insight ... I have been able to adjust the numerous batch files accordingly ..... apart from one, which would certainly benefit from some sort of new line command to make the message shall we say a little more aesthetically pleasing ? I have tinkered about with vbcrlf, vbnewline and even /n in the relevant positions within the maessage body but only see the commands as they are written in. I'm guessing there is another tweak required somewhere. This is definitely not a matter of life or death .... but again an enquiring mind ! Code as follows using your fix. echo a = msgbox("Off-site backup operation selected - ensure drive is connected to USB. Operation will take approx 1hr 30mins so please do not switch off or use the computer until verification message/email is received - Do you want to continue ?",vbInformation + vbyesno,"Event log") > "%temp%\popup.vbs" echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 7 goto no if errorlevel 6 goto yes :no echo msgbox"Operation cancelled",vbinformation,"Event log" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" goto end :yes ----- Operation command goes in here ----- echo msgbox"Operation completed - Press OK to exit",vbinformation,"Event log" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" :end Many thanks again
-
Thank you so much for that - works a treat and I believe I understand explanation for the handing of the codes. You never know, this might rekindle the programmer of days gone by !!! Thanks again and have a great day.
-
I only made it a batch file for simplicity plus the fact I know nothing about Powershell. The closest I got to programming was RPG400 back in the good old days !!! I do have a workaround using command MSGBOX.EX, (found online) this, with YESNO parameter in the command line handles the errorlevels as above. But it would be interesting to know why the return codes from the buttons in MSGBOX don't behave in the same way. Thank you anyway for your prompt reply.
-
For the life of me I cannot seem to get the following "simple" code to work in a batch file. After reading all about return codes for the MSGBOX buttons, I thought that a simple if errorllevel = "" goto would work. I must stress that I am no coder !!!! If anybody could please tell me where my logic is going wrong I would be most grateful. Batch file is as follows: echo msgbox"Operation will be executed - Do you want to continue ?",vbInformation + vbyesno,"Event log" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" if errorlevel 7 goto no if errorlevel 6 goto yes :no echo msgbox"Operation cancelled",vbinformation,"Event log" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" goto end :yes ----- Operation command goes in here ----- echo msgbox"Operation completed - Press OK to exit",vbinformation,"Event log" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" :end Many thanks in advance
