Windows Share Path

rjframe dlang at ryanjframe.com
Sat Dec 2 13:05:37 UTC 2017


On Sat, 02 Dec 2017 07:48:14 +0000, Vino wrote:

> On Saturday, 2 December 2017 at 05:08:27 UTC, Vino wrote:
>> Hi All,
>>
>>   Request your help, I have samll program which validates the
>> file path, the script run perfectly when i run it manually, but if i
>> run it via windows task scheduler i am getting "Invalid File Path
>> <Path> or Path do not Exist", The path is a windows share, Even tried
>> to add the net path as "\\\\server\\share$\\BACKUP" for the parameter
>> "p" in the below code but no luck, the same error.
>>
>> Even tried to call this program via .bat script not luck same error
>>
>> Windows .BAT program @echo off cd D:\DScript start /D D:\DScript /B
>> /WAIT D:\DScript\TestDir.exe exit
>>
>> Program import std.stdio;
>> import std.file;
>> import std.path;
>> import std.system;
>>
>> void main()
>> {
>>  version (Windows) { auto p = "N:\\\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
> 
> 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


More information about the Digitalmars-d-learn mailing list