Jump to content

RunAsSet problems...


emmanuel
 Share

Recommended Posts

I've got a problem with this script, I can't get the runasset to kick off right... doesn't seem to work with any local acount, though neither does the domain account I tried...

I've added a line to copy the file locally if the user isn't an admin and to run it from there, to allow for not having access to the server with the local account.

give it a glance if you've got a chance?

AutoItSetOption("RunErrorsFatal", 0)

$UserName = "administrator"
$Password = 'password'

$RUN = 0
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
; set to admin mode
If $RUN = 0 Then
   If Not IsAdmin() Then      
      If FileCopy(@ScriptFullPath, @TempDir, 1) = 0 Then
         MsgBox(0, "error", "error copying install app")
         Exit
      EndIf
      
      RunAsSet($UserName, @ComputerName, $Password,0)
     ; start the script program (itself) again but now in Adminmode...so all done tasks will run in Adminmode
     ;~       Run('"' & @ScriptFullPath & '" " 1"') 

      $AdminRunPath = '"' & @TempDir & "\" & FileGetShortName(@ScriptName) & '" 1"'
MsgBox(4096,'debug:' , '$adminrunpath:' & $adminrunpath);### Debug MSGBOX  to check the path to the app that's to be run
      Run($adminrunpath) 

      If @error = 1 Then
         MsgBox(48, "Error", "Cannot start Admin mode.")  ;this is getting triggered everytime.
      EndIf
      Exit
   EndIf
EndIf

I just had a odd thoght, would a symbol in the password cause issues?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Try FileGetShortPath(@TempDir & "\" & @ScriptName) instead

<{POST_SNAPBACK}>

ok, tried that, same problem.

just tried putting notepad instead of $adminrunpath and get the same error. So, it's down to runas not working right...

tried doing runas /user:computer\administrator "pathto.exe" at the cmd prompt and got an error, even though I can login with the same local admin name and password!

what's going on?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Just a thought.

Keep in mind (quoted fro the help file):

<{POST_SNAPBACK}>

yeah, I didn't check that, but I did try a manual runas and that also requires those same service(s)... the manual failed for the local admin account but worked for the domain account... but the domain account doesn't work in script.

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Another thought

Are you running the script from a local drive or from a mapped network drive?

Mapping can be lost when runAsSet

<{POST_SNAPBACK}>

that's actually why I've put the clause in there to copy the file locally (to temp) if the user's not an admin before running it from temp as an admin.

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Hiya,

this may be a stupid question, but is that the whole script or is there more? Cause it doesnt seem to do anything if parameter is 1 or you are admin ...?

And i think theres a wrong quote in your line (at the end):

$AdminRunPath = '"' & @TempDir & "\" & FileGetShortName(@ScriptName) & '" 1"'

should be:

$AdminRunPath = '"' & @TempDir & "\" & FileGetShortName(@ScriptName) & '" 1'

Greetings,

ZeD

Link to comment
Share on other sites

  • Developers

that's actually why I've put the clause in there to copy the file locally (to temp) if the user's not an admin before running it from temp as an admin.

<{POST_SNAPBACK}>

emmanuel, the issue is that the directory you are running the script from, isn't there anymore for the run command, since this is executed under the other credentials. You were also missing a double quote around the 1.

To solve this specify the StartupDir in the Run command like:

$AdminRunPath = '"' & FileGetShortName(@TempDir & "\" & @ScriptName) & '" " 1"'
      MsgBox(4096, 'debug:', '$adminrunpath:' & $AdminRunPath);### Debug MSGBOX  to check the path to the app that's to be run
      Run($AdminRunPath,@TempDir)

@ZeDMIN: this script restart itself to enable you to add function to it like reading/updating the registry that also require admin rights.

So yea there will be more below the endif..

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

emmanuel, the issue is that the directory you are running the script from, isn't there anymore for the run command, since this is executed under the other credentials. You were also missing a double quote around the 1.

To solve this specify the StartupDir in the Run command like:

$AdminRunPath = '"' & FileGetShortName(@TempDir & "\" & @ScriptName) & '" " 1"'
      MsgBox(4096, 'debug:', '$adminrunpath:' & $AdminRunPath);### Debug MSGBOX  to check the path to the app that's to be run
      Run($AdminRunPath,@TempDir)

<{POST_SNAPBACK}>

I was really hoping you were right, but it doesn't seem to be so. I got the same error, then also coppied the file to the local desktop and got this error (I restored RunErrorsFatal to default to see if I could get more details)

---------------------------

AutoIt Error

---------------------------

Line 0  (File "K:\viewer\psemaps upgrade.exe"):

Run($AdminRunPath, @TempDir)

Error: Unable to execute the external program.

Logon failure: unknown user name or bad password.

---------------------------

OK 

---------------------------

I also can't seem to get this to work manualy:

C:\>runas /user:2psebs60\administrator ""C:\Documents and Settings\eplesh\Local Settings\Temp\psemaps upgrade.exe" " 1""

or a host of other quote combos all return the syntax help for runas...

oh, \ by the " like this:

C:\>runas /user:2psebs60\administrator "C:\Documents and Settings\eplesh\Local Settings\Temp\psemaps upgrade.exe\" 1\""

but, it doesn't want to work. It says that my password is bad. I can login to this box with the same user/pass and the RunAs Service is started and running...

found it, here's what works at the command prompt:

C:\>runas /user:2psebs60\administrator "\"C:\Documents and Settings\eplesh\Local Settings\Temp\psemaps upgrade.exe\" 1\""

It's making me wonder exactly how autoit's passing the quotes to the runas service, and how it might be effected.

GAH!!!! I'm going to go jump off the roof and try to impale myself on some nice rebar at the building site nextdoor. Hopefully through the head.

I had wondered if symbols in the password were giving me problems... so I put it in double quotes. someone shoot me.

it works now, Jdeb you rock, once more you save the day by pointing out the obvious... I'd just had to go and screw myself up more...

if we lived in the same country I'd buy you a beer for this one.

"I'm not even supposed to be here today!" -Dante (Hicks)

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