Error message: NOT super-user

  • Hi, I was trying to do:

    shutdown -h now

    from an NSTask in an awakeFromNib method, but it didn't work. So I tried to run it in the Terminal and got this message: NOT super-user.
    I am the system administrator of my machine, why doesn't this work? Or, what should I do to make it work?

    Thanks in advanced
  • On Sep 8, 2007, at 12:11 PM, Ricardo Diaz wrote:

    > from an NSTask in an awakeFromNib method, but it didn't work. So I
    > tried to run it in the Terminal and got this message: NOT super-user.
    > I am the system administrator of my machine, why doesn't this work?
    > Or, what should I do to make it work?

    If it says that you need to be the super-user, it means you need to
    run it with root privileges. But if you really need to shut down the
    computer for some reason, then you ought to use NSAppleScript and
    System Events instead. That won't require root privileges.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • Yeah I don't care, how can I run it with root privileges?
  • >> from an NSTask in an awakeFromNib method, but it didn't work. So I
    >> tried to run it in the Terminal and got this message: NOT super-user.
    >> I am the system administrator of my machine, why doesn't this work?
    >> Or, what should I do to make it work?
    >
    > If it says that you need to be the super-user, it means you need to
    > run it with root privileges. But if you really need to shut down the
    > computer for some reason, then you ought to use NSAppleScript and
    > System Events instead. That won't require root privileges.
    >
    > Nick Zitzmann
    >

    Yeah I want to do it this way. I tried using:

    su

    but I can't type anything in "Password:", I also tried typing it blindly and hitting enter but it didn't work.
  • On Sep 8, 2007, at 4:47 PM, Ricardo Diaz wrote:
    >
    > Yeah I want to do it this way. I tried using:
    > su
    > but I can't type anything in "Password:", I also tried typing it
    > blindly and hitting enter but it didn't work.
    >

      Search this list's archives - this is a VFAQ (VERY frequently asked
    question).

    --
    I.S.
  • This is an extremely bad idea; if the user has any open applications
    they will just be killed without warning. The user won't be asked "do
    you want to save?," the app won't save out any changes to its
    preference files, and if the app is in the middle of writing data,
    the file will be corrupted.
    Even if you don't care, trust me, your users will care, when this
    poorly written app causes them to lose data.
    Anyway, the correct technique doesn't require a password either, so
    it's easier for you and for your users.
    Use NSAppleScript and try a script like this.

    tell application "System Events"
        shut down
    end tell

    On Sep 8, 2007, at 1:28 PM, Ricardo Diaz wrote:

    >
    > Yeah I don't care, how can I run it with root privileges?
  • On 8 Sep 2007, at 21:28, Ricardo Diaz wrote:

    > Yeah I don't care, how can I run it with root privileges?

    You could use a helper tool.  Look at the docs for the Authorization
    framework.  If you *do* do that, then make sure that your tool checks
    for a right; otherwise it might allow an unprivileged user to shut
    down the system abruptly, which would be a *huge* security hole.

    But why not save yourself the trouble and send the relevant Apple
    Events instead?  This is particularly important if there might be GUI
    programs running, since they rarely contain code to handle the abrupt
    Unix-y type of shut down that you'll get from using the command you
    mentioned.

    It's quite easy; you just send a kAEShowShutdownDialog event (with
    event class kCoreEventClass) to the process with ProcessSerialNumber
    { 0, kSystemProcess }.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
  • Ok, how can I make a string which has double quotes in it?

    Here's what I have:

    NSString *script = @"tell application "System Events" to shut down";
    shutdown = [[NSAppleScript alloc] initWithSource:script];
    id status = [shutdown executeAndReturnError:nil];

    but this doesn't take System Events as part of the string, how should I do it?
  • Nevermind, I used:

    char quote = '"';
    NSString *script = [NSString stringWithFormat:@"tell application %cSystem Events%c to shut down", quote, quote];
    shutdown = [[NSAppleScript alloc] initWithSource:script];
    id status = [shutdown executeAndReturnError:nil];
  • How about: @"string with \"quotes\" in it"

    --
    I.S.

    On Sep 8, 2007, at 6:15 PM, Ricardo Diaz wrote:

    >
    > Nevermind, I used:
    >
    > char quote = '"';
    > NSString *script = [NSString stringWithFormat:@"tell application
    > %cSystem Events%c to shut down", quote, quote];
    > shutdown = [[NSAppleScript alloc] initWithSource:script];
    > id status = [shutdown executeAndReturnError:nil];
  • On 09.09.2007, at 00:08, Ricardo Diaz wrote:
    > Ok, how can I make a string which has double quotes in it?
    >
    > Here's what I have:
    >
    > NSString *script = @"tell application "System Events" to shut down";
    > shutdown = [[NSAppleScript alloc] initWithSource:script];
    > id status = [shutdown executeAndReturnError:nil];
    >
    > but this doesn't take System Events as part of the string, how
    > should I do it?

      At the risk of sounding like I'm talking down at you: You'll save
    yourself a lot of pain if you get a good book about programming in C
    and learn the language completely. If you don't know how to escape
    quotes, chances are you're missing a lot of other important
    information that could make things a lot easier for you.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today