TCL script: test permissions -
how can check if script running root-privileges?
i using following code, uses linux commands user id not work on m$ win. there platform independent approach handle problem ?
if { [exec id -u] eq 0 } { //nice, let destroy something! } else { //sorry. not root }
windows has no root privileges.
maybe system account or member of administrators group want.
there no known platform independent approach know of.
i suggest branching different os.
on windows: check if current process runs member of administrators group following thing:
package require twapi set token [twapi::open_process_token] set groups [twapi::get_token_groups_and_attrs $token] twapi::close_token $token if {[dict exists $groups s-1-5-32-544] && {enabled} in [dict $groups s-1-5-32-544]} { puts "i run administrator" } else { puts "no admin rights" }this requires twapi, great package windows.
administrators' sid hardcoded, because same on every system, while name of administrators group not (on system "administratoren").you should check if group enabled because starting windows vista there uac, list administrators' group sid (s-1-5-32-544) members of group, use_for_deny_only flag. (only when invoked "run administrator", group enabled.)
on unix/linux suggest using tclx.
here simple:
package require tclx if {[id userid]} { puts "not root" } else { puts "root" }this might work os/x, i'm not sure.
ps: don't evil.
Comments
Post a Comment