Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Structure of runas command

  • 01-10-2010 11:17am
    #1
    Closed Accounts Posts: 1,829 ✭✭✭


    Hi I was trying to run a command similar to this on Vista

    runas /user:<myuserid>@&lt;mydomain> "CMD /C copy /Y d:\\newhosts c:\\windows\\system32\\drivers\\etc\\hosts"

    The idea is to replace the hosts file with an updated file.
    When I run this, I get prompted for the password. I enter it and the cmd prompt flashes and nothing happens.
    Access to most of the C drive requires admin privs which I can access using UAC.

    The command will work if I try and copy to an open location, for example the D drive.
    Any thoughts on what might be going on?
    Thanks
    JC


Comments

  • Registered Users, Registered Users 2 Posts: 3,557 ✭✭✭SickBoy


    JackieChan wrote: »
    Hi I was trying to run a command similar to this on Vista

    runas /user:<myuserid>@&lt;mydomain> "CMD /C copy /Y d:\\newhosts c:\\windows\\system32\\drivers\\etc\\hosts"

    The idea is to replace the hosts file with an updated file.
    When I run this, I get prompted for the password. I enter it and the cmd prompt flashes and nothing happens.
    Access to most of the C drive requires admin privs which I can access using UAC.

    The command will work if I try and copy to an open location, for example the D drive.
    Any thoughts on what might be going on?
    Thanks
    JC

    Are the double backslashes necessary?


  • Moderators, Arts Moderators, Regional Abroad Moderators Posts: 11,138 Mod ✭✭✭✭Fysh


    JackieChan wrote: »
    Hi I was trying to run a command similar to this on Vista

    runas /user:<myuserid>@&lt;mydomain> "CMD /C copy /Y d:\\newhosts c:\\windows\\system32\\drivers\\etc\\hosts"

    The idea is to replace the hosts file with an updated file.
    When I run this, I get prompted for the password. I enter it and the cmd prompt flashes and nothing happens.
    Access to most of the C drive requires admin privs which I can access using UAC.

    The command will work if I try and copy to an open location, for example the D drive.
    Any thoughts on what might be going on?
    Thanks
    JC

    There's a difference between a standard command prompt and an admin-level one.

    As an experiment, I would open an administrative-privilege command-prompt and test your command there. If it works, your issue is with invoking an administrative command prompt when using runas. Might be better to look into creating a powershell script to do this for you - save it to the desktop, run the script as administrator, up pops a command prompt asking you for the password for the account specified, and away you go.


  • Closed Accounts Posts: 1,829 ✭✭✭JackieChan


    Fysh wrote: »
    There's a difference between a standard command prompt and an admin-level one.

    As an experiment, I would open an administrative-privilege command-prompt and test your command there. If it works, your issue is with invoking an administrative command prompt when using runas. Might be better to look into creating a powershell script to do this for you - save it to the desktop, run the script as administrator, up pops a command prompt asking you for the password for the account specified, and away you go.

    thanks Fysh, yes if I start an admin command prompt and then run the command it works fine. Im looking at this been a 'dirty' workaround to get an entry in to the hosts file for some users.So I want a handful of users in remote sites to be able to run it under my account(with a quick password reset afterwards by me)


  • Registered Users, Registered Users 2 Posts: 6,003 ✭✭✭JDxtra


    Why not just copy the updated hosts file from your machine (logged on as an admin) directly to theirs? You just need the remote machines to be online.

    Saves the hassle of embedding your password in a batch file and changing it later.


  • Registered Users, Registered Users 2 Posts: 6,003 ✭✭✭JDxtra


    If it's only a handful, this would work.

    copy /Y d:\newhosts \\machine1\c$\windows\system32\drivers\etc\hosts
    copy /Y d:\newhosts \\machine2\c$\windows\system32\drivers\etc\hosts
    copy /Y d:\newhosts \\machine3\c$\windows\system32\drivers\etc\hosts
    copy /Y d:\newhosts \\machine4\c$\windows\system32\drivers\etc\hosts


    Any more, and I'd write a script which logs errors, checks machines are online etc.


  • Advertisement
  • Moderators, Arts Moderators, Regional Abroad Moderators Posts: 11,138 Mod ✭✭✭✭Fysh


    There's a useful-looking script chunk in the comments of this page that might help you do it as a batch file, though it depends on the target boxes having Powershell installed.


  • Closed Accounts Posts: 1,829 ✭✭✭JackieChan


    Thanks guys,

    JD,I tried following the syntax of your command to copy something to my machine initially, but just got "the network path was not found"...and yes the machine is online! ;)
    It was only going to be for 10-12 users so would have been a nice workaround.

    I've bitten the bullet and actually requested a new DNS entry...just takes extra time to get this done(as in days!)


  • Registered Users, Registered Users 2 Posts: 6,003 ✭✭✭JDxtra


    You may not have been an admin on the remote machines or maybe the Windows folder is different. But yes - a DNS entry saves all this hassle! :)


Advertisement