Do Shell Script .. with Administrator Privileges ... ?

hi everyone!
I have a script that have multiple lines like this:
do shell script " ... " with administrator privileges
do shell script " ... " with administrator privileges
Mac OS X 10.4 does it right(?) by asking ONCE for an admin login/password, and would run both lines above ... but 10.2 (and 10.3?) asks TWICE for the password using the same code. What am I doing wrong? I want all versions 10.2-4 to ask only once ... Any ideas?
Thank you!!
Cass

If you would prefer that your script would not ask for a password to get admin privileges, then this uses the keychain:
set aVariable to do shell script DefinedAsVariable password getPassw() with administrator privileges
-- The Handler --
The following handler assumes you have a password in your keychain called ASPW (could be anything you want) saved as a generic key. To do that, open your Keychain Access (in Utilities) application, choose file New, and in the sheet give it a name, enter your account name and type the password you want to use (your admin password in this case). OK. Now find the new password and double-click it. Under the attributes tab change Kind to generic key (it will be Applications). This makes for a fast search because there aren't many of them. Switch to the access control tab and select the "Allow all applications to access this item" button. Enter your admin password in the dialog that appears, and you are done. The first time you run the script, you'll have to click "Always Allow" in the dialog that appears - perhaps several times. After that, it won't ask.
to getPassw()
tell application "Keychain Scripting"
launch
tell current keychain to ¬
tell (some generic key whose name is "ASPW")
return password
end tell
end tell
end getPassw

