vyperhand Posted April 2, 2015 Posted April 2, 2015 I have a script that captures all relevant user and system information into a single pop-up screen that can be referenced easily by our helpdesk personnel to save time on information gathering. I have been asked to add a second option to the screen that will give the customer the option to reboot their system. For the life of me, I cannot make that work in an acceptable way. I have tried GUI options to replicate my existing functionality until I've gone cross-eyed, and I cannot seem to figure out how the frack to just add this button and leave everything else in my script operational. Here is the basic script: expandcollapse popupGlobal $strComputer Global $strlist Global $collection Global $objWMI $strComputer="." $strlist="" $objWMI = ObjGet("winmgmts:\\.\root\cimv2") $collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") $colSMBIOS = $objWMI.ExecQuery ("Select * from Win32_SystemEnclosure") $strlist="Computername: " & @TAB & @ComputerName & @CRLF $strlist=$strlist & "Username: " & @TAB & @UserName & @CRLF $strlist=$strlist & "Operating System: " & @TAB & @OSVersion & @CRLF $strlist=$strlist & "OS Patch: " & @TAB & @TAB & @OSServicePack & @CRLF For $objSMBIOS in $colSMBIOS $SN = $objSMBIOS.SerialNumber Next $strlist=$strlist & "Serial or Service Tag: " & @TAB & $SN & @CRLF & @CRLF For $obj In $collection $AdapterName = $obj.Description $IP = $obj.IPAddress $DNS = $obj.DNSServerSearchOrder $Gateway = $obj.DefaultIPGateway Next $strlist=$strlist & $AdapterName & @CRLF $strlist=$strlist & " IP Address: " & @TAB & $IP[0] & @CRLF $strlist=$strlist & " DNS Server 1: " & @TAB & $DNS[0] & @CRLF $strlist=$strlist & " DNS Server 2: " & @TAB & $DNS[1] & @CRLF $strlist=$strlist & " Gateway: " & @TAB & $Gateway[0] & @CRLF $result = MsgBox(0,"System Information", $strlist) I tried replacing $result with this, but it's too easy for the user to reboot unintentionally: $result = MsgBox(68,"System Information", $strlist & @CRLF & "" & @CRLF & "Do you want to reboot this terminal?",0) switch $result case 6 ;YES Run("shutdown -r -f -t 0") case 7 ;NO Exit endswitch What I would like to do is have a separate Reboot? button with a verification pop-up injected right above the OK button - but as soon as I interject any GUI elements at all, I can no longer get it to properly output the massive contents of $strlist. Here's the most recent variation I tried before surrendering: $winders = GUICreate ("System Information") GUISetState(@SW_SHOW) GUICtrlSetData($strlist, -1 , -1) $doReboot = GUICtrlCreateButton("Reboot?", -1 , -1) GUICtrlSetOnEvent($doReboot, "Choice_Reboot") $doneNow = GUICtrlCreateButton ("OK", -1 , -1) GUICtrlSetOnEvent($doneNow, "Done_Now") While 1 Sleep(10) WEnd This gave me a blank window with working buttons, but $strlist was nowhere to be found. Any help would be greatly appreciated.
Kyan Posted April 2, 2015 Posted April 2, 2015 I don't know if I'm understanding your problem right, but if you want to display text, your need to create a label or edit and use GUICtrlSetData to set the text GUICtrlCreateEdit() GUICtrlCreateLabel() Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better
MilesAhead Posted April 2, 2015 Posted April 2, 2015 A simple solution to reduce the chance of unintended reboot would be to make the No Button the default. That way if the user just hits Enter without thinking, it will be NO. My Freeware Page
Moderators JLogan3o13 Posted April 2, 2015 Moderators Posted April 2, 2015 Look at Melba's Extended MsgBox: '?do=embed' frameborder='0' data-embedContent>> "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Moderators Melba23 Posted April 2, 2015 Moderators Posted April 2, 2015 (edited) vyperhand,If you want a dialog with custom button titles, I suggest you use my ExtMsgBox UDF (look in my sig for the link). Then you can do something like this:$result = _ExtMsgBox(0, "Reboot|Exit", "System Information", $strlist) ; Note custom button text Switch $result Case 1 ; First button If MsgBox($MB_SYSTEMMODAL + $MB_YESNO, "Confirm", "Are you sure you want to reboot?") = $IDYES Then ; Here is your confirmation ConsoleWrite("Reboot" & @CRLF) ; Replace this with the reboot code EndIf Case 2 ConsoleWrite("Exit" & @CRLF) EndSwitch ; And we exit here ExitI hope this helps. M23Edit: I see others thought the same. Edited April 2, 2015 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
vyperhand Posted April 2, 2015 Author Posted April 2, 2015 I'll check out Extended MsgBox, thank you both that suggested it. This is really driving me batty, so I hope this works!
ViciousXUSMC Posted April 2, 2015 Posted April 2, 2015 Yes either use Extended MsgBox or a GUI. I have a reboot button in my GUI for techs to use. It follows up with a confirmation so that it is not done on accident. #Region Button12 Restart PC If $nMsg = $Button12 Then $restart = MsgBox(4, "Black Magic GUI", "Restart Computer Now?") If $restart = 6 Then Shutdown(2) EndIf EndIf
vyperhand Posted April 2, 2015 Author Posted April 2, 2015 Looks like that will in fact take care of it - moving to sandbox test now. Thanks again - looks like you've saved what's left of my sanity twice now. So you know, this is what I ended up doing with it: $result = _ExtMsgBox(0, "Reboot|Exit", "System Information", $strlist) Switch $result Case 1 ; First button $confirm = MsgBox(68,"Confirm Reboot", "Are you sure you want to reboot?",0) switch $confirm case 6 ;YES Run("shutdown -r -f -t 60") case 7 ;NO Exit endswitch Case 2 Exit EndSwitch Exit
Moderators Melba23 Posted April 2, 2015 Moderators Posted April 2, 2015 vyperhand,looks like you've saved what's left of my sanityMy pleasure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
vyperhand Posted April 2, 2015 Author Posted April 2, 2015 (edited) OK... so, there are no operational problems at all, now. That's cool. But for some reason, the extmsgbox function output formatting is being super erratic - I can't get it to display the output consistently on any two machines. The text ends up misaligned, sometimes wrapping around the message box, sometimes not. Sometimes my tabbing still results in two neat output columns, on others it zig-zags wildly. Is there a way I can force the message box to just be as wide as the longest line and never wrap a line? Edited April 2, 2015 by vyperhand
nitekram Posted April 3, 2015 Posted April 3, 2015 Yes either use Extended MsgBox or a GUI. I have a reboot button in my GUI for techs to use. It follows up with a confirmation so that it is not done on accident. #Region Button12 Restart PC If $nMsg = $Button12 Then $restart = MsgBox(4, "Black Magic GUI", "Restart Computer Now?") If $restart = 6 Then Shutdown(2) EndIf EndIf I think this might be better? #Region Button12 Restart PC If $nMsg = $Button12 Then If MsgBox(4, "Black Magic GUI", "Restart Computer Now?") = 6 Then Shutdown(2) EndIf my $0.02 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
Moderators Melba23 Posted April 3, 2015 Moderators Posted April 3, 2015 vyperhand, I can't get it to display the output consistently on any two machinesThat is because the various descriptors are of different lengths and so depending on the machine's default font the text after the tab is sometimes pushed to the next stop. You already make a allowance for this effect in this line with its added tab: "OS Patch: " & @TAB & @TAB & @OSServicePack & @CRLFI suggest you use the flexibility of the ExtMsgBox UDF to make the display font monospaced so that you have a consistent descriptor length and can then set the correct number of tabs to align the following text - here is my take on how it might be done:expandcollapse popup#include <MsgBoxConstants.au3> #include <ExtMsgBox.au3> ; You can declare and assign on the same line Global $strComputer = "." Global $strlist = "" Global $objWMI = ObjGet("winmgmts:\\.\root\cimv2") Global $collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") $colSMBIOS = $objWMI.ExecQuery ("Select * from Win32_SystemEnclosure") ; Added @TABs where necessary $strlist="Computername: " & @TAB & @TAB & @ComputerName & @CRLF $strlist &= "Username: " & @TAB & @TAB & @UserName & @CRLF $strlist &= "Operating System: " & @TAB & @OSVersion & @CRLF $strlist &= "OS Patch: " & @TAB & @TAB & @OSServicePack & @CRLF For $objSMBIOS in $colSMBIOS $SN = $objSMBIOS.SerialNumber Next ; Note use of &= to add to the same string $strlist &= "Serial or Service Tag: " & @TAB & $SN & @CRLF & @CRLF For $obj In $collection $AdapterName = $obj.Description $IP = $obj.IPAddress $DNS = $obj.DNSServerSearchOrder $Gateway = $obj.DefaultIPGateway Next $strlist &= $AdapterName & @CRLF $strlist &= " IP Address: " & @TAB & @TAB & $IP[0] & @CRLF ; And what if there is only 1 DNS? Best to do it this way For $i = 0 To UBound($DNS) - 1 $strlist &= " DNS Server " & $i + 1 & ": " & @TAB & $DNS[$i] & @CRLF Next $strlist &= " Gateway: " & @TAB & @TAB & $Gateway[0] & @CRLF ; Set the ExtMsgBox to use default font on the buttons, but a monospaced font for the text _ExtMsgBoxSet(4, Default, Default, Default, 9, "Consolas") $result = _ExtMsgBox(0, "Reboot|Exit", "System Information", $strlist) Switch $result Case 1 ; First button If MsgBox($MB_SYSTEMMODAL + $MB_YESNO, "Confirm", "Are you sure you want to reboot?") = $IDYES Then ; Here is your confirmation ConsoleWrite("Reboot" & @CRLF) ; Replace this with the reboot code EndIf Case 2 ConsoleWrite("Exit" & @CRLF) EndSwitch ; And we exit here ExitI also made a few other changes to your basic script - I hope the comments are self-explanatory. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Bert Posted April 3, 2015 Posted April 3, 2015 Melba - would the display size make any difference? I haven't worked with your code so I have no idea. The Vollatran project My blog: http://www.vollysinterestingshit.com/
vyperhand Posted April 3, 2015 Author Posted April 3, 2015 Thank you again Melba. I took a look, and that concept works as long as there is only one active adapter. If there is a second active adapter (such as VPN or Wireless) the formatting kinda loses it's mind again. I attached a sample of what happened on one of the sandboxes. I appreciate the help you've been, and I will continue tinkering to find a solution that both works and looks decent.
Moderators Melba23 Posted April 3, 2015 Moderators Posted April 3, 2015 vyperhand,That looks as if the text is correctly aligned horizontally, but there is a wrapped line which throws off the vertical sizing. Try using the "Expand Tabs" option like this:_ExtMsgBoxSet(4 + 8, Default, Default, Default, 9, "Consolas")That option was designed for this very case and should force the dialog to be wider and so have room to fit the line. Any better? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
vyperhand Posted April 6, 2015 Author Posted April 6, 2015 Unfortunately, it seems I may have to abandon the ExtMsgBox plan entirely and go back to trying to build a gui, or just chicken out completely and just go back to my original VBScript and use nested yes-no boxes for reboot validation. Adding the parameters above made things look great across 9/10 test platforms... unfortunately on the 10th which is the oldest make/model/OS in our field, I get a 100% replicable error I was unable to resolve. "AutoIt Error Line 4849 <path to script file> Error: Subscript used on non-accessible variable" For now, I'm back to chopping away to try and get the GUI to intelligently put buttons at the bottom while retaining dynamic window width to allow it to expand as necessary on systems with more than one active adapter.
Moderators Melba23 Posted April 6, 2015 Moderators Posted April 6, 2015 vyperhand, I may have to abandon the ExtMsgBox plan entirely and go back to trying to build a guiAn ExtMsgBox is just an standard AutoIt GUI - so that plan does not seem entirely viable. >If you can post the actual text you get in the SciTE console when you run the script on that one recalcitrant machine we might be able to help you determine exactly what is going wrong. What OS is that machine running? AutoIt in its latest releases requires a minimum of XP SP3. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
vyperhand Posted April 6, 2015 Author Posted April 6, 2015 That really was it - see attached. This is from running the compiled .exe on a test machine. Yes, I tried re-compiling. I even re-imaged the machine to fresh in case I'd messed something on it up during other test efforts. The machine is XP SP3, but it's XP embedded. *However*, this error only started with the last change to the ExtMsgBoxSet - the 4+8 option changed from just the 4 option. If I come up with an alternative solution or get my original plan working, I will post it to this thread.
Moderators Melba23 Posted April 6, 2015 Moderators Posted April 6, 2015 vyperhand, this error only started with the last change to the ExtMsgBoxSet - the 4+8 option changed from just the 4 optionI can see nothing linked to that change which jumps out as a possible cause when looking at the UDF code. Can you let me see the script you are using. Attach it to a PM if you do not want to post it in open forum. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now