运行Process.Start时无法打开:c:\ users \ ... \ temp \ package.cab

时间:2015-06-11 11:24:46

标签: c# scripting text-files temp

你好,我得到了这个微软的小脚本:

@echo off
rem *** Author: T. Wittrock, Kiel ***

if not exist "%TEMP%\wsusscn2.cab" (
  .\bin\wget.exe -N -i .\static\StaticDownloadLinks-wsus.txt -P "%TEMP%"
  if exist "%TEMP%\wuredist.cab" del "%TEMP%\wuredist.cab"
  if exist "%TEMP%\WindowsUpdateAgent30-x64.exe" del "%TEMP%\WindowsUpdateAgent30-x64.exe"
  if exist "%TEMP%\WindowsUpdateAgent30-x86.exe" del "%TEMP%\WindowsUpdateAgent30-x86.exe"
)
if exist "%TEMP%\package.cab" del "%TEMP%\package.cab"
if exist "%TEMP%\package.xml" del "%TEMP%\package.xml"
%SystemRoot%\System32\expand.exe "%TEMP%\wsusscn2.cab" -F:package.cab "%TEMP%"
%SystemRoot%\System32\expand.exe "%TEMP%\package.cab" "%TEMP%\package.xml"
del "%TEMP%\package.cab"


%SystemRoot%\System32\cscript.exe //Nologo //E:vbs .\cmd\XSLT.vbs "%TEMP%\package.xml" .\xslt\ExtractDownloadLinks-w60-x64-glb.xsl "%TEMP%\DownloadLinks-all.txt"


%SystemRoot%\System32\cscript.exe //Nologo //E:vbs .\cmd\XSLT.vbs "%TEMP%\package.xml" .\xslt\ExtractDownloadLinks-w60-x86-glb.xsl "%TEMP%\DownloadLinks-all.txt"

del "%TEMP%\package.xml"
del "%TEMP%\wsusscn2.cab"

:EoF

当我双击它时,我运行得很好。 我尝试使用以下代码通过C#打开它:

System.Diagnostics.Process.Start("C:\\Users\\me\\Desktop\\trunk-r664\\trunk\\ExtractDownloadLinks-all");

但是当我运行它时,它在cmd中出现错误,说:

Can not open input file: c:\users\me\appdata\local\temp\packacge.cab
Can not open input file: c:\users\me\appdata\local\temp\wsusscn2.cab

我想解决这个问题的最佳选择是机会微软的脚本吗?但我不知道怎么做。或者也许C#中有一个解决方案吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

我得到了一位对离线wsus非常了解且知道如何编写脚本的人的帮助。我在这里问同样的问题:http://forums.wsusoffline.net/viewtopic.php?f=4&t=5001&p=15991#p15991得到了这个答案: 特别感谢“Aker”!

System.Diagnostics.Process wsusou = new Process();
            wsusou.StartInfo.FileName = "cmd.exe";
            wsusou.StartInfo.Arguments = @"/k C:\Users\me\Desktop\trunk-r664\trunk\ExtractDownloadLinks-all.cmd"; // replace "/k" with "/c", if cmd should auto-close
            wsusou.StartInfo.WorkingDirectory = @"C:\Users\me\Desktop\trunk-r664\trunk";
            wsusou.Start();
            while (wsusou.HasExited == false)
            {
                System.Threading.Thread.Sleep(100);
            }
            wsusou.Dispose();