Page 1 of 2 12>
Topic Options
#181869 - 2007-10-23 09:53 PM WSH issue w/ KF Kode
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
I mentioned this in the scripting forum a while back...

When I use WSHPipe, WSHPing, or any WSH-based function from within a KixForms process, a command window opens momentarily and then disappears. Is there any way to suppress this? It's downright annoying!

Thanks,

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181870 - 2007-10-23 10:06 PM Re: WSH issue w/ KF Kode [Re: Glenn Barnas]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
are you useing kix32.exe or wkix32.exe? well i should have to ask you that, my guess is that there is somthing in the code that is poping the command box, can you post your code?
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#181871 - 2007-10-23 10:53 PM Re: WSH issue w/ KF Kode [Re: Benny69]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
WKix32 - I've associated .kxf with WKix32. Same deal with 4.53 & 4.6.

I doubt it's code, as it happens all the time.

Here's the WSHPipe udf (with headers removed), with a call to Ping Localhost. For me, a console window opens when I run "WKix32 .\test.kxf". I added the sleep commands to simulate the prep that goes on in my other commands. This example illustrates what happens before I instantiate KF, during initialization. Once KF has opened a form, future calls to WSH-related processes pop up additional windows - so it is not KF related.

Glenn
 Code:
Break On

Sleep 3
$a = WSHPipe('ping localhost', 1)
Sleep 3

;Function: 
;   WshPipe() 
; 
;Author: 
;   Christopher Shilt (christopher.shilt@relizon.com) 
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
	Dim $oExec, $Output
	$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
	If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
	$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
	If Not $NoEcho $Output Endif
	$WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10))
	Exit($oExec.ExitCode)
EndFunction


_________________________
Actually I am a Rocket Scientist! \:D

Top
#181878 - 2007-10-24 01:58 AM Re: WSH issue w/ KF Kode [Re: Glenn Barnas]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
I think you are right its not the code.

I have slightly modified the code to show the steps in the code:
 Code:
Break On

Sleep 3
$a = WSHPipe('ping localhost', 1)
Sleep 3

;Function: 
;   WshPipe() 
; 
;Author: 
;   Christopher Shilt (christopher.shilt@relizon.com) 
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
	Dim $oExec, $Output
	
  $oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
  ? 1
  Get $
  
  If Not VarType($oExec) = 9
    $WshPipe="WScript.Shell Exec Unsupported"
    Exit 10
  EndIf
  
  $Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
  ? 2
  Get $
  
  If Not $NoEcho
    $Output
  EndIf
	
  $WshPipe=Split(Join(Split($Output,Chr(13)),''),Chr(10))
  Exit($oExec.ExitCode)
  
EndFunction


I think what is being seen is the output (maybe output is not the correct word) of ping.exe its self.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#181881 - 2007-10-24 04:46 AM Re: WSH issue w/ KF Kode [Re: Benny69]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Gee, thanks - now I have two windows opening! \:o

It's clear that one is from the Ping command, since the title shows "C:\Windows\System32\Ping.exe". The other is the expected window with the output from your "1" "2" statements.

The length of time the Ping window was open was surprising until I added "-n 1" - do that and you'll see just how quickly it flashes by in my app.

