none
List a folder contents at startup using batch file when folder owned by system RRS feed

  • Question

  • Win 10 Pro

    I have a batch file called by a shortcut in startup. It creates a few drives with subst and then lists contents of temporary folders with the DU command.

    There is no output from the command below unless the batch  file runs as administrator, even though I have admin rights.

    du -q "C:\windows\Temp"

    At one time I changed the protections on the temp folder but then I reasoned that it would be nice if the procedure would handle the situation where an update reinstates SYSTEM ownership which has just happened - hence the lack of output from the DU command.

    If a shortcut to the batch file is configured to run as administrator then the UAC gets in the way. So I tried the work-around to create a scheduled task to be run via a startup batch file. After a lot of fiddling about it will run and the subst commands appear to work but the drives are not actually created. And there appears to be no control of the cmd display either, ie font size and dialogue size.

    So I am now trying to solve problems several generations of problem removed from the original.

    • Moved by Bill_Stewart Thursday, January 25, 2018 10:37 PM Off-topic
    Sunday, November 19, 2017 7:22 PM

All replies

  • You cannot do what you are trying to do.  Startup runs before there is a GUI to display on and output can only be sent to a full session.

    \_(ツ)_/

    Sunday, November 19, 2017 7:41 PM
  • If my login is given ownership of the temp folders, the du command produces the desired output. And certainly the drives are created. The only time that the subst command seemed to fail was if using the task scheduler method - which I may have done incorrectly. But I didn't want to carry on down an never-ending labyrinth of complexity with that method and an ever increasing set of faults to solve.

    To which aspect of the script are you referring please?

    Sunday, November 19, 2017 11:15 PM
  • A startup script is run from the system startup scripts folder here: "C:\WINDOWS\System32\GroupPolicy\Machine\Scripts\Startup".

    Scripts located here run under SYSTEM.  They run before the system is fully available for user access.

    You have to explain why you need to do this? So far your explanation is conflicted.


    \_(ツ)_/

    Sunday, November 19, 2017 11:24 PM

  • I've not seen that startup folder before. The one I use is accessed from run>shell:startup

    For me that equates to 

    C:\Users\Stephen_Ford\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

    A batch file there runs the same as if run manually - it opens a cmd dialogue and displays the programmed info. But now that Win10 using the UAC, that gets in the way of the startup instantiation as compared with the manual instantiation.

    Some bright spark realised that a scheduled task can be run from a similar batch file with user privileges but which is created by an admin who sets the task to run with admin privilege. But I have not created a bug-free version of this method yet. I decided to go back to the original idea to see if the du command could be persuaded to run as admin.
    Sunday, November 19, 2017 11:50 PM
  • Have you also put the script under the Common Startup location and test if it runs?

    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

    This runs after the user logs in. This location becomes invisible since the new Windows start button.


    • Edited by Naw Sunday, November 19, 2017 11:52 PM
    Sunday, November 19, 2017 11:51 PM
  • That is a local user startup folder.  It does not have access to protected folders or to system folders.

    Why do you need to do this?  It is likely that you are taking the wrong approach to solving a problem that you have not defined.  Why do you need to create these links on every login?  Why not use links and not subst?  Subst is an old and mostly unused command.


    \_(ツ)_/

    Sunday, November 19, 2017 11:55 PM
  • There's no magic in this. I mentioned subst just because the command is there and it works a treat for my needs. They have no other relevance.

    The du command lists various temp folder contents because I want to see the size of the contents at login (which is as good a time as any...). Windows' programmers have a habit of creating lots of rubbish and then not tidying up after themselves, so I clear them out periodically.

    Monday, November 20, 2017 9:26 AM
  • "du" is not a command in Windows batch.

    Windows manages the temp folder automatically.

    Place the batch file in the local user startup folder and it will work but access to the temp folder requires elevation.

    Programmers do not use \windows\temp.  It is owned by the system and only system processes can use it.  If you have no disabled the system optimization then this folder will be cleared periodically.


    \_(ツ)_/

    Monday, November 20, 2017 10:46 AM