2

I am having following issue when I try to use net use using a batch file which is configured in Hudson.

I added test user as administrator in remote Windows Server 2012 and also set the password.

My batch script:

net use p: /delete  
net use p: "\\cazrt\C$" /USER:test /PERSISTENT:NO xxxxx
set "source=%~1"
set "target=p:/%~2"

echo "%source%" "%target%"

echo F|xcopy /S /I /Q /Y "%source%" "%target%"

Output on execution:

[exec] C:\HudsonProjects\NGA>net use p: /delete   
[exec] 
[exec] C:\HudsonProjects\apps>net use p: "\\cazrt\C$" /USER:test /PERSISTENT:NO xxxxx 
[exec] System error 5 has occurred.
[exec] 
[exec] Access is denied.

If I try to use net use without PERSISTENT, I get the same access denied error and the network connection could not be found.

Output on execution:

[exec] C:\HudsonProjects\NGA>net use p: /delete   
[exec] 
[exec] C:\HudsonProjects\apps>net use p: "\\cazrt\C$" /USER:test xxxxx 
[exec] The network connection could not be found.
[exec] More help is available by typing NET HELPMSG 2250.
[exec] 
[exec] 
[exec] 
[exec] C:\HudsonProjects\apps>set "source=D:/target/DROP" 
[exec] 
[exec] C:\HudsonProjects\apps>set "target=p:/C:/temp" 
[exec] 
[exec] C:\HudsonProjeSystem error 5 has occurred.
[exec] 
[exec] Access is denied.

If I type net use from local windows machine, it is showing:

\\cazrt\c$ command executed successful.
Mofi
  • 46,139
  • 17
  • 80
  • 143
testprabhu
  • 63
  • 1
  • 8
  • Is Hudson using your account or does it run as a service ? – Marged Feb 05 '16 at 13:47
  • Hudson will call the build.xml from ant xml it will call the cmd to execute which will do the copy – testprabhu Feb 05 '16 at 13:57
  • 1
    will not solve your problem, but you should rethink `set "target=p:/C:/temp"` – Stephan Feb 05 '16 at 14:03
  • This does not answer my question. There must be a reason why you are denied access. – Marged Feb 05 '16 at 14:47
  • C$ is an administrative share and not intended for general usage. Getting an "access denied" error is the expected outcome. Create your own share and ensure that the user account that runs Hudson has the required access rights. Using the share name instead of mapping a drive letter is also strongly recommended. Use serverfault.com to ask more about it. – Hans Passant Feb 05 '16 at 15:44

1 Answers1

3

you can checkout https://helgeklein.com/blog/2011/08/access-denied-trying-to-connect-to-administrative-shares-on-windows-7/ solution

basically:

One may like this or not, the solution is luckily pretty simple. UAC remote restrictions can be disabled by setting the registry value LocalAccountTokenFilterPolicy to 1:

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System Value: LocalAccountTokenFilterPolicy Data: 1 (to disable, 0 enables filtering) Type: REG_DWORD (32-bit) After a reboot access tokens from remote connections are not filtered any more. On Windows 8 and Windows 10 the reboot is not even required any more.

Mark Woods
  • 31
  • 2