Solved

Powershell Runas Explorer

Posted on 2011-09-30
7
1,335 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
Comment Utility
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
Comment Utility
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
Comment Utility
"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
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

 

Author Comment

by:tomtom98
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
OfficeMate Freezes on login or does not load after login credentials are input.
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

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

10 Experts available now in Live!

Get 1:1 Help Now