Solved

Powershell Runas Explorer

Posted on 2011-09-30
7
1,396 Views
Last Modified: 2012-05-12
I am new to windows pwershell. I am working on my first cmdlet. I want to open explorer as a runas for another user. I want to add to the code to automaticall add in our domain so that we just have to type our username and not domain\username. I am sure this is easy, but driving me nuts..Thanks.
#Get UserInfo
$UserInfo = Get-Credential

#Spawn instance using new account
Start-Process –cred $UserInfo explorer.exe

Open in new window

0
Comment
Question by:tomtom98
  • 3
  • 3
7 Comments
 
LVL 6

Accepted Solution

by:
netjgrnaut earned 500 total points
ID: 36891702
You can't edit data in the Get-Credential cmdlet in flight.  That would be a security Don't.  In the same vein, you can't edit the .UserName property of the resulting object either.

You'd have to prompt your user twice - once for the UserName, then again for the password.  In the middle, you could construct the correct Domain\UserName and pass it to the Get-Credential cmdlet for the second request.

IMO, that sounds like a lot of coding work (and an awkward user experience) just to avoid typing Domain\ before your user name.

But... if you really want to... (this is written around command line processing; dialog box driven would be different)

Set-ItemProperty 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds' ConsolePrompting $true
$adDom = "YOURDOMAIN\"

#Get "friendly" UserName
$uName = Read-Host "Enter RunAs UserID"

#Prompt for password
$UserName = $adDom + $uName
$UserCred = Get-Credential $UserName

#Spawn instance using new account
Start-Process –cred $UserCred explorer.exe

Open in new window


Hope that helps.
0
 
LVL 66

Expert Comment

by:johnb6767
ID: 36892275
Your still trying to get a workaround for stopping/restarting the shell? I would be surprised if PS worked.....
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 36892316
"still trying..."  Did I miss a step?

I read this as an effort to launch a new file explorer window using alternate credentials.

Context would help.  :-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tomtom98
ID: 36892409
It works just as he says...have to type in password twice and it brings up an instance of explorer.
0
 
LVL 66

Expert Comment

by:johnb6767
ID: 36893157
Under ALTERNATE credentials? Verified by seeing this in the Task Manager?

@netjgrnaut

Sorry, that wasnt towards your work, you did a fine job.  We had a similar thread a weekish or so ago, and we came to the conclusion that since IE7, this was no longer possible..... Windows 7 Just doesn't allow it anymore.... So for you to accomplish it, bravo....
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 36893473
Well, I ran my tests launching cmd.exe here.  I'm on a network where I have both admin and non-admin credentials.  Running the above script under my non-admin account, and entering my admin credentials, got me a cmd.exe window where "whoami" resplied with my admin account.

So there's that.   ;-)
0
 
LVL 66

Expert Comment

by:johnb6767
ID: 36895493
Yea, most apps can still run side by side in different credentials, but Explorer.exe, to browse the file system/control panel etc has not been done as far as I had seen.... Only workaround I know of is to kill explorer from a RunAs'd CMD prompt, and restart it, which now loads under the Admin creds....
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

756 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