Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell Runas Explorer

Posted on 2011-09-30
7
Medium Priority
?
1,512 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 2000 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
Screencast - Getting to Know the Pipeline

876 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