CLI runas admin

Page 1 of 2 12 LastLast

  1. Posts : 11
    Windows 10, Debian 9
       #1

    CLI runas admin


    Code:
    net localgroup administrators
    Members
    -----------------------------
    Administrator
    user

    Code:
    runas /user:Administrator "chkdsk c:"
    <enter user, which should be administrator, pass>
    user name or password is incorrect

    Code:
    runas /user:user "chkdsk c:"
    <enter user pass>
    attempting to start chkdsk c: as user ...

    Fails to run.

    What am I missing here? Is there a way to give Administrator member its own password. It appears as though my user pass doesn't work even though it's supposedly admin. To be clear, I'm not asking how to right click. How do I elevate to admin privilege and run a program through cli?
      My Computer


  2. Posts : 3,453
       #2

    This may not be a direct solution as cmd is a bit foreign to me ... however in powershell...

    Code:
    <################################################# Elevate ######################################################>
    $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
    $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
    $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
    
    if (-not ($myWindowsPrincipal.IsInRole($adminRole)))
      {
        Start-Process PowerShell.exe -Verb Runas -ArgumentList $myInvocation.MyCommand.Definition
        return
       }
    <################################################################################################################>
    
    chkdsk.exe /f /r e:
    Change the drive letter to whichever - and save as something.ps1
      My Computer


  3. Posts : 5,478
    2004
       #3

    Not sure what your question is.

    Do you mean you want to set Administrator password?
    Code:
    net user administrator Password /active:yes
    or you want to elevate privileges, for example
    Code:
    :checkPrivileges 
    NET FILE 1>NUL 2>NUL
    if '%errorlevel%' == '0' ( goto gotPrivileges 
    ) else ( powershell "saps -filepath %0 -verb runas" >nul 2>&1)
    exit /b
    windows - How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required? - Stack Overflow
      My Computer


  4. Posts : 856
    Windows 10 Pro 21H2 build 19045.2193 Dual Boot Linux Mint
       #4

    Over complicating things, just run the Command Processor as Administrator.

    Right Click Run as Administrator.

    Code:
    Microsoft Windows [Version 10.0.15063]
    (c) 2017 Microsoft Corporation. All rights reserved.
    
    C:\WINDOWS\system32>chkdsk c:
    The type of the file system is NTFS.
    Volume label is System.
    
    WARNING!  /F parameter not specified.
    Running CHKDSK in read-only mode.
    
    Stage 1: Examining basic file system structure ...
                                                                                                                                                                      327936 file records processed.                                                
    File verification completed.
                                                                                                                                                                      3606 large file records processed.
                                                                                                                                                                      0 bad file records processed.
    
    Stage 2: Examining file name linkage ...
                                                                                                                                                                      397314 index entries processed.                                               
    Index verification completed.
                                                                                                                                                                      0 unindexed files scanned.
                                                                                                                                                                      0 unindexed files recovered to lost and found.
    
    Stage 3: Examining security descriptors ...
    Security descriptor verification completed.
                                                                                                                                                                      34690 data files processed.
    CHKDSK is verifying Usn Journal...
                                                                                                                                                                      36069072 USN bytes processed.                                                 
    Usn Journal verification completed.
    
    Windows has scanned the file system and found no problems.
    No further action is required.
    
     233058303 KB total disk space.
      47762496 KB in 141521 files.
         95840 KB in 34691 indexes.
             0 KB in bad sectors.
        555091 KB in use by the system.
         65536 KB occupied by the log file.
     184644876 KB available on disk.
    
          4096 bytes in each allocation unit.
      58264575 total allocation units on disk.
      46161219 allocation units available on disk.
    
    C:\WINDOWS\system32>
      My Computers


  5. Posts : 5,478
    2004
       #5

    clam1952 said:
    Over complicating things, Right Click Run as Administrator.
    They did say in the first post:

    jnich said:
    To be clear, I'm not asking how to right click.
    Perhaps you missed it.
      My Computer


  6. Posts : 856
    Windows 10 Pro 21H2 build 19045.2193 Dual Boot Linux Mint
       #6

    Seems to be a pointless over complication just to run chkdsk......

    Maybe it doesn't work as the Computer name isn't specified? runas /user:computer name\account name chkdsk C:
      My Computers


  7. Posts : 11
    Windows 10, Debian 9
    Thread Starter
       #7

    Thank you lx07! I needed to set a password for Administrator member reboot and runas /user:Administrator to get it working. I'm sorry for the confusion. chkdsk was just an example.
      My Computer


  8. Posts : 856
    Windows 10 Pro 21H2 build 19045.2193 Dual Boot Linux Mint
       #8

    OK I'm now unconfused, glad you got it sorted. :)
      My Computers


  9. Posts : 31,651
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #9

    jnich said:
    I needed to set a password for Administrator....
    Yes, runas requires the account you want to 'run as' to have a password - else you get...
    Account restrictions are preventing this user from signing in. For example: blank passwords aren't allowed...
    By default the built-in Administrator account has a blank password and is disabled. Setting a password for Administrator has a downside, it is the account used when booting to the repair environment and your emergency way in when all else fails. Forget that password and your only repair option may be a clean install.

    It would be better to leave Administrator alone, for your purposes I would create another local account (say, Admin) make that an administrator and give it a password. Then you can runas Admin rather than the built-in Administrator.
      My Computers


  10. Posts : 11
    Windows 10, Debian 9
    Thread Starter
       #10

    Bree said:
    It would be better to leave Administrator alone, for your purposes I would create another local account (say, Admin) make that an administrator and give it a password. Then you can runas Admin rather than the built-in Administrator.
    This is where my troubles began. According to Windows, my user was the Administrator so running as that user and providing its password should have worked. I tried several times, just to be sure there wasn't a typo when entering my password. Assigning a password to Administrator and rebooting did the job. I'm not worried about forgetting a password in this environment, but I'll keep that in mind.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 01:40.
Find Us




Windows 10 Forums