none
Batch file run as immediate scheduler task does not behave as expected RRS feed

  • Question

  • Win10Pro
    Home network
    My login has Admin rights

    I have been trying to make a batch file (below) run at startup.

    subst J: "G:\BUSINESS DATA"
    du -q "C:\windows\Temp"

    Solution#1
    There is a shortcut in the local account startup folder (located with run> shell:startup)

    The DU command would normally fail becasue (I understand) the temp folder is owned by System but the first solution was to chown the folder to my login, and it worked fine until...

    an update chowned the folders back to System so I thought it would be nice to solve the problem in a more comprehensive way.

    Solution #2
    I tried a scheduler-task that is called by a shortcut in the local account startup folder with the target -:

    C:\Windows\System32\schtasks.exe /RUN /TN \Ahs_Apps\Ahs_Subst_batch_file

    Properties
    Runs with my account
    Run with highest prviledges
    Configured for Win10

    The DU command works fine.

    The subst command reports as it did in solution#1 but no J: drive is created

    When the shortcut is then run manually immediately afterwards it reports: Drive is already SUBSTed. I tried J: from a command shell and it says the drive is not present.

    If I revert to Solution#1, then at startup J: is created and if I run the batch file manually immediately afterwards it reports as above as expected.
    Thursday, November 23, 2017 12:48 PM

Answers

  • substr does not create drives.  It creates an alias for a path.  That alias can look like a drive.  It exists only during  the current session.

    To permanently map a drive use PowerShell.

     New-PsDrive -Name J -Root 'G:\BUSINESS DATA' -Persist -PSProvider FileSystem

    This drive is a full drive and is persistent across sessions.

    Normally we would use Group Policy to set persistent drives.  It is much easier to manage with GP.

    "batch" is obsolete.  Don't waste your time learning it.  It will not exist in future versions of Windows.


    \_(ツ)_/

    Thursday, November 23, 2017 6:23 PM

All replies

  • As I posted before.  The system will clean up the temp folder periodically.  It is not necessary for you to do this.  Just be sure the default claner/optimizer is running and someone hasn't stopped it.

    cleanmgr /?

    https://support.microsoft.com/en-us/help/253597/automating-disk-cleanup-tool-in-windows


    \_(ツ)_/

    Thursday, November 23, 2017 1:22 PM
  • Thank you for your suggestion, however there are things going on here which I would like to understand. So Hopefully there will be someone willing to explain what's happening.
    Thursday, November 23, 2017 5:24 PM
  • Without access to you system that would not be possible.


    \_(ツ)_/

    Thursday, November 23, 2017 5:32 PM
  • I should also note that creating a drive under the system account or with the scheduler does not create the drive outside of that session.

    Why do you have to crate a drive? Why do you have to use a batch file?


    \_(ツ)_/

    Thursday, November 23, 2017 5:34 PM
  • OK, that makes sense, but it seems like a behaviour that should be modifiable. To me the idea of a scheduler is that is does a job for me. If I tell it to create some drives, then I expect it to do that, not to play coy and say well you can have the drives while I am running, but if I stop the drives go with me.

    I have a number of pcs all with different versions of windows and different drive configurations, all of which have copies of my data. I have devised a set of drive letters that enable all my software to access all that data via those drives on all the platforms. It's simple, and it works. All I have to do is create a set of subst commands for each platform that create the drives. So I have no difficulty adding PCs.

    Over the years I have had so much trouble with Windows not doing it's own housekeeping I decided just to view the temp folders at startup. And it's a good job I did because the folders can be empty for a while and then suddenly begin filling up. So I let them go for a while and then zap them. Although recently I discovered CleanMgr.exe but I haven't had time to study it.

    To me the idea of Scheduler is that is does something I could do during my login but I chose to farm out the task. That means I want it to act as if it's me within my login session.

    Although come to think of it, if what you say is true then running the task manually after it ran at startup should not find the drives present. But it does. So that seems to indicate it's created another session somehow that exists after Scheduler stops but is not my session, so I can't see its drives but scheduler can - that seems weird.

    Thursday, November 23, 2017 6:14 PM
  • substr does not create drives.  It creates an alias for a path.  That alias can look like a drive.  It exists only during  the current session.

    To permanently map a drive use PowerShell.

     New-PsDrive -Name J -Root 'G:\BUSINESS DATA' -Persist -PSProvider FileSystem

    This drive is a full drive and is persistent across sessions.

    Normally we would use Group Policy to set persistent drives.  It is much easier to manage with GP.

    "batch" is obsolete.  Don't waste your time learning it.  It will not exist in future versions of Windows.


    \_(ツ)_/

    Thursday, November 23, 2017 6:23 PM
  • Well that's seen me safely out of the copse, but across the clearing I see a forest to negotiate. Oh well, such is life.

    Thank you for that. I think I see what needs to be done.

    Thursday, November 23, 2017 8:53 PM
  • But, lo! from forth a copse that neighbours by,
    A breeding jennet, lusty, young, and proud,
    Adonis’ trampling courser doth espy,
    And forth she rushes, snorts and neighs aloud

         ---- Will S.


    \_(ツ)_/

    Friday, November 24, 2017 12:46 AM
  • oh very good :-)
    Friday, November 24, 2017 8:20 AM