Search notes:

admin.ps1

admin.ps1: A PowerShell script to become administrator (if the respective token is granted) or to query if the session is running with administrator privileges:
In order to query if I am running as adminstrator, the -amI or its alias -? must be specified.
PS C\:> admin -?
False
PS C\:> admin
PS C\:> admin -?
True

Source code

#
#  V.2
#
param (
   [alias('?')] [switch] $amI
)

set-strictMode -version 3

if ($amI) {

   $curIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
   $principal   = new-object System.Security.Principal.WindowsPrincipal $curIdentity
   $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)

   return
}

# Start same powershell executable as administrator
# in the current directory.
$ps_exe = (get-process -pid $pid).path
start-process $ps_exe -verb runAs -argumentList '-noExit', '-command', 'cd', "'$pwd'"
Github repository scripts-and-utilities, path: /admin.ps1

History

V.2 Start admin Powershell session in the current (working) directory (i. e. $pwd)

See also

admin.bat

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758207402, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/tools/scripts/personal/admin_ps1(82): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78