在网络位置保存批处理文件的输出

时间:2016-09-01 11:06:08

标签: batch-file windows-networking

我已经从多个地方提取了一些代码,并制作了以下代码。

此代码的功能基本上是读取所有软件并以csv格式保存,以便我可以进一步使用它。我希望代码将输出保存在域上共享的另一台计算机上的文件夹中。以下是代码:

@ECHO OFF 
SETLOCAL EnableExtensions EnableDelayedExpansion

set OutputFile=C:\Domo\%computername%.csv
echo "Computer","Key","Version","Name","Publisher">"%OutputFile%"

call :getsw "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall"
call :getsw "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall"
call :getsw "HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

ENDLOCAL
exit /b

:getsw
    for /F "delims=" %%g in ('reg query "%~1" 2^>NUL') do (
        set "_swRegKey=%%~g"
        set "_swName="
        set "_swVers="
        set "_swPub="

        for /F "tokens=1,2,*" %%G in ('
          reg query "%%~g" /V DisplayName 2^>NUL ^| findstr /I "DisplayName"
                                      ') do set "_swName=%%~I" 
        for /F "tokens=1,2,*" %%G in ('
          reg query "%%~g" /V DisplayVersion 2^>NUL ^| findstr /I "DisplayVersion"
                                      ') do set "_swVers=%%~I"
        for /F "tokens=1,2,*" %%G in ('
          reg query "%%~g" /V Publisher 2^>NUL ^| findstr /I "Publisher"
                                      ') do set "_swPub=%%~I"

        call :echosw 
        ) 
    exit /b

:echosw
    if "!_swName!!_swVers!"=="" (
        echo "%COMPUTERNAME%","unknown","!_swRegKey!","","">>"%OutputFile%"
    ) else (
        echo "%COMPUTERNAME%","!_swRegKey!","!_swVers!","!_swName!","!

_swPub!">>"%OutputFile%"
    )
    exit /b

问题是当我将输出文件(第3行)的位置从C:\ Domo \%computername%.csv更改为网络位置,例如\ Win-p0sck5u2hqd \ csv \%computername%。.csv

执行批处理文件时出现访问被拒绝的错误。有什么我想念的吗?请帮助我理解为什么它不起作用,是否有任何解决方案。

此位置\ Win-p0sck5u2hqd \可从我的运行命令访问。

0 个答案:

没有答案