Solved

Powershell Runas Explorer

Posted on 2011-09-30
7
1,365 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

776 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