Re: Windows Share Path

2017-12-03 Thread rjframe via Digitalmars-d-learn
On Sun, 03 Dec 2017 16:42:46 +, vino wrote:

> Question:
> Is there a way to map network drive in windows using D code, similar to
> the windows command such as "net use" or "pushd" or powershell command
> New-PSDrive.?
> 
> From,
> Vino.B

There's WNetAddConnection2[1] and WNetAddConnection3[2] in the Windows API. 
The API header module is core.sys.windows.winnetwk[3].

I've not used either function, but based on the documentation, it looks 
straightforward.

--Ryan


[1]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa385413
(v=vs.85).aspx
[2]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa385418
(v=vs.85).aspx
[3]: https://github.com/dlang/druntime/
blob/2db828bd4f21807254b770b3ec304f14596a9805/src/core/sys/windows/
winnetwk.d


Re: Windows Share Path

2017-12-03 Thread vino via Digitalmars-d-learn

On Sunday, 3 December 2017 at 01:27:40 UTC, codephantom wrote:

On Saturday, 2 December 2017 at 14:23:48 UTC, Vino wrote:

Hi,
  Even tried the Option "Run with Highest Privilege" but no 
luck. and also tried with option "Configure for : Windows 
Vista , Windows Server 2008"


From,
Vino.B


You haven't accidently ticked the 'Do not store password' 
option? That is a common mistake. (i.e. make sure it's *not* 
ticked, and reinsert credentials).


In my 'sysadmin' days, I *refused* to use the windows 
scheduler. I didn't want something that kept changing depending 
on which version of windows you were using. I wanted 
consistency.


From memory, i think I installed 'system scheduler' on all my 
MS servers.


https://www.splinterware.com/tour/scheduler.html


Hi All,

 Finally was able to resolve the issue, the issue was, the 
windows share was mapped using domain user so when the .bat 
program is scheduled via task manager with the option "Run 
whether the user is logged in or not" the .bat script run the 
task in session 0, where as the windows share was mapped in user 
session (domain user , session 23), so the the D program was not 
able to find the windows share path, so add the windows command 
"net use \\server\share" as the first line in the .bat and then 
added line calling the D program which resolved the issue.

Option : Do not store password was unchecked"

Solution:
D Program(TestDir.exe)
import std.stdio;
import std.file;
import std.path;


void main()
{
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); }
}
  }

Bat Program(Run.bat)
@echo off
net use N: \\shareserver\sharename /Persistence: No
start /D D:\DScript /B /WAIT D:\DScript\TestDir.exe
exit

Question:
Is there a way to map network drive in windows using D code, 
similar to the windows command such as "net use" or "pushd" or 
powershell command New-PSDrive.?


From,
Vino.B


Re: Windows Share Path

2017-12-02 Thread codephantom via Digitalmars-d-learn

On Saturday, 2 December 2017 at 14:23:48 UTC, Vino wrote:

Hi,
  Even tried the Option "Run with Highest Privilege" but no 
luck. and also tried with option "Configure for : Windows Vista 
, Windows Server 2008"


From,
Vino.B


You haven't accidently ticked the 'Do not store password' option? 
That is a common mistake. (i.e. make sure it's *not* ticked, and 
reinsert credentials).


In my 'sysadmin' days, I *refused* to use the windows scheduler. 
I didn't want something that kept changing depending on which 
version of windows you were using. I wanted consistency.


From memory, i think I installed 'system scheduler' on all my MS 
servers.


https://www.splinterware.com/tour/scheduler.html




Re: Windows Share Path

2017-12-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Dec 2017 14:16:17 +, Vino wrote:

> 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

Is storing the password allowed by your local security policy? (gpedit on 
the local machine: Computer Configuration > Windows Settings > Security 
Settings > Local Policies > Security Options > Network access: Do not 
allow storage of passwords and credentials for network authentication)

Other than that, I'm out of ideas; this should be a slow week at work so I 
might be able to try later.

Note that running "whether logged on or not" will run in interactive mode 
so your `writeln`s won't output anywhere; you'd need to log to a file. But 
it shouldn't restrict network access.

--Ryan


Re: Windows Share Path

2017-12-02 Thread Vino via Digitalmars-d-learn

On Saturday, 2 December 2017 at 14:16:17 UTC, Vino wrote:

On Saturday, 2 December 2017 at 13:05:37 UTC, rjframe wrote:

[...]


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

Hi,
  Even tried the Option "Run with Highest Privilege" but no luck. 
and also tried with option "Configure for : Windows Vista , 
Windows Server 2008"


From,
Vino.B


Re: Windows Share Path

2017-12-02 Thread Vino via Digitalmars-d-learn

On Saturday, 2 December 2017 at 13:05:37 UTC, rjframe wrote:

On Sat, 02 Dec 2017 07:48:14 +, 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:  
```

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






Re: Windows Share Path

2017-12-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Dec 2017 07:48:14 +, 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
>>  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:  
```

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


Re: Windows Share Path

2017-12-02 Thread codephantom via Digitalmars-d-learn

On Saturday, 2 December 2017 at 07:48:14 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"




Are you using appropriate credentials in the scheduled task?



Re: Windows Share Path

2017-12-01 Thread Vino via Digitalmars-d-learn

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  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


Windows Share Path

2017-12-01 Thread Vino via Digitalmars-d-learn

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  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