![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How can I run scipts with Admin privilege? I can open PS shells via "Run as administrator" but that option is greyed out for PS scripts and their shortcuts. I have set "unrestricted" access for execution policy!?? DavieH === Windows 7, PS v2. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How can I run scipts with Admin privilege? Hello DavieH, Quote: > I can open PS shells via "Run as administrator" but that option is > greyed out for PS scripts and their shortcuts. I have set > "unrestricted" access for execution policy!?? > > DavieH > === > Windows 7, PS v2. by double clicking on them - thus, you can't "run a script with admin privleges" withut first opening the shell or ISE. |
My System Specs![]() |
| | #3 (permalink) |
| | RE: How can I run scipts with Admin privilege? By design PowerShell does not run scripts by double clicking them. This is extremely unlikely to change in future versions of PowerShell. There is no way to elevate privileges from within a PowerShell script. The only way to run scripts with admins privileges is to start PowerShell or the ISE using run as admin OR you could schedule a job to run the powershell script and use an account with admins privileges -- Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "DavieH" wrote: Quote: > I can open PS shells via "Run as administrator" but that option is greyed out > for PS scripts and their shortcuts. I have set "unrestricted" access for > execution policy!?? > > DavieH > === > Windows 7, PS v2. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How can I run scipts with Admin privilege? I simply open two powershell windows when I first log on - one standard user, one elevated. The elevated one has a maroon background, and has Administrator in the title bar. -- Charlie. http://msmvps.com/blogs/xperts64 http://mvp.support.microsoft.com/profile/charlie.russel "RichS [MVP]" <RichSMVP@xxxxxx> wrote in message news:1BE21458-D8E8-4A09-AE7A-8D59A22DFC20@xxxxxx Quote: > By design PowerShell does not run scripts by double clicking them. This > is > extremely unlikely to change in future versions of PowerShell. There is > no > way to elevate privileges from within a PowerShell script. > > The only way to run scripts with admins privileges is to start PowerShell > or > the ISE using run as admin > OR you could schedule a job to run the powershell script and use an > account > with admins privileges > -- > Richard Siddaway > All scripts are supplied "as is" and with no warranty > PowerShell MVP > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "DavieH" wrote: > Quote: >> I can open PS shells via "Run as administrator" but that option is greyed >> out >> for PS scripts and their shortcuts. I have set "unrestricted" access for >> execution policy!?? >> >> DavieH >> === >> Windows 7, PS v2. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How can I run scipts with Admin privilege? Hello Charlie Russel - MVP, Quote: > I simply open two powershell windows when I first log on - one > standard user, one elevated. The elevated one has a maroon background, > and has Administrator in the title bar. > Administrator PowerShell for the title, black background, a Yellow "Admiminstratoe <path>" prompt, and magenta (inside company joke) for the foreground Can't mistake it for my non admin shell! |
My System Specs![]() |
| | #6 (permalink) |
| | Re: How can I run scipts with Admin privilege? Exactly - no mistaking this one either! I use a multiline prompt, as well, left over from my days as an Oracle DBA and UNIX sysadmin. Has what account I'm running under, what my default database is, and what my current location (machine and path) is. Converting that from Korn shell was one of my first fun projects in PowerShell. But for elevated windows, I change the background/foreground as well. Just so there's no doubt! -- Charlie. http://msmvps.com/blogs/xperts64 http://mvp.support.microsoft.com/profile/charlie.russel "Karl Mitschke" <kmitschke@xxxxxx> wrote in message news:d66cd4c26245d8cb558b021e4ec9@xxxxxx Quote: > Hello Charlie Russel - MVP, > Quote: >> I simply open two powershell windows when I first log on - one >> standard user, one elevated. The elevated one has a maroon background, >> and has Administrator in the title bar. >> > > Administrator PowerShell for the title, black background, a Yellow > "Admiminstratoe <path>" prompt, and magenta (inside company joke) for the > foreground > > Can't mistake it for my non admin shell! > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: How can I run scipts with Admin privilege? "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message news:u4h$0y6hJHA.5000@xxxxxx Quote: > I simply open two powershell windows when I first log on - one standard > user, one elevated. The elevated one has a maroon background, and has > Administrator in the title bar. I can only give it the normal range of ConsoleColor enum values. I can't give it a more pleasing color which can you mix up if you go into the command shell preferences. As for elevating once you're at a prompt though, check this out. I just added this to my Host.psm1 module. It depends on a utility by Wintellect called Elevate.exe but it's pretty convenient if you're sitting in a directory and think "dammit I forgot to elevate this process..." Get the module here... http://cid-89e05724af67a39e.skydrive...l/Modules/Host Usage: cd c:\some\deep\directory\structure\I\really\dont\wanna\type\again Start-PowerShell .\Update-Gac.ps1 -Elevated Start-PowerShell -Command { ...do horrible admin stuff... } -Elevated Here's the function(s): function Start-ElevatedProcess { [CmdletBinding()] param ( [Parameter(Position=1)][String]$Path, [Parameter(Position=2)][String[]]$Arguments, [Parameter()][Switch]$Wait ) $ElevateExe = Join-Path $PSScriptRoot 'elevate.exe' $ElevateMissingMessage = @" The Wintellect elevate.exe utility was not found in the module directory. This utility is required to launch elevated processes. Download this utility and place it in the following folder. $PSScriptRoot Do you want to download it now from http://www.wintellect.com? "@ if ( Test-Path $ElevateExe ) { $ElevateArgs = @() if ($Wait) { $ElevateArgs += '-wait' } $ElevateArgs += $Path $ElevateArgs += $Arguments Start-Process $ElevateExe $ElevateArgs -NoNewWindow } else { # Prompt the user to get it from Wintellect Show-Menu 'Download Elevate.exe' -m $ElevateMissingMessage { Choice 'No' { } Choice 'Yes' { [System.Diagnostics.Process]::Start('http://www.wintellect.com/CS/files/folders/sample_files/entry3385.aspx') } } } } function Start-PowerShell { [CmdletBinding(DefaultParameterSetName='File')] param ( [Parameter(ParameterSetName='File', Position=1)] [String]$File, [Parameter(ParameterSetName='ScriptBlock')] [ScriptBlock]$Command, [Parameter()] [String]$PSConsoleFile, [Parameter()] [Switch]$STA, [Parameter()] [Switch]$NoProfile, [Parameter()] [Switch]$Elevated ) $PowerShellArgs = @('-NoExit') if ( $PSConsoleFile ) { # A PSConsole file to start with: Use the ProviderPath $ResolvedConsoleFile = (Resolve-Path $PSConsoleFile).ProviderPath $PowerShellArgs += ('-PSConsoleFile',$ResolvedConsoleFile) } if ( $STA ) { $PowerShellArgs += '-Sta' } if ( $NoProfile ) { $PowerShellArgs += '-NoProfile' } if ( $File ) { # A script to run: Use the ProviderPath $ResolvedFile = (Resolve-Path $File).ProviderPath } # Encodes the command as Base64 and prepends a # Set-Location command which puts us in the same dir $CommandString = "Set-Location '$PWD'" if ( $Command ) { $CommandString += "; $Command" } if ( $File ) { $CommandString += "; &'$ResolvedFile'" } $CommandBytes = [System.Text.Encoding]::Unicode.GetBytes($CommandString) $CommandBase64 = [Convert]::ToBase64String($CommandBytes) $PowerShellArgs += ('-EncodedCommand',$CommandBase64) # Start-Process bitches if you are in HKLM:\ or something # so we'll temporarily cd into $PSHOME then pop out Push-Location $PSHOME try { if ( $Elevated ) { Start-ElevatedProcess 'powershell.exe' $PowerShellArgs } else { Start-Process 'powershell.exe' $PowerShellArgs } } finally { Pop-Location } } |
My System Specs![]() |
| | #8 (permalink) |
| | Re: How can I run scipts with Admin privilege? I guess you do that stuff in the profile script and I can open a Cmd-replica shell by running PS from within another script with a -Command block to set up my variables (the black background is undoubtably because of some options that I haven't set). By default I use two Admin shells because I learned from Vista the problems that arise from "Virtualisation" (the data that gets into \VirtualStore) because of insufficient privilege (and NOT because of program data in Program Files like Adobe with v8 of their Reader!). SUGGESTION: Allow Admin privilege on script files and their shortcuts via the context menu only because an (inexperienced) user can do more damage in a shell that is persistently open with Admin privilege! DavieH ==== "Charlie Russel - MVP" wrote: Quote: > Exactly - no mistaking this one either! > > I use a multiline prompt, as well, left over from my days as an Oracle DBA > and UNIX sysadmin. Has what account I'm running under, what my default > database is, and what my current location (machine and path) is. Converting > that from Korn shell was one of my first fun projects in PowerShell. But for > elevated windows, I change the background/foreground as well. Just so > there's no doubt! > > -- > Charlie. > http://msmvps.com/blogs/xperts64 > http://mvp.support.microsoft.com/profile/charlie.russel > > "Karl Mitschke" <kmitschke@xxxxxx> wrote in message > news:d66cd4c26245d8cb558b021e4ec9@xxxxxx Quote: > > Hello Charlie Russel - MVP, > > Quote: > >> I simply open two powershell windows when I first log on - one > >> standard user, one elevated. The elevated one has a maroon background, > >> and has Administrator in the title bar. > >> > > > > Administrator PowerShell for the title, black background, a Yellow > > "Admiminstratoe <path>" prompt, and magenta (inside company joke) for the > > foreground > > > > Can't mistake it for my non admin shell! > > > > > |
My System Specs![]() |
| | #9 (permalink) |
| | Re: How can I run scipts with Admin privilege? Wow... there's a few things I don't understand, but I'll try it before asking! DavieH ==== "Josh Einstein" wrote: Quote: > As for elevating once you're at a prompt though, check this out. I just > added this to my Host.psm1 module. It depends on a utility by Wintellect > called Elevate.exe but it's pretty convenient if you're sitting in a > directory and think "dammit I forgot to elevate this process..." |
My System Specs![]() |
| | #10 (permalink) |
| | Re: How can I run scipts with Admin privilege? OK - got there (wasn't sure about @ operator). And Elevate.exe enables me to execute commands with admin privilege from a shortcut to a file containing:- Elevate powershell.exe -outputformat XML -nologo -WindowStyle Normal -command { ...... } Or provide an Admin shell (by adding -noexit). thanks, DavieH ==== "DavieH" wrote: Quote: > Wow... there's a few things I don't understand, but I'll try it before asking! > > DavieH > ==== > > "Josh Einstein" wrote: Quote: > > As for elevating once you're at a prompt though, check this out. I just > > added this to my Host.psm1 module. It depends on a utility by Wintellect > > called Elevate.exe but it's pretty convenient if you're sitting in a > > directory and think "dammit I forgot to elevate this process..." |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
Lost Admin Privilege! Please Help Me! | General Discussion | |||
| admin privilege | Vista account administration | |||
| Detect admin privilege due to elevation? | Vista security | |||
| Is it possible for a service to start a user app running with admin privilege? | Vista General | |||
| Is it possible for a service to start a user app running with admin privilege? | Vista security | |||