This will be my last post in this thread maybe I should open a new post in the beginners section with the topic "What shell redirects are possible" ;\) .
I have try a lot of combination with redirects but all without any good result.

My question is how can I hide any window from the starting program? --> when I start the program with the runnas.exe!
I my example below it open every time the "CMD.EXE" window, of course I can hide the output in the CMD.EXE window, but not the window itself.

Maybe someone can show me in my small example how I can HIDE any output/window from my starting program (example 1 and 2)?

 Code:
$rc = SetOption('NoVarsInStrings','ON')
$rc = SetOption('Explicit','ON')

; File _dir.cmd
;@ECHO OFF
;DIR %WINDIR% > %1\out.txt

; Example 1
runas(@SCRIPTDIR + '\_dir.cmd ' + @SCRIPTDIR)

; Example 2
;runas('%comspec% /c dir %WINDIR% > ' + @SCRIPTDIR + '\out.txt')

Function runas($cmd)
    Dim $User, $Pass, $runnas
    $User = "DOMAIN\USER"
    $Pass = "PASSWORD"
	$runnas = @SCRIPTDIR + '\runnas.exe'
	RUN $runnas + ' /user:' + $User + ' "' + $cmd + '" /password:' + $Pass + ' /ENV /WAIT'
EndFunction 


So I think it would be a good idea the have an extra switch, as example /HIDE, to hide any output/window from programs which are started with the runnas.exe.

In the meanwhile I have play with AutoIt and now I have an similar function with my "_RunAs.exe", is this possible with the runnas.exe in a similar way -> redirect or whatever?

As example what I mean my AutoIt code......
 Code:
#NoTrayIcon 

;  PARAMETER
; _RunAs /user:USERNAME "command" /password:PASSWORD [/HIDE] [/WAIT]

If $CmdLine[0] > 2 Then
	$Username = StringSplit ( $CmdLine[1], ":")
	If $Username[1] = "/user" Then 
		$Username = $Username[2]
	Else
		_help()
	EndIf
	
	$Domain = StringSplit ( $Username, "\")
	If @error Then
		$Domain = @ComputerName
	Else
		$Username = $Domain[2]
		$Domain = $Domain[1]
	EndIf
	
	$CMD = $CmdLine[2]

	$Password = StringSplit ( $CmdLine[3], ":")
	If $Password[1] = "/password" Then 
		$Password = $Password[2]
	Else
		_help()
	EndIf
Else
	_help()
EndIf

If $CmdLine[0] > 3 Then
	If $CmdLine[4] = "/HIDE" Then 
		$Window = @SW_HIDE 
	Else 
		$Window = @SW_MAXIMIZE 
	EndIf
Else
	$Window = @SW_MAXIMIZE
EndIf

If $CmdLine[0] < 5 Then
	$WAIT = "/NOWAIT"
Else
	$WAIT = $CmdLine[5]
EndIf

If $WAIT = "/WAIT" Then 
	RunAsWait($Username, $Domain, $Password, 0, $CMD, @TempDir,$Window)
Else
	RunAs($Username, $Domain, $Password, 0, $CMD, @TempDir,$Window)
EndIf

exit 0

Func _help()
	MsgBox(64,'Help','_RunAs.exe /user:USERNAME "command" /password:PASSWORD [/HIDE] [/WAIT]' & @CRLF & @CRLF & '<USERNAME> should be in form USER or DOMAIN\USER.')
	Exit
EndFunc





Edited by JJ1 (2008-11-20 05:22 PM)