+ Post New Thread
Results 1 to 12 of 12
Scripts Thread, Scripting an Elevated Command Prompt? in Coding and Web Development; I have software to install on lots of PC's. It's educational, and thus rubbish. After install, I need to copy ...
  1. #1

    Join Date
    Jan 2012
    Posts
    610
    Thank Post
    172
    Thanked 80 Times in 57 Posts
    Rep Power
    67

    Scripting an Elevated Command Prompt?

    I have software to install on lots of PC's. It's educational, and thus rubbish. After install, I need to copy a file from our network to the local machine in order to make it work properly. If the command prompt isn't an Administrative one, it returns Access Denied, so I have to install the software and then RC-Run as Administrator on lots of PC's. I don't want to use RUNAS because this would require me putting my password in on each of the PC's and that kind of defeats the object.

    I've tried creating a shortcut which runs as an administrator, which works, and launches an Administrative cmd with a mere pressing of a 'Yes' buttom (requiring a left-enter which can be done much quicker than typing a password 30+ times), but I can't seem to find a way to make that prompt automatically run a batch file, so that I can just remotely push the file out to x-amount of PC's and have it install via msciexec.

    I've tried a batch file of M:\acmd.lnk "\\Batch Location" but that doesn't work, it just loads up a regular cmd, then an Administrative cmd, but the Administrative one doesn't run the batch file (at "\\Batch Location"). So I tried modifying the location of M:\acmd.lnk to C:\Windows\System32\cmd.exe "\\Batch Location", but that has only the same result, only with just one CMD window this time.

    Any ideas? The batch file in question is simply an MSIEXEC and an XCOPY, if it matters.

  2. IDG Tech News
  3. #2

    AngryTechnician's Avatar
    Join Date
    Oct 2008
    Posts
    3,231
    Thank Post
    597
    Thanked 1,021 Times in 636 Posts
    Rep Power
    346
    At the moment, I'm guessing your shortcut has a target of %windir%\system32\cmd.exe, yes?

    Try changing the target to %windir%\system32\cmd.exe /c "\\Batch Location"

  4. #3

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,067
    Thank Post
    1,057
    Thanked 664 Times in 573 Posts
    Rep Power
    212
    Quote Originally Posted by Garacesh View Post
    After install, I need to copy a file from our network to the local machine in order to make it work properly. If the command prompt isn't an Administrative one, it returns Access Denied, so I have to install the software and then RC-Run as Administrator on lots of PC's.
    I use AutoIT, which has a selection of runas / requireadmin commands to run various command lines as a particular user. It will compile its scripts up into a self-executing EXE file, so you don't have to distribute your password in the clear to all machines.

  5. #4

    Join Date
    Jan 2007
    Location
    Nottinghamshire
    Posts
    467
    Thank Post
    1
    Thanked 80 Times in 54 Posts
    Rep Power
    31
    Can you install the msi via gpo and copy the file via gpp?

  6. #5
    MordyT's Avatar
    Join Date
    Sep 2012
    Location
    Milwaukee WI
    Posts
    106
    Thank Post
    11
    Thanked 31 Times in 29 Posts
    Rep Power
    7
    How about running whatever file you need through psexec?

    psexec @%labList% -h -n 5 c:\deploy\installTemp\install.bat

    That's what we use....

  7. #6
    superfletch's Avatar
    Join Date
    Nov 2007
    Location
    South
    Posts
    419
    Thank Post
    139
    Thanked 76 Times in 60 Posts
    Rep Power
    29
    All good answers so far. For my 2p worth.

    Open the elevated command prompt from your server (however you like) - you need only open it once and type the password once.

    Then use PSExec as @MordyT described to copy the file from the remote location to the target PC's. I'm presuming the elevated command prompt uses credentials which will authenticate against the target PC's (locally or at domain level) and have access over the directory which needs to receive the extra file.

    The PC's can be listed in a single text file (where @MordyT wrote @%lablist%).

    If you get the command right PSExec can copy the file from the network location to the local disk and loop through the text file to work on each of the target machines.
    Last edited by superfletch; 8th February 2013 at 09:41 AM.

  8. #7
    superfletch's Avatar
    Join Date
    Nov 2007
    Location
    South
    Posts
    419
    Thank Post
    139
    Thanked 76 Times in 60 Posts
    Rep Power
    29
    Just realised how old this thread is - sorry...

  9. #8
    MordyT's Avatar
    Join Date
    Sep 2012
    Location
    Milwaukee WI
    Posts
    106
    Thank Post
    11
    Thanked 31 Times in 29 Posts
    Rep Power
    7
    Its my fault, I didn't see the date either and brought it back to life.

  10. #9

    Join Date
    Jan 2012
    Posts
    610
    Thank Post
    172
    Thanked 80 Times in 57 Posts
    Rep Power
    67
    It's fine, chaps, I still never figured out how to do it (we don't have any of the programs you guys suggested in our image, I was hoping for a non-third-party way but that's not always the case) and I expect this problem will rear its head again in the future. So I'm still open to ideas. Your necrobump is forgiven.
    I ended up writing a small batch file to replace said file and RC-Run as Administrator on every PC.

    Thank goodness for NetSupport and its mass-logon (shame the mass-run can't run as admin, 'eh?)

  11. #10
    MordyT's Avatar
    Join Date
    Sep 2012
    Location
    Milwaukee WI
    Posts
    106
    Thank Post
    11
    Thanked 31 Times in 29 Posts
    Rep Power
    7
    PSexec shouldn't be considered 3rd party... everyone should have it in their path.

  12. #11

    Join Date
    Apr 2008
    Location
    Keighley, North Yorks
    Posts
    156
    Thank Post
    15
    Thanked 24 Times in 21 Posts
    Rep Power
    15
    Quote Originally Posted by Garacesh View Post
    (we don't have any of the programs you guys suggested in our image
    From memory, though feel free to correct me, you don't actually need PSExec in your image on the PCs - you only need it on your own PC/server as it installs itself as a service, runs, then removes itself.

    Many people do also put it (and the rest of PStools) on their PCs, but I don't think it's needed.

    Peter

  13. #12
    MordyT's Avatar
    Join Date
    Sep 2012
    Location
    Milwaukee WI
    Posts
    106
    Thank Post
    11
    Thanked 31 Times in 29 Posts
    Rep Power
    7
    Quote Originally Posted by howartp View Post
    From memory, though feel free to correct me, you don't actually need PSExec in your image on the PCs - you only need it on your own PC/server as it installs itself as a service, runs, then removes itself.

    Many people do also put it (and the rest of PStools) on their PCs, but I don't think it's needed.

    Peter
    This is correct. It only needs to be on the pc running the command. I don't know about it installing/removing a service on the client though...
    Although, if you want psexec on each pc, you can install it with psexec after deployment..

SHARE:
+ Post New Thread

Similar Threads

  1. Copying Command prompt to clipboard
    By russdev in forum Windows
    Replies: 10
    Last Post: 21st April 2009, 07:39 AM
  2. Uploading to sharepoint document library via command prompt?
    By BatchFile in forum Virtual Learning Platforms
    Replies: 1
    Last Post: 27th January 2009, 11:13 AM
  3. Replies: 4
    Last Post: 25th November 2008, 12:12 PM
  4. Prevent Student Access To Command Prompt
    By DaveP in forum How do you do....it?
    Replies: 13
    Last Post: 21st March 2007, 11:37 AM
  5. Run script with elevated permissions
    By ajbritton in forum Windows
    Replies: 3
    Last Post: 9th August 2006, 02:04 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •