Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to do what I believed would be very simple: have a .bat file that rename two folders on a network drive. The script works fine when running from prompt, but not from the scheduler. Any ideas why?

Setup

Network drive \\NAS\Backup mapped as B:

Folders in Backup that should be renamed: Current and Previous

  • \\NAS\Backup\Current
  • \\NAS\Backup\Previous

Task XML

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2013-12-12T16:01:26.5634611</Date>
    <Author>nivis-server\nivis</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2013-12-12T00:00:05</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Saturday />
        </DaysOfWeek>
        <WeeksInterval>1</WeeksInterval>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>nivis</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\script\SwitchNivisCurrent.bat</Command>
      <Arguments>&gt; execution.log</Arguments>
      <WorkingDirectory>C:\script</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

Script

Located in c:\script

rename B:\Current tmp
rename B:\Previous Current
rename B:\tmp Previous



========== UPDATE: Solution - courtesy of techie007 ==========

techie007 provided the solution and the script now looks like:

net use x: \\10.22.0.105\nivis-nas ****PWD**** /user:nivis

x:

rename Current tmp
rename Previous Current
rename tmp Previous

net use x: /d
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Couple things to consider:

  1. It may be executing in a user context ("nivis") that doesn't have access to that network location.
  2. Drive maps are user- and session-centric. The B: map may not exist for the user/session that the task runs in.

For 1: Ensure the user it's being run as has write/modify access to both the share and the underlying folders/files you want to change.

For 2: Modify the batch file to map B: to the network location (net use) at the start, and then un-map it a the end. Alternatively, reference the network share by UNC (\\servername\sharename) instead of using a mapped drive.

share|improve this answer
    
#2 here is important. A good example of this would be mapping a drive in Explorer, and then starting an admin command prompt - note that the drive mappings do not exist in that context. –  ernie Dec 12 '13 at 16:58
1  
I tried your second proposal and it worked. Thanks! –  nivis Dec 12 '13 at 20:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.