Jump to content

Nelson

Members
  • Posts

    25
  • Joined

  • Last visited

Reputation

20 Excellent

About Nelson

  1. 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.
  2. 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
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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 !!
  8. 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 ?
  9. 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
  10. 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
  11. 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.
  12. Many thanks for the suggestion. Another interesting scripting tool ...... must admit that I have never delved into this one. I'll see how I get on over the coming weeks with both Autohotkey and Visual Studio. Thankyou all.
  13. 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.
  14. 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.
  15. 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.
×
×
  • Create New...