So, pal - remember that the goal is to eliminate the WSH window, not add more!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181882 - 2007-10-24 09:15 AM Re: WSH issue w/ KF Kode [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Been a while since I've run it in production but I didn't have any window open that a user could see (back around 4.2x days as I recall.

Try an all new hand coded script (not a kgen version) and see if it still happens for you on a minimal script.

Top
#181888 - 2007-10-24 10:11 AM Re: WSH issue w/ KF Kode [Re: NTDOC]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I think you may be out of luck.

From MS technet article http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_pkoy.mspx?mfr=true (my emphasis)
 Quote:
You might want to run the application in a specified window type, such as a minimized window. Exec offers no control over window style


I can think of a couple of options if it really is a problem for you.
  1. Use WSHShell.RUN instead which has control over the window style. You will need to redirect output to a file and read it in so it's not a great solution.
  2. While you are waiting for the command to complete grab the window and minimise / hide it. The console will flash on the screen.
  3. Start the script from kix32.exe rather than wkix32.exe. If you do this the script will create a console that you can manage, and the WSH Exec will use the same console so you won't have additional ones popping up whenever you run a command. You can SetConsole("HIDE") when your script starts, so it should only be a minor irritation.

Top
#181889 - 2007-10-24 12:36 PM Re: WSH issue w/ KF Kode [Re: Glenn Barnas]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
On the other side you could also use the shell function of kf classic.
It may work but is quite undocumented \:\)

TypeLibrary Viewer on kixforms.dll yields:

Function Shell ([ByVal Cmd]) As Variant

Searching for a sample....
_________________________



Top
#181890 - 2007-10-24 12:45 PM Re: WSH issue w/ KF Kode [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
here is a demo script posted by Shawn on kf.org:


Break On

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Size = 600,400
$Form.Text = "Kixpad"
$Form.FontName = "Tahoma"
$Form.FontSize = 8.25

$CommandLabel = $Form.Controls.Add("Label")
$CommandLabel.Left = 5
$CommandLabel.Top = 5
$CommandLabel.Width = 65
$CommandLabel.Text = "Command:"
$CommandLabel.TextAlign = "MiddleLeft"

$CommandTextBox = $Form.Controls.Add("TextBox")
$CommandTextBox.Top = $CommandLabel.Top
$CommandTextBox.Left = $CommandLabel.Right
$CommandTextBox.Right = $Form.ClientWidth - 90
$CommandTextBox.Anchor = 13
$CommandTextBox.Text = 'cmd /c dir %%systemroot%%'

$ExecuteButton = $Form.Controls.Add("Button")
$ExecuteButton.Text = "Execute"
$ExecuteButton.Top = $CommandLabel.Top
$ExecuteButton.Left = $CommandTextBox.Right + 10
$ExecuteButton.Anchor = 9
$ExecuteButton.OnClick = "ExecuteButton_Click()"

$ListingTextBox = $Form.Controls.Add("TextBox")
$ListingTextBox.MultiLine = "True"
$ListingTextBox.ScrollBars = "Both"
$ListingTextBox.Left = 5
$ListingTextBox.Top = $CommandLabel.Bottom + 5
$ListingTextBox.Right = $Form.ClientWidth - 5
$ListingTextBox.Bottom = $Form.ClientHEight - 35
$ListingTextBox.Anchor = 15
$ListingTextBox.FontName = "Courier New"
$ListingTextBox.FontSize = 10
$ListingTextBox.BackColor = "Black"
$ListingTextBox.ForeColor = "White"
$ListingTextBox.MaxLength = 0

$StyleLabel = $Form.Controls.Add("Label")
$StyleLabel.Left = 5
$StyleLabel.Top = $ListingTextBox.Bottom + 5
$StyleLabel.Width = 80
$StyleLabel.Text = "Window Style"
$StyleLabel.TextAlign = "MiddleLeft"

$StyleComboBox = $Form.Controls.Add("ComboBox")
$StyleComboBox.Top = $StyleLabel.Top
$StyleComboBox.Left = $StyleLabel.Right
$StyleComboBox.Width = 150
$StyleComboBox.DropDownStyle = 2

$WindowStyles = "Hidden", "Normal (focus)", "Minimized (focus)", "Maximized", "Normal", "Minimized"

For Each $Style In $WindowStyles
 $= $StyleComboBox.AddItem($Style)
Next

$StyleComboBox.ListIndex = 4

$CloseButton = $Form.Controls.Add("Button")
$CloseButton.Top = $ListingTextBox.Bottom + 5
$CloseButton.Text = "Close"
$CloseButton.Left = $ExecuteButton.Left
$CloseButton.Anchor = 10
$CloseButton.OnClick = "CloseButton_Click()"

$Form.AcceptButton = $ExecuteButton
$Form.CancelButton = $CloseButton

$Form.Center
$Form.Show

$CommandTextBox.Focus

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function CloseButton_Click()
 $Form.Hide
EndFunction

Function ExecuteButton_Click()

 $WindowStyle = $StyleComboBox.ListIndex

 $ListingTextBox.Text = $System.Shell($CommandTextBox.Text,$WindowStyle,3)

EndFunction


You can set the WindowStyle to hidden, thus no console popup happens, and instead of assigning the console output to a TextBox text property you can assign it to a variable for later analysis \:\)


Edited by Jochen (2007-10-24 01:13 PM)
_________________________



Top
#181893 - 2007-10-24 01:39 PM Re: WSH issue w/ KF Kode [Re: Jochen]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Code Tags, Code Tags! Man, slacker ;\)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#181894 - 2007-10-24 01:42 PM Re: WSH issue w/ KF Kode [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
The above example was hand-coded and it still pops up the box, and the UDF was straigt off KORG. Can't get more basic than that. You can always tell a KGen'd script because line 1 looks like ";;KixGenerated <date>"

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181895 - 2007-10-24 01:47 PM Re: WSH issue w/ KF Kode [Re: Glenn Barnas]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
No,

you just have to select 'hidden' in the dropdown (ComboBox) below the huge black TextBox and the WindowStyle value of the Shell function will get set to 0.

Instead of displaying the result to a textbox like in the demo :

 Quote:

$ListingTextBox.Text = $System.Shell($CommandTextBox.Text,$WindowStyle,3)


you can as well do this :

 Code:

