Sign in to follow this  
Followers 0
Voltrina

RunAsSet

9 posts in this topic

hi, i'm new to autoit. i created my first script to start up several programs with different credentials. i did that with the example for RunAsSet in the help file, so it looks like this:

RunAsSet('Peter', "MyPC", 'password')
Run('"' & "D:\stuff\program.exe" & '"' & ' "' & @ScriptFullPath & '"', "D:\stuff")

and so on...

this works fine, but i need help with one program, which needs to be started with the "-startup" command. it works with shortcuts where the target is set to:

"D:\stuff\program2.exe" -startup

but i need it with different credentials.. and runasset doesnt work with shortcuts. can you help me?

Share this post


Link to post
Share on other sites



hi, i'm new to autoit. i created my first script to start up several programs with different credentials. i did that with the example for RunAsSet in the help file, so it looks like this:

RunAsSet('Peter', "MyPC", 'password')
Run('"' & "D:\stuff\program.exe" & '"' & ' "' & @ScriptFullPath & '"', "D:\stuff")

and so on...

this works fine, but i need help with one program, which needs to be started with the "-startup" command. it works with shortcuts where the target is set to:

"D:\stuff\program2.exe" -startup

but i need it with different credentials.. and runasset doesnt work with shortcuts. can you help me?

Just add a -startup inside the quotes with a space separating the .exe or whatever.

Share this post


Link to post
Share on other sites

i forgot to say, i already tried that and it says: The parameter is incorrect

Share this post


Link to post
Share on other sites

Voltrina - please post the code that failed so someone can fix it. I noticed that the following code has a convoluted collection of quote marks:

Run('"' & "D:\stuff\program.exe" & '"' & ' "' & @ScriptFullPath & '"', "D:\stuff")

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

First off, your run looks terribly overcomplicated. you do know that the only parameter required for Run() is the path to the executable right? The other stuff might not be required. And if you're getting a parameter incorrect error, it may be from the program and not the run command. Try using ShellExecute() instead and see if you get the same problem.

Aside from that, it sounds like you need to pass different credentials when using this prog?? if so, this is also easy. Seed two variables or arrays with user credentials. Pass the initial credentials to runasset() for when it sounds like a general majority of your program needs them and when you call the function or section of code that uses this special program, just reset runasset() with the new credentials and don't forget to re-reset the credentials back when you're done.


My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
Share on other sites

okay so this(suggested above) fails to work.

RunAsSet('Peter', "MyPC", 'Password')
Run('"' & "D:\szamla\szamlazo.exe -startup" & '"' & ' "' & @ScriptFullPath & '"', "D:\szamla")

the code is from the help file for autoit which is the following:

; This example will rerun itself with admin rights on using a local account
; Note on Vista this may not work as even though the user is admin it may 
; not be elevated even after the RunAs call.  In that case use #RequireAdmin
; at the top of the script.

; Are we already admin?
If Not IsAdmin() Then
    RunAsSet('USER', @Computername, 'PASSWORD')
    Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)
    Exit
EndIf

MsgBox(0, 'Message', 'Now running with admin rights.')

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

RunAsSet('Peter', "MyPC", 'Password')
If StringInStr(@ScriptFullPath, " ") Then
    $quoted_path = @ScriptFullPath
EndIf
;FileChangeDir("D:\szamla")
;Run("D:\szamla\szamlazo.exe -startup " & $quoted_path)
ConsoleWrite(@CR&"D:\szamla\szamlazo.exe -startup " & $quoted_path&@CR)
Run("D:\szamla\szamlazo.exe -startup " & $quoted_path, "D:\szamla")

See if what is in the Console window after you run this, will work in a newly created shortcut. Otherwise you might need to wait until the program is running before you exit the script - if so, you might try RunWait instead of Run. Post all of your code so we can see better what you are trying to do.

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

well, i don't fully understand that, but it works :) thank you for the help!!!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Victory ! :) Of course you should be able to remove commented lines now - lines beginning with a semicolon. The parameters for the run command, especially the first should be as they would be in the shortcut "Properties" menu. In the Run command you embed quotes around any filepath that has space characters in it. The second parameter in the Run command, which occurs after the first comma "," in the functions syntax, corresponds to the folder "Run in" parameter of a shortcut, and shouldn't have embeded quotes no matter what, as far as I know.

Keep on truckin' - you're learning. It's just a matter of trial and error, and studying forum posts, ecetera. :)

In your code, that line that begins with ConsoleWrite, was just for debugging purposes, of course.

Edited by Squirrely1

Das Häschen benutzt Radar

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  
Followers 0