Jump to content

Windows 8 - RunAs


furian
 Share

Recommended Posts

I am trying to do a quick runas script to start various programs with an admin account (not run as administrator though). For some reason i am unable to get the program to start. My password prompt seems to work, but after entering, it just goes away, and nothing starts. The script is very simple... what am I missing?

$sa_user = "username_sa"
$sa_pass = InputBox ("Password", "Please enter your SA password", "", "*")
$user_domain = "domainname"
$app = "C:\Program Files (x86)\Citrix\Citrix Delivery Services Console\Framework\CmiLaunch.exe"

RunAs ( $sa_user, $user_domain, $sa_pass, 1, $app)
Link to comment
Share on other sites

What is the return value of RunAs?

Could you specify a working directory and try again? According to the help file: "It is important to specify a working directory the user you are running as has access to, otherwise the function will fail."

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Did you also try on Windows 7 or another OS?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I changed it slightly, but same results.

This works:

Local $sUserName = "username"
Local $sDomainName = "domain"
Local $sPassword = InputBox ("Password", "Please enter your SA password", "", "*")
Local $sApp = "notepad.exe"
Local $sWorkingDir = "c:usersusername"
RunAs ($sUserName, $sDomainName, $sPassword, 0, $sApp, $sWorkingDir, @SW_SHOWMAXIMIZED)

This does not:

Local $sUserName = "username"
Local $sDomainName = "domain"
Local $sPassword = InputBox ("Password", "Please enter your SA password", "", "*")
Local $sApp = "cmilaunch.exe"
Local $sWorkingDir = "c:usersusername"
RunAs ($sUserName, $sDomainName, $sPassword, 0, $sApp, $sWorkingDir, @SW_SHOWMAXIMIZED)

cmilaunch.exe is a valid executable and its path is in my global path variable. I tested by clicking start run, and it executes.

I have to be missing something very simple here! I'm not sure how to check output of runas, my scripts tend to be very simple, so i don't get that deep into the code.

I tried on both Win 8 and 7 and same results

Edited by furian
Link to comment
Share on other sites

Try using the full path to the exe as well as it's file name. I can run Word from the Run box but I can't run it from a script without the full path in front of the "Winword.exe"/

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Try using the full path to the exe as well as it's file name. I can run Word from the Run box but I can't run it from a script without the full path in front of the "Winword.exe"/

still doesn't work.

Local $sUserName = "username"
Local $sDomainName = "domain"
Local $sPassword = InputBox ("Password", "Please enter your SA password", "", "*")
Local $sApp = "C:Program Files (x86)CitrixCitrix Delivery Services ConsoleFrameworkCmiLaunch.exe"
Local $sWorkingDir = "c:usersusername"
RunAs ($sUserName, $sDomainName, $sPassword, 0, $sApp, $sWorkingDir, @SW_SHOWMAXIMIZED)

I also tried various other executables, such as mmc.exe, and "mmc.exe test.msc" files, with and without paths. i can't get those to work either. Seems only notepad works!

Edited by furian
Link to comment
Share on other sites

Try changing this variable to this:

Local $sApp = '"C:Program Files (x86)CitrixCitrix Delivery Services ConsoleFrameworkCmiLaunch.exe"'

Surround the string with this ' '. The string also needs to contain " ", because you have spacesin your path.

Doesn't work!

I tried this as well:

Local $sUserName = "username"
Local $sDomainName = "domain"
Local $sPassword = InputBox ("Password", "Please enter your SA password", "", "*")
Local $sApp = "C:Progra~2CitrixCitrix~1Framew~1CmiLaunch.exe"
Local $sWorkingDir = "c:usersusername"
RunAs ($sUserName, $sDomainName, $sPassword, 1, $sApp, $sWorkingDir, @SW_SHOWMAXIMIZED)

I have a work around - I just put the path in the cmd file and it will launch this way.... i really need to start saving my scripts for future reference. I have fought this before.

Local $sUserName = "username"
Local $sDomainName = "domain"
Local $sPassword = InputBox ("Password", "Please enter your SA password", "", "*")
Local $sApp = "C:AdminStartscitrixconsole.cmd"
Local $sWorkingDir = "c:usersusername"
RunAs ($sUserName, $sDomainName, $sPassword, 1, $sApp, $sWorkingDir, @SW_SHOWMAXIMIZED)
Edited by furian
Link to comment
Share on other sites

is there anything showing when it doesn't work? Is there an error message or does it just end?

I don't have Windows 8 to test it so I can't really help much if it's a Windows 8 problem only, does it work on Win7 or Vista?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@Furian, Reply #6:

Start, run does *NOT* check, if the program will run, because it's included in the %path% statement (user or system).

Try this:

Start, Run, notepad, OK -> will execute

start, Run, scite, OK -> will execute

Open a CMD.EXE box, working dir = "C:", then...

Type notepad <enter> -> will execute (in path, usually @windir or @systemdir)

Type scite <enter> -> it will *NOT* execute

type start scite <enter> -> it *WILL* execute, amazing at the first glance, isn't it?

The important information for the "Start" functionality is stored here:

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionApp Paths]

There you will find an entry for many executables (including SciTE.exe, when "setup installed"). These keys/vals do the trick, that the named executables *WILL* run from start, run, ... , but *ONLY* from start, run (or "CMD-BOX", "start programname <enter>"), and not from any random "working directory" (implying the EXE's path is not included in the %path% statement)

Regards, Rudi.

<edit: grammar, typo>

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

No errors... just doesn't start. I am running as an administrator. It doesn't work on Windows 7 either. I tried adding it to the App Paths and it doesn't work afterwards.

This is in 64bit key as well

[HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionApp PathsCmilaunch.exe]
@="C:Program Files (x86)CitrixCitrix Delivery Services ConsoleFrameworkcmilaunch.exe"
"Path"="C:Program Files (x86)CitrixCitrix Delivery Services ConsoleFramework"

cmilaunch.exe runs from the start>run menu, as well as from a command line (I added path to global path variable).

While i can get around this, it would be nice to know what is going on. I'm curious as to why notepad.exe works, and mspaint.exe works as well (with no paths), but mmc.exe does not.

Edited by furian
Link to comment
Share on other sites

  • Administrators

notepad.exe/mspaint.exe is manifested as "AsInvoker" so you can run them from any level of user. The other programs are probably "RequireAdministrator" or "HighestAvailable". Basically if the program brings up a UAC prompt, you can't start it directly from RunAs.

Link to comment
Share on other sites

I did not have #RequireAdmin in the front of script. I added, with the same results. UAC is off.

On a whim, i changed the login flag to 0 and got the same result. However, it WORKS when using 2 as the login flag AND #RequireAdmin.

I had picked 1 because I thought I needed a profile. The tool I am using has some discovery options and I need those settings to be retained the next time I launch it. Using 2 appears to retain those settings, so it looks like this resolved.

Final working script:

#RequireAdmin

Local $sUserName = "username"
Local $sDomainName = "domain"
Local $sPassword = InputBox ("Password", "Please enter your SA password", "", "*")
Local $sApp = "C:Progra~2CitrixCitrix~1Framew~1CmiLaunch.exe"
Local $sWorkingDir = "c:usersusername"
RunAs ($sUserName, $sDomainName, $sPassword, 2, $sApp, $sWorkingDir, @SW_SHOWMAXIMIZED)
Edited by furian
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...