mrfite Posted April 15, 2010 Posted April 15, 2010 I am trying to make a script that will make a GUI for the windows msg.exe program. The problem is that the msg.exe command has switches. I want to capture input from the gui interface and use those variables for the switches for msg.exe. This is my code so far: $Computer = InputBox("Messenger", "Enter the name of the Computer to Send a message to.") $Time = InputBox("Messenger", "Enter the number of seconds you wish the message to display.") $Message = InputBox("Messenger", "Please type your message now.") $msg = "C:\Windows\System32\msg.exe" runwait( @comspec & " /c msg * /server:Computer /Time:$Time $Message") Any help is appreciated.
Fulano Posted April 15, 2010 Posted April 15, 2010 (edited) Well, your main problem is with the way you are inserting the variables into the command string. Here is the correct way, with a few mild improvements to make debugging easier. I do not have Vista, so I cannot test this, and don't know what, if any, output the program generates. For this reason I have set it up to be as verbose as possible. expandcollapse popup;Changes to this part do the following: InputBoxes will time out after 2 minutes. If you press 'Cancel' or don't include a value then the message will ;not send. 30 is set as the default message duration Local $Computer = InputBox("Messenger", "Enter the name of the Computer to Send a message to.", "", Default, Default, Default, Default, Default, 120) If @error Or Not $Computer Then Exit Local $Time = InputBox("Messenger", "Enter the number of seconds you wish the message to display.", "30", Default, Default, Default, Default, Default, 120) If @error Or Not $Time Then Exit Local $Message = InputBox("Messenger", "Please type your message now.", "", Default, Default, Default, Default, Default, 120)) If @error Or Not $Message Then Exit ;Run the command, capturing any output from the program Local $msg_exe = "C:\Windows\System32\msg.exe" Local $Debug = RunGetText( @comspec & " /c " & $msg_exe & " * /server:" & $Computer & " /Time:" & $Time & " " & $Message, Default, @SW_HIDE, 60*3) ;Write any output to the console for debugging ConsoleWrite ($Debug) ;$command = full path to the exe ;$workingDir = full path of working directory ;$showFlag = passes value directly to Run() command, see Run() documentation ;$timeOut = time before expiring in seconds Func RunGetText ($command, $workingDir, $showFlag, $timeOut) $timeOut *= 1000 Local $pid = Run ($command, $workingDir, $showFlag, 0x8) Local $returnText For $i = 0 to 5 Local $startTime = TimerInit () While 1 Local $temp = StdoutRead ($pid) If @error Then ExitLoop $returnText &= $temp If TimerDiff ($startTime) > $timeOut Then StdioClose ($pid) $returnText = "" ExitLoop EndIf WEnd If $returnText Then ExitLoop Next Return $returnText EndFunc Edited April 15, 2010 by Fulano #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!
mrfite Posted April 15, 2010 Author Posted April 15, 2010 Well, your main problem is with the way you are inserting the variables into the command string. Here is the correct way, with a few mild improvements to make debugging easier. I do not have Vista, so I cannot test this, and don't know what, if any, output the program generates. For this reason I have set it up to be as verbose as possible. expandcollapse popup;Changes to this part do the following: InputBoxes will time out after 2 minutes. If you press 'Cancel' or don't include a value then the message will ;not send. 30 is set as the default message duration Local $Computer = InputBox("Messenger", "Enter the name of the Computer to Send a message to.", "", Default, Default, Default, Default, Default, 120) If @error Or Not $Computer Then Exit Local $Time = InputBox("Messenger", "Enter the number of seconds you wish the message to display.", "30", Default, Default, Default, Default, Default, 120) If @error Or Not $Time Then Exit Local $Message = InputBox("Messenger", "Please type your message now.", "", Default, Default, Default, Default, Default, 120)) If @error Or Not $Message Then Exit ;Run the command, capturing any output from the program Local $msg_exe = "C:\Windows\System32\msg.exe" Local $Debug = RunGetText( @comspec & " /c " & $msg_exe & " * /server:" & $Computer & " /Time:" & $Time & " " & $Message, Default, @SW_HIDE, 60*3) ;Write any output to the console for debugging ConsoleWrite ($Debug) ;$command = full path to the exe ;$workingDir = full path of working directory ;$showFlag = passes value directly to Run() command, see Run() documentation ;$timeOut = time before expiring in seconds Func RunGetText ($command, $workingDir, $showFlag, $timeOut) $timeOut *= 1000 Local $pid = Run ($command, $workingDir, $showFlag, 0x8) Local $returnText For $i = 0 to 5 Local $startTime = TimerInit () While 1 Local $temp = StdoutRead ($pid) If @error Then ExitLoop $returnText &= $temp If TimerDiff ($startTime) > $timeOut Then StdioClose ($pid) $returnText = "" ExitLoop EndIf WEnd If $returnText Then ExitLoop Next Return $returnText EndFunc Thanks for your assistance but I am still having trouble When running the above script, I get no output. The msg.exe program is formated the following way in DOS. msg * /server:COMPUTERNAME /Time:NUMBEROFSECONDS MESSAGE What this does is it sends a popup message (MESSAGE) to all users on the computer (COMPUTERNAME) it will display it for so many seconds (NUMBEROFSECONDS) The input boxes work correctly but I am getting no output.
Fulano Posted April 15, 2010 Posted April 15, 2010 I'm not familiar with msg.exe, but it might not output any information at the command line. If you could run it manually and post what is printed at the prompt, as well as running it and having it fail on purpose, then I might be able to help. I have XP, and msg.exe is Vista and Windows 7 specific, so I can't test it myself. #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!
mrfite Posted April 15, 2010 Author Posted April 15, 2010 It has no output at the command line. example: C:\>msg * /server:mis2 /time:55555 Test Message C:\> yields the attached file as a popup window.
Fulano Posted April 15, 2010 Posted April 15, 2010 Ok, so that means that nothing would be returned by the RunGetText function. As to why the infobox isn't showing up, I'll have to leave that to our friends out there who've got Vista/7 machines to test it on. #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!
MHz Posted April 16, 2010 Posted April 16, 2010 Let us go back to the original question. I am trying to make a script that will make a GUI for the windows msg.exe program. The problem is that the msg.exe command has switches. I want to capture input from the gui interface and use those variables for the switches for msg.exe. ... Not quite a question but the wanting is bolded. mrfite, You want the input to work correct that is added to RunWait(). This is how I interpret this question and no reference to output. With some error checking added, this seems like it may work. $Computer = InputBox("Messenger", "Enter the name of the Computer to Send a message to.") If Not @error And $Computer Then ; Not error and $Computer nneds to be something to be valid $Time = InputBox("Messenger", "Enter the number of seconds you wish the message to display.") If Not @error And $Time Then ; Not error and $Time needs to be something to be valid $Message = InputBox("Messenger", "Please type your message now.") If Not @error Then ; Not error and no message can be valid? ;$msg = "C:\Windows\System32\msg.exe" RunWait('"' & @ComSpec & '" /c msg * "/server:' & $Computer & '" "/Time:' & $Time & '" "' & $Message & '"') EndIf EndIf EndIf Creating your own GUI would look much better with all input controls on one main GUI and better handling of errors so it can try again for the users sanity.
mrfite Posted April 16, 2010 Author Posted April 16, 2010 Let us go back to the original question. Not quite a question but the wanting is bolded. mrfite, You want the input to work correct that is added to RunWait(). This is how I interpret this question and no reference to output. With some error checking added, this seems like it may work. $Computer = InputBox("Messenger", "Enter the name of the Computer to Send a message to.") If Not @error And $Computer Then ; Not error and $Computer nneds to be something to be valid $Time = InputBox("Messenger", "Enter the number of seconds you wish the message to display.") If Not @error And $Time Then ; Not error and $Time needs to be something to be valid $Message = InputBox("Messenger", "Please type your message now.") If Not @error Then ; Not error and no message can be valid? ;$msg = "C:\Windows\System32\msg.exe" RunWait('"' & @ComSpec & '" /c msg * "/server:' & $Computer & '" "/Time:' & $Time & '" "' & $Message & '"') EndIf EndIf EndIf Creating your own GUI would look much better with all input controls on one main GUI and better handling of errors so it can try again for the users sanity. Works like a charm. Thank you for your help!
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