Sign in to follow this  
Followers 0
toofat

RunAsSet

9 posts in this topic

This Script works like a charm:

RunAsSet ("ADMINISTRATOR", @Computername, "ADMINPASS", 0)
 Run ("Notepad.exe")

This one doesn't:

RunAsSet ("REGULARUSER", @Computername, "USERPASS", 0)
 Run ("Notepad.exe")

"Regular User" has loged on to "@Computername" ... When I'm loged on as admin and run Windows RunAs as "Regular User" on Notepad it works OK but when I run Notepad from AutoIt (as "Regular User") it displays "Error: Unable to execute the external program. The directory name is invalid."

Share this post


Link to post
Share on other sites



Hi.

RunAsSet() can enter the security context of any user.

What results does this code give to you?

run ("net user foo bar /add")
RunAsSet("foo",@ComputerName,"bar",0)
RunWait (@ComSpec & " /k set")
MsgBox(0,"","done")

Maybe it's a NTFS rights issue for the user you want to use?

Regards, Rudi.


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

Share this post


Link to post
Share on other sites

Hi.

RunAsSet() can enter the security context of any user.

What results does this code give to you?

run ("net user foo bar /add")
RunAsSet("foo",@ComputerName,"bar",0)
RunWait (@ComSpec & " /k set")
MsgBox(0,"","done")

Maybe it's a NTFS rights issue for the user you want to use?

Regards, Rudi.

Well no change Rudi, returns the same error and it doesn't return error when user has admin rights ... and it's not a problem with directory access rights or @WorkingDir (I have tried all of the combinations and all produce the same error) because I try to run "Notepad" which even guest account can run (and REGULARUSER is just that; "Regular User" and not a guest) ... I have AutoIt ver 3.2.10.0 installed ... which ver do you have ???

Share this post


Link to post
Share on other sites

Try adding a Workdir to the Run() statement that is accessible for the "REGULARUSER".

:D

OK, I'm an idiot. What I've tried to do is

Run ("C:\WINDOWS\NOTEPAD.EXE")

and what I should have done is

Run ("NOTEPAD.EXE", "C:\WINDOWS")

OK, now it works and I am idiot ... Thanks for help ...

Share this post


Link to post
Share on other sites

OK, I'm an idiot. What I've tried to do is

Run ("C:\WINDOWS\NOTEPAD.EXE")

and what I should have done is

Run ("NOTEPAD.EXE", "C:\WINDOWS")

OK, now it works and I am idiot ... Thanks for help ...

Nah, you are not a complete idiot :D

It is common to supply the full path in the first parameter. The real issue you have is that the current workdir is only accessible by the Original User, not the RunAs user, which makes the Run() command fail. In your case it fixed the issue because Windows knows to find notepad, but for any other program it would still fail.

eg:

Run ("C:\program files\myapp.EXE", "C:\WINDOWS")

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Nah, you are not a complete idiot :D

It is common to supply the full path in the first parameter. The real issue you have is that the current workdir is only accessible by the Original User, not the RunAs user, which makes the Run() command fail. In your case it fixed the issue because Windows knows to find notepad, but for any other program it would still fail.

eg:

Run ("C:\program files\myapp.EXE", "C:\WINDOWS")

Jos

OK Jos I understand that this won't work

Run ("C:\program files\myapp.EXE", "C:\WINDOWS")

Trust me when I say that I understand that if User1 tries to access dir that only User2 has access to he will not succed, through Windows, through RunAs (loged on as User2 or admin but RunAsSet is configured for User1) or even through Black Magic :-)) ...

But can you explain to me why for admin this works

RunAsSet ("ADMINISTRATOR", @Computername, "ADMINPASS", 0)
Run ("Notepad.exe")

and for regular user it must be written like this

RunAsSet ("REGULARUSER", @Computername, "USERPASS", 0)
Run ("Notepad.exe", "C:\WINDOWS")

I will say one more time that Regular User has access to "C:\WINDOWS" (full read access just not admin rights), that he has allready loged on and ... Why for admin you don't have to specify WorkingDir and for Regular user you do ??? Thanks for help and I would apriciate the answer and sorry for bad speling :D ...

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

From which directory are you starting this script and does the REGULARUSER have access to this script directory ?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

From which directory are you starting this script and does the REGULARUSER have access to this script directory ?

Jos

OK now I see what you are getting at :D . Yes, REGULARUSER does not have access to the script dir. I execute the script like admin but ... OK, I understand. When I get home I will try to execute it from some dir that REGULARUSER has access to. Thank you very much :D ... The solution is so logical and so clear to me now. Like I've sad before; I'm an idiot. NTFS basics. Yes, yes, I'm an idiot.

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