On Saturday, 2 December 2017 at 13:05:37 UTC, rjframe wrote:
On Sat, 02 Dec 2017 07:48:14 +0000, Vino wrote:

On Saturday, 2 December 2017 at 05:08:27 UTC, Vino wrote:
[...]

Even tried with the below code, it works manually but not via Windows scheduler with option "Run whether user is logged on or not"

Program:
import std.stdio;
import std.file;
import std.path;
import std.string;
import std.process;

void main()
{
auto result =
execute(["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\
\powershell.exe",
"-command", "New-PSDrive -Name", "R", "-PSProvider FileSystem -Root",
"\\\\bp1xeuss005-f05.bp.com\\ea_sap_basis2$", "-Persist"]);
auto p = "R:\\BACKUP";
if (!p.isValidPath && !p.strip.isValidFilename || !p.exists ) {
writeln("Invalid File Path (", p, ") or Path do not Exist"); }
else { writeln("File Exist :", p); }

}
From,
Vino.B

FYI: The backquote gives you a WYSIWYG string: `c:\windows\system32`, which is incredibly useful for Windows paths.


I don't have a network share available to test with, but:

Are you running with elevated privileges in the scheduled task? If so, do you run as admin when trying manually? If you mount the share as a user, I'm wondering if the task can't access it running in another context.

You could try in the batch file, either adding
```
net use N: \\server\share\BACKUP /USER: <user> <password>
```

prior to running the exe (and "net delete" afterword), or try
"pushd \\server\share\BACKUP" to access the path (and make it the current working directory). Use "popd \\server\share\BACKUP" at the end of the
script.

Source: https://blog.adrianbanks.co.uk/windows/2007/03/08/accessing- network-file-shares-from-a-command-prompt.html

Hi,

The script is schedule using a domain user id(domain\user id), and the windows share are mapped using the same user id /password and ran the scheduled task by login with the same domain user(Not Administrator) , the script executes fine when run manually and executes fine when scheduled with option "Run when user is logged in" , but the same is not running when schedule with option "Run whether user is logged in or not". The domain id is added to the Administrator Group and the Security policy "Logon as Batch user" is assigned. The domain id has the Full access to the Network share.

From,
Vino.B




Reply via email to