Jump to content

Hide a command line window with Runasset


Xavier
 Share

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)

Runasset()

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

Any help would be greatly apprecited.

Xavier

Link to comment
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) 


Break(0)
$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")
   Exit
EndIf
; commands go here that require Administrator rights
Link to comment
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
  Run('C:\Program.exe')
EndIf

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

Edited by Saunders
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...