Jump to content

Autoit "RunAs" Prefix


Recommended Posts

Hi i have been running into a few issue with a simple "RunAs" prefix.

In the help it lists:

RunAs ( "username", "domain", "password", logon_flag, "program" [, "workingdir" [, show_flag [, opt_flag]]] )

if i make those into variables like:

Global $Domain = "Domain.net" OR "Domain" OR "Domain\"
Global $UserName = "ITtest" 
Global $Password = "Password"

Do i include the ".net" at the end for my domain? Or do i use a "domain\" Ect.

I'm new to the forms and not sure the best way to go about posting this.

Link to comment
Share on other sites

  • Moderators

Have you tried all three? Are you getting errors? Have you then looked at the running process in Task Manager to see what user account it is running under? Which works for you?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

As an example run

MsgBox(0, "", @LogonDomain)

to get the name of the domain you are currently logged in.

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

So the "@logonDomain" is what i was looking for there.

but now i'm still having a issue with the "RunAs"

TestRun()

Global $sDomain = @LogonDomain
Global $sUserName = "ITtest"
Global $sPassword = "Password"
Global $sAdminRun = RunAs($sUserName, $sDomain, $sPassword, $RUN_LOGON_NETWORK, $ProgramName)


Func TestRun()
   local $ProgramName = "Z:\Installer Files\TreeSize\TreeSizeProfessional\TreeSize-x64-Full.exe"
   Run($sAdminRun)
   EndFunc

I'm trying to run a program as a different domain user than the one that is currently logged on.

I was trying to use the $ProgramName as a variable for each function but i'm getting a "Not Declared"?

Again i'm pretty new to the whole Autoit Scene but im learning fast.

Link to comment
Share on other sites

First you call the function before you declared your variables.  They are unknown at the moment of your call. Second you the run statement is wrongly formatted (read help file carefully).  Third the runas uses a variable local to a function, thus inaccessible. 

Global $sDomain = @LogonDomain
Global $sUserName = "ITtest"
Global $sPassword = "Password"
Global $ProgramName = "Z:\Installer Files\TreeSize\TreeSizeProfessional\TreeSize-x64-Full.exe"

Global $sAdminRun = RunAs($sUserName, $sDomain, $sPassword, $RUN_LOGON_NETWORK, $ProgramName)
MsgBox (0,"","This is a PID " & $sAdminRun)

There is no need in your code to create a func.

Link to comment
Share on other sites

Thanks Nine and Bert,

I guess my plan was to have a function for each Program install.

I'm doing a lot of upgrades for our AutoCad programs and instead of touching 60+ Workstations i was trying to make a program/Script to run those installers as a Domain Account with Administration access.

I understand what happened with that copy of the script, i realized i was calling before my variables and moved it.

I also looked at your project bert, do you know if there is any way to inject custom fields like "Company Name" "Product Keys" etc. into the batch install for apps that don't have native batch installing? In my case Solid Edge Viewer 2019.

Thanks again guys

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...