1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!perl
use strict;
use warnings;
use FileHandle;
use File::Spec;
my $file = File::Spec->catfile('C:', 'Program Files (x86)', 'perl-test.txt');
my $fh = FileHandle->new($file, '>');
if( defined $fh ) {
$fh->print("bar\n");
$fh->close();
}else{
die("Error: $!");
}
1
2
3
4
5
6
7
my $install_dir = File::Spec->catdir('C:', 'Program Files (x86)');
my $glaskugel = Glaskugel->new();
if( $glaskugel->is_writable( $install_dir ) ) {
print "Toll! Du kannst schreiben!\n";
}else{
print "Du kommst hier nicht rein.\n";
}
1
2
3
4
5
6
7
8
9
Aufruf in der Konsole als Benutzer:
C:\Perl\Scripten\test\installer>perl permission.pl
16749
C:\Perl\Scripten\test\installer>
Aufruf in der Konsole als Administraor:
C:\Perl\Scripten\test\installer>perl permission.pl
16749
C:\Perl\Scripten\test\installer>
Win32::IsAdminUser()
QuoteWin32Win32::IsAdminUser()
Returns non zero if the account in whose security context the current process/thread is running belongs to the local group of Administrators in the built-in system domain; returns 0 if not. On Windows Vista it will only return non-zero if the process is actually running with elevated privileges. Returns undef and prints a warning if an error occurred. This function always returns 1 on Win9X.