CMD / Batch file: Creating an output/log file on a network share doesn't work

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tds1973lbp
Posts: 7
Joined: 02 Feb 2017 01:19

CMD / Batch file: Creating an output/log file on a network share doesn't work

#1 Post by tds1973lbp » 03 Feb 2017 04:32

Hello, :D

I want to make my CMD command's result be written to a txt file. No problem.

But creating the txt on a network share doesn't work.

Is this regularly impossible or do I have to chose a special syntax?

...>\\192.168.0.1\testshare\log.txt doesn't work. Creating the txt on a local drive works.

Access rights for the network share are given (share rights + ntfs rights: Everybody could do everything).

TD

Squashman
Expert
Posts: 3664
Joined: 23 Dec 2011 13:59

Re: CMD / Batch file: Creating an output/log file on a network share doesn't work

#2 Post by Squashman » 03 Feb 2017 07:51

I have no problems writing to a file using a unc path. Maybe you should show us the REAL code you are using.

Also posted on SO.
http://stackoverflow.com/questions/4202 ... oesnt-work

tds1973lbp
Posts: 7
Joined: 02 Feb 2017 01:19

Re: CMD / Batch file: Creating an output/log file on a network share doesn't work

#3 Post by tds1973lbp » 06 Feb 2017 03:20

Hello Squashman,

sorry - yes, after some tests I can confirm that the problem is not the CMD command generally.

I start the command remote - via WMI.

I made some tests. Result is: Make the remote system starting the the CMD command works.

But: You can't make the remote system do something on a third system!

Starting the test app on the remote system - it works. The CMD command can create the txt file on a local drive on the remote system. But when you want the txt be created on a third system it fails.

Same result:
When you make the remote system create the txt on ofe of its local drives and then make it move the txt on a third system via CMD command, it fails.

It is not a CMD/DOS/Batch problem ... it is a problem concerning WMI. It seems to be a kind of security problem.

Code: Select all


Function funct_test()

    Dim objWMIService
    Dim objProcess
   
    Dim strCMDApp, strCMDLog, strCMDFull
   
    Dim lngReturn
    Dim intPID
   
    Set objLocator = CreateObject("WbemScripting.SWbemLocator")   
    Set objWMIService = objLocator.ConnectServer("192.168.0.5", "root\cimv2", "TEST-PC\testuser", "123456789")

    strCMDApp = """C:\Program Files\testapp\testapp.exe"""
    strCMDLog = """\\192.168.0.7\log\log.txt"""

    strCMDFull = "cmd /von /c ""call " & strCMDApp & " &>" & strCMDLog & " echo !errorlevel!"""
   
    Set objProcess = objWMIService.Get("Win32_Process")
    lngReturn = objProcess.create(strCMDFull, Null, Null, intPID)
    Set objProcess = Nothing

    Set objWMIService = Nothing   
    Set objLocator = Nothing

End Function


Squashman
Expert
Posts: 3664
Joined: 23 Dec 2011 13:59

Re: CMD / Batch file: Creating an output/log file on a network share doesn't work

#4 Post by Squashman » 06 Feb 2017 07:28

Sounds more like a permissions issue.

tds1973lbp
Posts: 7
Joined: 02 Feb 2017 01:19

Re: CMD / Batch file: Creating an output/log file on a network share doesn't work

#5 Post by tds1973lbp » 07 Feb 2017 02:16

That's it. No CMD problem. It is WMI. You can't open a WMI session and then make another connect from the remote system to a third system. It is forbidden.

Post Reply