Anlage des Repos
This commit is contained in:
11
examples/PowerShell/AccessTests/AccessRights-test.ps1
Normal file
11
examples/PowerShell/AccessTests/AccessRights-test.ps1
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
$file = [System.io.File]::Open("E:\test.txt", 'Open', 'Read', 'ReadWrite')
|
||||
#$reader = New-Object System.IO.StreamReader($file)
|
||||
#$text = $reader.ReadToEnd()
|
||||
#$reader.Close()
|
||||
$file.Close()
|
||||
|
||||
Write-Host $file.CanRead
|
||||
Write-Host $file.CanWrite
|
||||
Write-Host $file.CanSeek
|
||||
Write-Host $file.CanTimeout
|
||||
61
examples/PowerShell/AccessTests/AccessRights.ps1
Normal file
61
examples/PowerShell/AccessTests/AccessRights.ps1
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
Set-Variable -name file -Value E:\test.pdf
|
||||
|
||||
function checkFileStatus1($filePath)
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILECHECK] Checking if" $filePath "is locked"
|
||||
$fileInfo = New-Object System.IO.FileInfo $filePath
|
||||
|
||||
try
|
||||
{
|
||||
$fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read )
|
||||
write-host (get-Date) "[ACTION][FILEAVAILABLE]" $filePath
|
||||
#$fileInfo.close()
|
||||
#$fileInfo.dispose()
|
||||
|
||||
|
||||
|
||||
return $true
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILELOCKED] $filePath is locked"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function checkFileStatus2($filePath)
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILECHECK] Checking if" $filePath "is locked"
|
||||
$fileInfo = New-Object System.IO.FileInfo $filePath
|
||||
|
||||
try
|
||||
{
|
||||
$fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read )
|
||||
#$fileStream = $fileInfo.Open()
|
||||
write-host (get-Date) "[ACTION][FILEAVAILABLE]" $filePath
|
||||
$fileInfo.close()
|
||||
$fileInfo.dispose()
|
||||
#$fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read )
|
||||
|
||||
|
||||
return $true
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILELOCKED] $filePath is locked"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
checkFileStatus2 -filePath $file
|
||||
# checkFileStatus1 -filePath $file
|
||||
@@ -0,0 +1,5 @@
|
||||
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”) -or -NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”) -or -not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Domain Admins"))
|
||||
{
|
||||
Write-Warning “You do not have sufficient permissions to run this script!`nPlease re-run this script as an Administrator!”
|
||||
Break
|
||||
}
|
||||
Reference in New Issue
Block a user