Solved

CMD shell scripting runas

Posted on 2014-01-29
21
460 Views
Last Modified: 2014-02-05
Below I have two statements: the first runs fine, the second gives access denied, even whn I run the script "As Administrator" Both run fine when manually inserted onto the CMD line

Any idea what I am missing? Thanks!

%windir%\system32\runas.exe /profile /env /user:domain\jdarby2 "C:\Program Files (x86)\Internet Explorer\iexplore.exe"

%windir%\system32\runas.exe /profile /env /user:domain\jdarby2 "C:\Windows\explorer.exe"
0
Comment
Question by:johndarby
21 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
This may help:
http://www.youtube.com/watch?v=OGHQzg69vsg

If not, let me know. :)
0
 
LVL 1

Author Comment

by:johndarby
Comment Utility
Thanks; I have been running as Local Admin already, but inside the script execution access to C:\Windows is restricted.
0
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
I would think that you'll need to lower the UAC setting.  Sometimes it's the only way.
0
 
LVL 1

Author Comment

by:johndarby
Comment Utility
UAC settings are set by GPO and cannot be changed without a bunch of hassle :/
0
 
LVL 1

Author Comment

by:johndarby
Comment Utility
Update: I lowered UAC to never notify and took ownership of the \Windows directory to the LocalAdmins group; I made sure the account referred in RUNAS is a member of LocalAdmin group...still no love :(
0
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
This is just running locally on your own machine (not through a remote session or virtual box or anything)?
0
 
LVL 1

Author Comment

by:johndarby
Comment Utility
Yes; it is local...the error almost acts like UAC wants to prompt for elevated perms (run as Admin) and is unable to spawn the Message window. However, UAC has been turned off :/
0
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
I've requested more experts on this.  Wish I had a quicker answer for you.

Just a thought: What if you referenced a shortcut to explorer instead of explorer.exe directly?

My guess is that Microsoft restricted this in a update because it proved to be a security hole (someone can, after all, do a lot of damage with explorer.exe while in the windows directory).
0
 
LVL 1

Author Comment

by:johndarby
Comment Utility
Thanks sl8rz,

I think you're on the path...it may be some REG change necessary to execute in the form I have it above. I could go back to my initial need and see if any other method might be suggested:

I need to regularly open a explorer window with an alternate user with specific perms to remote directories.
0
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
There's the crux of the matter isn't it...opening an explorer window in someone else's profile?  I don't think that would be intentionally block by Microsoft, if the user has admin privileges and the other profile was not admin.  However, if the other profile is admin then I'm not so sure.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:johndarby
Comment Utility
Both ad local admin; the "other" account is also a Domain Admin
0
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
I'll try this against both admin and non-admin; it won't surprise me if it works against the non-admin account.  If it does, then we'll know that we are dealing with a security barrier designed specifically to prevent this particular action.
0
 
LVL 1

Author Comment

by:johndarby
Comment Utility
Thank you
0
 
LVL 15

Expert Comment

by:David L. Hansen
Comment Utility
No joy.  I think Microsoft is purposefully trying to prevent this.
0
 
LVL 1

Author Comment

by:johndarby
Comment Utility
I will dig a bit more
0
 
LVL 36

Accepted Solution

by:
Jian An Lim earned 250 total points
Comment Utility
it is called explorer /separate in windows XP
but windows 7, there is a lot of resistance.

this article explains how to do so, but use with cares
http://superuser.com/questions/290940/how-to-launch-windows-explorer-with-the-privileges-of-a-different-domain-user
0
 
LVL 38

Assisted Solution

by:Rich Rumble
Rich Rumble earned 250 total points
Comment Utility
If explorer is running already, you may want to kill it first for it to work as you intend from the CLI.

Might even try http://technet.microsoft.com/en-us/sysinternals/cc300361
http://social.technet.microsoft.com/Forums/windows/en-US/1798a1a7-bd2e-4e42-8e98-0bc715e7f641/unable-to-open-an-elevated-windows-explorer-window?forum=w7itprosecurity
You may want to use runas with the /NOPROFILE switch instead, you may also look at the /trustlevel switch too.
-rich
0
 
LVL 35

Expert Comment

by:Nick Sui
Comment Utility
Try these:

1st with Local Admin to see if it works:

%windir%\system32\runas.exe /profile /env /user:local_Admin "C:\Windows\explorer.exe"

2nd with cmd.exe /k switch as below:

%windir%\system32\runas.exe /profile /env /user:domain\jdarby2 "cmd.exe /c C:\Windows\explorer.exe"

2nd command isolates two commands to be executed in its own area.

Try and let us know.
Sys.
0
 
LVL 16

Expert Comment

by:gurutc
Comment Utility
Hi,

Our GPOs are very locked down as well.  Even when logged in as a local admin and starting  using "run as administrator" you're going to have issues if... your scripts are on the C: drive. UAC is a bear about running scripts from C:.  Try them from the D: drive and see if that works.  Also, using the /env and /profile switches will also break things because they'll try to write the temp info to the user's profile folder temp location - which is on the C: drive.

Not promising this is your issue, but it's dinged us in the past.  We get around this by using Sysinternals psexec  to launch things like explorer with the -h switch to elevate, the -s switch to use system impersonation, and the -w switch to force the working directory to somewhere not on C:.

Good Luck,
- gurutc
0
 
LVL 1

Author Closing Comment

by:johndarby
Comment Utility
Thank you all! The reg edit worked. :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now