Jump to content
Sign in to follow this  

Hide a command line window with Runasset

Recommended Posts


Hi all,

I'm trying to run programs with a admin account, it works fine but the windows is visible. Here is part of the code

Runasset ($AdminAccount, $DomainName, $AdminPassword)

Run (@Comspec & " /c " & "dsquery " & $target & " -samid " & $Computername & "$" & " -limit 0 | dsget " & $target & " -memberof >> " & $CompInfoBuffer , "c:\temp", @SW_HIDE)


If i try the same without runasset, the windows won't appear

Any help would be greatly apprecited.


Share this post

Link to post
Share on other sites

I don't know why the window isn't hide with the runasset(), but you can try to use the WinSetState() call to hide it when it appears...

Share this post

Link to post
Share on other sites

Only works with *.exe-files (obviously)

; AutoIt Version: 3.0
; Language:    English
; Platform:    Win9x/NT/XP
; Author:        jos van der Zande
AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 

$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0      ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
; commands go here that require Administrator rights

Share this post

Link to post
Share on other sites

I asked this same question many moons ago... If I remember correctly, it's because of some built-in Windows security type thing that won't let you start a program running as a different user as hidden. My work around was to run the AutoIt script as another user, which of course has no window by default, and then have the script do a regular Run() call to run the program.

Something like this (this example needs to be compiled, but there are ways you can do it without compiling):

If $CmdLine[0] < 1 Then
  RunAsSet('USERNAME', @ComputerName, 'ASSWORD')
  Run(@AutoItExe & ' /runasset')
ElseIf $CmdLine[1] = '/runasset' Then

*Edit: Looks like someone beat me to it. :whistle:

Edited by Saunders

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.