Similar Messages

  • My 'run with administrative privileges' script no longer works - help

    Hey all. I have an applescript that shuts down the computer that I made a while back. I pulled it out today to use it and it no longer works. Here's part of the code I'm having trouble with:
    do shell script ¬
    "sudo shutdown -h now" password "myadminpassword" with administrator privileges
    On old machines this worked great, I would just put the admin password where myadminpassword is and it would work perfectly. Now though, I run it on my machine and I get the prompt to enter my admin username and password before it will shutdown.
    Now this is going on a remote install so I need it to work. Any ideas? The machine is running snow leopard, but it seems to still work on an old leopard macbook pro.

    Well, for one, do not use sudo in do shell script.
    The whole 'with administrator privileges' part takes care of elevating your privileges. sudo has no place in do shell script.
    Don't know if that's your issue, but it's the first thing I'd fix.
    If that doesn't help, are you running the script as your admin user?
    Nowhere in your script are you defining the username to run the command as, therefore it will attempt to run as the current user who may not be the same as your admin user, nor have the same password. You might need to include the username:
    do shell script "shutdown -h now" user name "admin" password "myadminpassword" with administrator privileges

  • With Administrator Privileges Error:  Authentication Failed

    i have an applescript app with the following line:
    do shell script "/System/Library/StartupItems/CiscoTUN/CiscoTUN restart" with administrator privileges
    When I run this script in Script Editor, I'm prompted for the admin username/password, but when I run the script saved as an application, i receive:
    "Authentication failed."
    I've tried this script with and without "sudo" preceding the rest of the shell script, but it behaves the same either way.
    Any clue why "with administrator privileges" is working in Script Editor but not when the application is run alone? Thanks!

    Hello
    My wild shot in the dark.
    If you have not saved your script as application bundle, try saving it as such.
    Applet as application bundle contains universal binary while applet as (non-bundle) application contains ppc binary, which is run via Rosetta in x86mac.
    This might make difference.
    H

  • Applescript "with administrator privileges" and without Password prompt

    i,
    I have to configure some phone settings in the central VOIP/VPN/Gateway Router via a ssh (with certificate) command.
    There is only a option to allow or disallow the ssh access in the router. Therefor I wrote a applescript to allow only the specific ssh command "set /Setup/Voice-Call-Manager/Call-Router/Call-Routing/". To avoid the configuration access for anyone and to hard code passwords I have to execute this script with root permissions (do shell script "/usr/bin/su - " & user & " -c " & "'" & cmd & "'" with administrator privileges"). In any other unix implementation I can use "chmod 4755; chown 0:0". Even I compiled the Applescript and stored it as Carbon App, I get a user/password prompt.
    How can I avoid this prompt or authorize the script/app in any way?
    Thanks Henri

    I agree, but to use the private key of the applescript caller opens any user the ability to change any WLAN key, VPN settings or delete the admin account, not a good idea....
    Therefor I would like to run the applescript with root, "su - <adminuser> ssh router set ....".
    This restricts the access to the router config to this applescript and I would like avoid the hard coding of the root password in the applescript.
    I tried also the add the command to /etc/sudoers, this work fine from the command line but how to call "sudo applescript" from the desktop without entering the admin password?
    Thanks
    Henri

  • Access Denied when trying to access shared folders on the server with administrative privileges

    I have problem accessing shared folder on the server machine from Windows 7 machine even if I try to access it with administrative privileges (server Administrator account). I will try now to explain better my situation.
    In my company, we have small network infrastructure with one main server machine (HP ProLiant server) with Windows Server 2012 R2 installed and couple of desktop machines. The network is administrated by me.
    On Windows Server we have installed and setup DHCP, DNS, Remote Access and Routing, File and Storage and Active Directory services. Desktop machines are having Windows 8.1 Pro, Windows 8.1 or Windows 7 Home Premium installed on them. In Active
    Directory I have created domain, User groups and Users for employees in my company and so far, I didn't added desktop machines to the domain.
    Also, I've created one folder on the server which should contain different projects data for network users and I have set access permissions and security for this folder and shared it on the network (I've added couple of users to one user group and I
    gave Full control to this group over this folder). When I try to access this folder from network, I've been asked for login credentials (normally), where I just type in one of users username and password who has been given access permissions to (who is member
    of group with full control over the folder). From Windows 8.1 Pro and Windows 8.1 machines I can access and work on this folder without any problems.
    The problem comes with Windows 7 machines. On Windows 7 machines (I have also tried this with Windows 7 Ultimate in VMWare) I can access server, I can see its shares, but as soon I try to access folder I've created for projects, I get Access Denied message
    with request for User login credentials. Whichever user account I use (even servers main Administrator account) I keep getting this message over and over and I'm unable to access it at all.
    I have also tried to access the server through VPN (from local or outside) but I'm getting the same error again. Also I've tried to add these Windows 7 machines to the domain and login with domain user but the result is the same. Turned off both firewalls
    (on server and desktop machines, which I know is unnecessary, but lets try it), still same case. I've tried couple more things with registry editor on desktop machines which I found on different forums and websites but still no luck. And now I don't know
    what else I can do.
    Does anyone knows what's the problem here, have I set something wrong, have not set something I should?

    Hi MeipoXu,
    thanks for your response. I will first answer on your question.
    Yes, the main issue is that we can see the folder when we access the server but we cannot access its contents from Windows 7 machines. I have tried on two machines, one with Windows 7 Home Premium version and the other one with Windows 7 Ultimate version
    and the situation is the same.
    As you recommended, I've checked Network Discovery and File and Printer Sharing and the situation is next: File and Printer Sharing is turned on all layers (Private, Public and Domain) while Network Discovery is off for all layers too. I don't know if this
    is normal thing but Network Discovery cannot be turned on in Windows Server (I'm able to select Turn on Network Discovery and apply the changes, but when I get back to this settings page, I again see that it's turned off, so I assume this can't be changed
    at all).
    I also tried with icacls in command prompt and everything seems to be ok there regarding permissions. Share permissions are set to Full control to Everyone and Security permissions are set to Full control only for Administrators and the user group I've created
    for employees in my company. The confirmation for this is that on Windows 8 machines you can access this folder without any problem and without getting any message connected with access permissions with any user account within this user group. This share is
    created through File and Storage Services service in Server Manager panel.
    And then something came up on my mind. I went in Server Manager to check shared folder settings in File and Storage Services and under Settings page I saw that "Encrypt data access" has been enabled (I enabled this option because I thought
    I will get more security with this option). I asked my self what would happen if I disable it, tried it and now everything works ok on Windows 7 machines too. Now I assume that Windows 7 doesn't have this feature implemented or there are some
    settings which needs to be set on Windows 7 machines to make this encryption thing work with Windows Server. So basically, I will let this feature off for now until I find out more about it and how to implement it to work with all operating systems.
    I want to thank you once more for your kind help!

  • I have windows vista user account with administrator privilege. I am unable to update mozilla firefox to the latest version. It is saying "do not have required privileges". I already uninstalled the previous version :(

    I am unable to update mozilla firefox. I have user account with administrator privilege.

    Try to run the installer as Administrator via the right-click context menu (Run as Administrator).

  • Error inserting image file in Excel 2013, it's working with administrator privileges

    When I tri to insert image file like .JPG in Excel 2013, I get an import error. It's working fine with administrator privileges.
    I check, graphic filter (registry values)  and made also an Office repare. But i have still the problem.
    My computer: Windows 8.1 64 bits, Office 2013 32 bits

    Try to check the grant permission for the Excel property itself.
    Try to insert image from other path, e.g. D:\ to check if we still receive the error.
    Try to run Excel with safe mode. ("Excel.exe /safe") and perform th insert action without any add-ins interrupt. Thanks.
    Tony Chen
    TechNet Community Support

  • Blackberry Media Sync Failed To Initialize - Run With Administrative Privileges

    I've downloaded the Blackberry Desktop Manager (4.7) and everything works fine except for the Blackberry Media Sync which fails to initialize and needs to be run with administrative privileges.  Anyone experience this and how did you correct the administrative privileges situation.  I am using a BB Bold.  TYIA

    BlackBerry Media Sync has just been updated to version 2.0.
    I suggest you download it and see if the issue is solved.
    The search box on top-right of this page is your true friend, and the public Knowledge Base too:

  • Open application with administrative privilege

    Can anyone point me to resources on how to execute a command in Java to open an application with administrative privileges - similar to the windows runas command - but will accept the login and password in the command?

    First figure out how to do it at the command line (it's beyond me). Then use Runtime.exec() to run the command. You'll have to use the Process's output stream to respond to the password prompt, and it's possible that might not work if Windows isn't prompting on stdin.

  • How do you pass shell scripts with cocoa?

    How do you pass shell scripts with cocoa?

    You asked for more detail -- I don't know if this is what you were referring to or not, but here's a little more detail on how to use the system() function if that's what you wanted to know.
    As etresoft mentioned, the system() function can be useful for the kind of thing you are talking about. You will need to write the following statement at the top of your code if you want to use it:
    #include <stdlib.h>
    To use the system() function, simply put the command as you would write it in the Terminal between double quotes between the parenthesis. For example, something as simple as:
    system("ls");
    I don't what the practical use of the above statement would be, but it will run, and that's the general format for the system() function. So just put between the quotes whatever command you want to send.
    Hope there was something helpful here.

  • Executing a shell script with DBMS_SCHEDULER

    Hi,
    when I execute a shell script with DBMS_SCHEDULER this doesn't works correctly
    BEGIN
    DBMS_SCHEDULER.create_job
    job_name => 'job_AR',
    job_type => 'EXECUTABLE',
    job_action => '/home/crm/crmdw/AR/start_execution.sh',
    enabled => TRUE,
    start_date => systimestamp,
    repeat_interval => 'FREQ=MINUTELY;INTERVAL=15',
    comments => 'Test Job AR'
    END;Inside the shell script there is a code who call a Hierarchy of process,
    if I executed it manually or with a cron, it works perfectly
    but when I execute it with the job that I've described before it's executes
    all process at same time and it doesn't work.
    What can I do to fix the issue,
    any Ideas?
    Thanks in advanced...

    #!/usr/bin/ksh
    #test_dbms_scheduler.ksh
    echo $1
    echo "I am in Unix"
    exit 0
    chmod 755 test_dbms_scheduler.ksh
    Create or replace procedure test_dbms_scheduler
    as
    v_text varchar2(255) := 'Parameter passed from Oracle to Unix';
    Begin
    dbms_output.put_line("I am in Procedure");
    dbms_scheduler.create_job
    (job_name=>'test_dbms_scheduler',
    job_action=>'/usr/bin/test_dbms_scheduler.ksh',
    number_of_arguments=>1,
    job_type=>'executable',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=SECONDLY; INTERVAL=1',
    enabled=>false,
    auto_drop => TRUE,
    comments=> 'Run shell-script test_dbms_scheduler.ksh');
    dbms_scheduler.set_job_argument_value(job_name =>'test_dbms_scheduler', argument_position => 1, argument_value => v_text);
    dbms_scheduler.enable('test_dbms_scheduler');
    dbms_output.put_line("I am back in Procedure");
    Exception
    when others then
    dbms_output.put_line(sqlcode||sqlerrm);
    end;
    set serveroutput on
    exec test_dbms_scheduler;

  • How do we open folders with administrator privileges?

    I am trying to open the folder Documents and Settings on my local machine.  I am the administrator, the computer is not on a network, and it is a standalone machine.

    Hello Milo,
    Thanks for the reply, I was just able to try your response today for the first time.
    I will type in exactly what I put in the command line
    icacls "D:\saved shit\" /grant administrators:F
    D:\saved shit" /grant administrators:F: The filename, directory name, or volume label syntax is incorrect.
    Successfully processed 0 files; Failed processing 1 files
    After this I enabled the "hidden admin" account and logged on that account to find I was able to edit the folder's permissions and I can now go into that folder.  The problem remains though that every folder and file within D:\saved shit is now inaccessible
    to either the administrator account or my original account with administrator privileges.
    When I attempt the icacls solution you posted for the subfolder D:\saved shit\My Documents it gives me the same message I wrote earlier.
    Sorry for the wall of text and I really do appreciate your help.  My end goal is just to have the default permissions set for all the files and subfolders so I can access them again.
    Thank you for your time!

  • How to run a java class from a shell script with passing arguments

    hi,
    I have a jar with all the required classes. I was using ant to run the classes i needed.
    But now i want to use a shell script to run the class, also the class accepts some arguments so when script is run it should accept arguments.
    So can any one tell me how to set class paths, jar location and call the required class from shell script or batch file with passing arguments to it.
    Thanks in advance.

    Let's say that the order of arguments is as below
    1. Jar file name
    2. Classpath
    Your shell script would look like this
    java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
    The same goes for a batch file
    java -cp %CLASSPATH%;%2 -jar %1

  • Sqlplus in Shell Script with startup pfile

    I have the following entry in my Korn shell script:
    ${ORACLE_HOME}/bin/sqlplus -s /nolog << EOSQL >> ${PR_LOG}
    connect / as sysdba
    whenever sqlerror exit sql.sqlcode;
    startup pfile "/u01/app/oracle/admin/${ORA_SID}/pfile/spfile${ORA_SID}.ora";
    EOSQL
    When I execute the script I get the following errors:
    LRM-00123: invalid character 0 found in the input file
    ORA-01078: failure in processing system parameters
    I've isolated the problem to the 4th line. When I change it to simply "startup", everything works. I did try changing the quotes to ` and ', but those didn't work. I even explicitly listed the ORA_SID, and I'm still getting the same error messages.
    Any ideas how I can resolve my problem with the 4th line? All help is appreciated.

    and yes I want to start the database with the spfile.
    If I just use "startup", everything is fine; and I can start the database with the spfile, because I have a symbolic link under $ORACLE_HOME/dbs to point to my actual spfile location - /u01/app/oracle/admin/salsa/pfile/So... what's the problem ? Just use "startup", if I'm not wrong you'd use the same spfile.
    To use that syntax you should create a file with a line like this
    spfile=<path of spfile>
    and start as
    startup pfile='<path of that file>'

  • How can IT departments set up basic users to run Captivate with Administrator privileges?

    As we all know, on WinVista and Win7 or later systems Adobe Captivate must be launched with Run As Administrator privileges in order to function correctly and not crash.  But the problem here is that in many corporate environments general users are not allowed to have Administrator access to their own work PCs.  This presents something of a dilemma for IT departments with Adobe Captivate users.
    Some time ago on this forum one of the Adobe technical staff chimed in on a thread about the Run As Administrator command and explained the technical steps required to set up a Group Policy in WinVista/Win7 that would allow a basic user to always launch Captivate with the necessary admin privileges even though they did NOT have Administrator access to any other app on their PC. 
    I have searched in vain to find that particular thread and post, so I've started this thread in the hope that someone at Adobe can again chime in to detail the necessary steps again.
    So is there anyone there that can help out?

    DOH! my bad.....I/we run WinXP at present and no UAC.
    However, all may not be lost, try some of these options as posted on teh MS Technet forums....An admin person may need t do this first to enable this for that user...
    Apologies for misundeerstand situation. ;-( hate it when that happens!
    Try these two options:
    Using Compatibility Mode
    NOTE: This will allow you to always have the program run as an administrator when you open it.
    1. Right click on the program shortcut or program .exe file, then click on Properties, and on the Compatibility tab. (See screenshots below)
    NOTE: If you are doing this while logged on as a standard user instead of an administrator, then you will need to also click on the Change settings for all users button and type in the administrator's password.
    http://www.sevenforums.com/attachments/tutorials/12832d1243933304-run-administrator-compat ibility_mode1.jpghttp://www.sevenforums.com/attachments/tutorials/12832d1243933304-run-administrator-compat ibility_mode1.jpghttp://www.sevenforums.com/attachments/tutorials/12832d1243933304-run-administrator-compat ibility_mode1.jpgUAC, then click on Yes to apply permission to allow the program to run with full permission as an administrator.
    2. To Always Run this Program as an Administrator
    A) Check the Run this program as an administrator box, and click on OK. (See screenshots above)
    3. To Not Always Run this Program as an Administrator
    A) Uncheck the Run this program as an administrator box, and click on OK. (See screenshots below step 1)
    4. Open the program.
    5. If prompted by
    NOTE: If you are doing this is while logged in as standard user instead of an administrator, then you will need to provide the administrator's password before the program will run as administrator.
    Using Advanced Properties
    NOTE: This will allow you to always have the program run as an administrator when you open it.
    1. Right click on the shortcut of the program, then click on Properties.
    2. Click on the Shortcut tab for a program shortcut, then cllick on the Advanced button. (See screenshot below)
    http://www.sevenforums.com/attachments/tutorials/12834d1243933304-run-administrator-advanc ed_properties1a.jpghttp://www.sevenforums.com/attachments/tutorials/12834d1243933304-run-administrator-advanc ed_properties1a.jpghttp://www.sevenforums.com/attachments/tutorials/12834d1243933304-run-administrator-advanc ed_properties1a.jpghttp://www.sevenforums.com/attachments/tutorials/12836d1243933304-run-administrator-advanc ed_properties2.jpghttp://www.sevenforums.com/attachments/tutorials/12836d1243933304-run-administrator-advanc ed_properties2.jpghttp://www.sevenforums.com/attachments/tutorials/12836d1243933304-run-administrator-advanc ed_properties2.jpgUAC, then click on Yes to apply permission to allow the program to run with full permission as an Administrator.
    3. To Always Run this Program as an Administrator
    A) Check the Run as administrator box, and click on OK. (See screenshot below)
    4. To Not Always Run this Program as an Administrator
    A) Uncheck the Run as administrator box, and click on OK. (See screenshot above)
    5. Click on OK. (See screenshot below step 2)
    6. Open the program.
    7. If prompted by
    NOTE: If you are doing this is while logged in as standard user instead of an administrator, then you will need to provide the administrator's password before the program will run as administrator

Maybe you are looking for