&& Weirdness

Page 1 of 2 12 LastLast

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

    && Weirdness


    Code:
    runas /user:Administrator "defrag c: /V"
    This works.
    Code:
    runas /user:Administrator "cleanmgr /VERYLOWDISK"
    This works.
    Code:
    runas /user:Administrator "defrag c: /V" && "cleanmgr /VERYLOWDISK"
    This does not work.

    I've tried /savecred thinking it might be some silly privilege issue, but that doesn't work either.
    Where did I go wrong?
      My Computer


  2. Posts : 795
    Microsoft Windows 10 Pro 64-bit
       #2

    Try a semicolon ​; ​ in powershell
    Last edited by Digital Life; 23 Apr 2017 at 17:48.
      My Computer


  3. Posts : 25,111
    10 Home x64 (21H2) (10 Pro on 2nd pc)
       #3

    In a command prompt a single & acts as a delimiter between two commands, effectively allowing you to enter a sequence of commands on one line as if you had typed each command after the previous one had completed.

    The double && is similar, but will only execute the command following the && if the previous command was successful. It may be that your first command didn't return a 'success' code.

    You can use the special characters listed in the following table to pass multiple commands.

    Character Syntax Definition
    & [...] command1 & command2 Use to separate multiple commands on one command line.
    Cmd.exe runs the first command, and then the second
    command.
    && [...] command1 && command2 Use to run the command following && only if the command
    preceding the symbol is successful. Cmd.exe runs the first
    command, and then runs the second command only if the first
    command completed successfully.
    || [...] command1 || command2 Use to run the command following || only if the command
    preceding || fails. Cmd.exe runs the first command, and then
    runs the second command only if the first command did not
    complete successfully (receives an error code greater than zero).
    ( ) [...] (command1 & command2) Use to group or nest multiple commands.
    ; or , command1
    parameter1;parameter2
    Use to separate command parameters.
    https://www.microsoft.com/resources/...loverview.mspx
      My Computers


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

    Try a semicolon ​; ​ in powershell
    That's good to know, but it appears to skip over the second command in PowerShell.

    In a command prompt a single & acts as a delimiter between two commands, effectively allowing you to enter a sequence of commands on one line as if you had typed each command after the previous one had completed.

    The double && is similar, but will only execute the command following the && if the previous command was successful. It may be that your first command didn't return a 'success' code.
    If I use & instead of && in CMD, it still skips the second command and gives me this error.
    >The system cannot find the path specified.

    Code:
    runas /user:Administrator ("defrag c: /V" & "cleanmgr /VERYLOWDISK")
    If I use nesting, neither command works and I get two cannot find path errors.
      My Computer


  5. Posts : 1,983
    Windows 10 x86 14383 Insider Pro and Core 10240
       #5

    Observation (may or may not affect outcome):

    If you run the cleanmgr command first, and some files are removed, followed by the defrag command, if successful, there will be fewer files to defrag, and there will be more space on disk for defrag to operate with, and fill gaps, resulting in a faster overall time, and a neater result on disk than the other way around..
      My Computers


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

    If you run the cleanmgr command first, and some files are removed, followed by the defrag command, if successful, there will be fewer files to defrag, and there will be more space on disk for defrag to operate with, and fill gaps, resulting in a faster overall time, and a neater result on disk than the other way around..
    Yes, the ordering was not very bright on my part. The outcome is still the same with only the first command being run.
      My Computer


  7. Posts : 8,701
    Mac OS Catalina
       #7

    jnich said:
    Yes, the ordering was not very bright on my part. The outcome is still the same with only the first command being run.
    Running those commands all of the time is just wearing down your hard drive, especially if you have a SSD. You should never run those commands, unless you have made major changes such as an upgrade to the next step version of Windows 10, or have removed a bunch of files that have been moved to another drive.
      My Computer


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

    Running those commands all of the time is just wearing down your hard drive, especially if you have a SSD. You should never run those commands, unless you have made major changes such as an upgrade to the next step version of Windows 10, or have removed a bunch of files that have been moved to another drive.
    I'm keenly aware. My intention is to write a one liner or batch script which does manual routine maintenance like defrag (on HDD), disk clean, defender update and scan, and windows update. I would like to write out a log of each process as well, but this is a secondary issue.
      My Computer


  9. Posts : 8,701
    Mac OS Catalina
       #9

    jnich said:
    I'm keenly aware. My intention is to write a one liner or batch script which does manual routine maintenance like defrag (on HDD), disk clean, defender update and scan, and windows update. I would like to write out a log of each process as well, but this is a secondary issue.
    You do not need to do one, since it actually causes Windows 10 to screw up its built in housekeeping duties and slows down your system. As I stated before, you do not have to do any of this, since Windows 10 automatically looks at the hard drive and defrags it as part of its housekeeping when booting up or shutting down it records that info for it to happen the next time you turn the system back on or reboot.

    The only time you have to use Disk Cleanup is after a in place upgrade or doing a clean install and having updates installed, along with installing programs on the machine.
      My Computer


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

    bro67 said:
    You do not need to do one, since it actually causes Windows 10 to screw up its built in housekeeping duties and slows down your system. As I stated before, you do not have to do any of this, since Windows 10 automatically looks at the hard drive and defrags it as part of its housekeeping when booting up or shutting down it records that info for it to happen the next time you turn the system back on or reboot.

    The only time you have to use Disk Cleanup is after a in place upgrade or doing a clean install and having updates installed, along with installing programs on the machine.
    Please forget the programs I'm using since they are irrelevant to the issue at hand.
    Code:
    mkdir new && cd new && echo 'test' > 1.txt
    Why would this work as a regular user?
    Code:
    runas /user:Administrator mkdir new && cd new && echo 'test' > 1.txt
    ...but not this?
    Code:
    runas /user:Administrator "mkdir new && cd new && echo 'test' > 1.txt"
    ..or this?
      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 09:41.
Find Us




Windows 10 Forums