$result = $System.Shell($CommandTextBox.Text,$WindowStyle,3)
if instr($result,"whatever")
    "it's a whatever !!!"
endif



See?
_________________________



Top
#181896 - 2007-10-24 01:48 PM Re: WSH issue w/ KF Kode [Re: Benny69]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 Originally Posted By: Benny69
Code Tags, Code Tags! Man, slacker ;\)


Nay nay, I don't want to see any more of these code scroll pains no more
_________________________



Top
#181897 - 2007-10-24 01:49 PM Re: WSH issue w/ KF Kode [Re: Richard H.]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Thanks, Richard..

1. I was trying to move away from the temp-file issue, which is what I was using with standard "shell" commands.
2. The short duration of the commands - "ping -n 1 host" and "nslookup host" flash so quickly that this isn't practical, unless your DNS is down (which is a bigger issue anyway)
3. I do all my debugging in Kix32 - set a debug flag and monitor the code progress. Never saw the popup then. One issue, though, is that use of MessageBox tends to bring the console above the KF main window, since MessageBox is associated with Kix and not KF process, I suppose.

Too bad WSH can't run as a minimized window, or even on the hidden desktop.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181899 - 2007-10-24 01:53 PM Re: WSH issue w/ KF Kode [Re: Jochen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Undocumented? $#%@$#%$#!! Shawn!!!! Wait till I get my hands on that sheep-___ @$# #$%$# (&*$$ (*%$ Grrrr!

I'm gonna have to give this a try. Thanks, Jochen! (code tags not withstanding;) ) This looks like what I need.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181901 - 2007-10-24 02:56 PM Re: WSH issue w/ KF Kode [Re: Glenn Barnas]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Well, I have to take the undocumented statement back ...

It is a Method of the System object, so I didn't find it immediately :

 Quote:

Kixforms Class Library
Shell Method


Description
Loads and runs a program.

Syntax
object.Shell(command, window-style, redirection)

Parameters
command

Command can be any 16-bit or 32-bit application. To run command interpreter commands, specify the correct command interpreter as part of the command.

window-style (optional)

One of the following values:

Value Setting Description
0 Hidden Window is hidden and focus is passed to the hidden window.
1 Normal (focused) Window has focus and is restored to its original size and position.
2 Minimized (focused) Window is displayed as an icon with focus. This is the default.
3 Maximized Window is maximized with focus.
4 Normal Window is restored to its most recent size and position. The currently active window remains active.
6 Minimized Window is displayed as an icon. The currently active window remains active.


redirection (optional)

One of the following values: Value Setting Description
0 None No redirection. This is the default.
1 Stdout Redirect standard output.
2 Stderr Redirect standard error.
3 Both Redirect both standard output and standard error.


Return Value
If redirection is specified, returns the redirected output as a string; otherwise, returns the integer exit code of the command.

Remarks
Script execution is stopped until the program exits.

Example
$Listing = $System.Shell("cmd /c dir c:\myfolder", 0, 3)

For Each $Line In Split($Listing, @CRLF)
?"Line=" $Line
Next
See Also
Applies To: System



It seems to have problems taking %ComSpec% as input though ...


Edited by Jochen (2007-10-24 03:00 PM)
_________________________



Top
#181904 - 2007-10-24 04:00 PM Re: WSH issue w/ KF Kode [Re: Jochen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
OK - maybe I'm caffiene depleted, but using
 Code:
Break On
Dim $System, $result
$System = CreateObject('Kixtart.System')$result = $System.Shell('cmd.exe /c ping.exe -n 1 fileserver1',0,3)
if instr($result,"TTL=")
    "Responds!" ?
endif

still pops up a window <sssssiip> (Ahhh!)
.
.
.
Oh, wait - that's from the "responds" line!

This is sweet!!

Shawn, I take back what I said, and will buy you the cutest little sheep...

Jochen - thanks for the heads up on this, I'll be adding some KFPing and KFNsLookup UDFs today...

Glenn \:D
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181905 - 2007-10-24 04:23 PM Re: WSH issue w/ KF Kode [Re: Glenn Barnas]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Yeah, no problem, just make sure to add the dependencies list ;\)
_________________________



Top
#188058 - 2008-06-04 11:37 PM Re: WSH issue w/ KF Kode [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh hey, btw.

If you just need to check for a reply of a remote host, my ping() thing udf from a couple years ago WON'T produce any temporary file unless you need to get the resolved host name from an IP address back from it.

I dunno if this was ever set right, and I know this is an old post, but it was just referenced in another post
_________________________



Top
#188059 - 2008-06-05 12:18 AM Re: WSH issue w/ KF Kode [Re: Jochen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Yeah, but Gargoyle wasn't pinging, he was running a command with WSHPipe and it was popping up that annoying CMD screen flash... \:o

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.075 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org