Schlagwort-Archive: batch

convert Powerpoint to JPG or PNG or whatever

I had to find an easy solution for my colleaugue to convert Powerpoint files to e.g. JPGs.
They have a big screen where they want to do slideshows and the people do Powerpoint files for easy changes.
Instead of doing all manually with save as and such it should be an automatic conversion.

Here is the batch convertPowerpoint2JPG.bat I came up with:

@echo off
SET imagemagickpath=%~dp0
set filepath=%~dp1
set extension=%~x1
set filename=%~n1
echo convert Powerpoint to PDF
if exist "%filepath%%filename%.pdf" del "%filepath%%filename%.pdf"
CSCRIPT "%imagemagickpath%ppt2pdf.vbs" "%filepath%%filename%%extension%" "%filepath%%filename%.pdf"
if not exist "%filepath%%filename%" mkdir "%filepath%%filename%"
echo convert PDF to JPGs
"%imagemagickpath%convert.exe" -monitor -quality 100 -unsharp 0x1 -density 400 "%filepath%%filename%.pdf" -resize 60%% "%filepath%%filename%\%filename%.jpg"
exit /b

It uses a vbs Skript to invoke Powerpoint for pdf saving and then converts the PDF with ImageMagick (actually the embedded portable GhostScript) to JPG.

The code for ppt2pdf.vbs is:

Option Explicit

Sub WriteLine ( strLine )
    WScript.Stdout.WriteLine strLine
End Sub

' http://msdn.microsoft.com/en-us/library/office/aa432714(v=office.12).aspx
Const msoFalse = 0   ' False.
Const msoTrue = -1   ' True.

' http://msdn.microsoft.com/en-us/library/office/bb265636(v=office.12).aspx
Const ppFixedFormatIntentScreen = 1 ' Intent is to view exported file on screen.
Const ppFixedFormatIntentPrint = 2  ' Intent is to print exported file.

' http://msdn.microsoft.com/en-us/library/office/ff746754.aspx
Const ppFixedFormatTypeXPS = 1  ' XPS format
Const ppFixedFormatTypePDF = 2  ' PDF format

' http://msdn.microsoft.com/en-us/library/office/ff744564.aspx
Const ppPrintHandoutVerticalFirst = 1   ' Slides are ordered vertically, with the first slide in the upper-left corner and the second slide below it.
Const ppPrintHandoutHorizontalFirst = 2 ' Slides are ordered horizontally, with the first slide in the upper-left corner and the second slide to the right of it.

' http://msdn.microsoft.com/en-us/library/office/ff744185.aspx
Const ppPrintOutputSlides = 1               ' Slides
Const ppPrintOutputTwoSlideHandouts = 2     ' Two Slide Handouts
Const ppPrintOutputThreeSlideHandouts = 3   ' Three Slide Handouts
Const ppPrintOutputSixSlideHandouts = 4     ' Six Slide Handouts
Const ppPrintOutputNotesPages = 5           ' Notes Pages
Const ppPrintOutputOutline = 6              ' Outline
Const ppPrintOutputBuildSlides = 7          ' Build Slides
Const ppPrintOutputFourSlideHandouts = 8    ' Four Slide Handouts
Const ppPrintOutputNineSlideHandouts = 9    ' Nine Slide Handouts
Const ppPrintOutputOneSlideHandouts = 10    ' Single Slide Handouts

' http://msdn.microsoft.com/en-us/library/office/ff745585.aspx
Const ppPrintAll = 1            ' Print all slides in the presentation.
Const ppPrintSelection = 2      ' Print a selection of slides.
Const ppPrintCurrent = 3        ' Print the current slide from the presentation.
Const ppPrintSlideRange = 4     ' Print a range of slides.
Const ppPrintNamedSlideShow = 5 ' Print a named slideshow.

' http://msdn.microsoft.com/en-us/library/office/ff744228.aspx
Const ppShowAll = 1             ' Show all.
Const ppShowNamedSlideShow = 3  ' Show named slideshow.
Const ppShowSlideRange = 2      ' Show slide range.

'
' This is the actual script
'

Dim inputFile
Dim outputFile
Dim objPPT
Dim objPresentation
Dim objPrintOptions
Dim objFso

If WScript.Arguments.Count <> 2 Then
    WriteLine "You need to specify input and output files."
    WScript.Quit
End If

inputFile = WScript.Arguments(0)
outputFile = WScript.Arguments(1)

Set objFso = CreateObject("Scripting.FileSystemObject")

If Not objFso.FileExists( inputFile ) Then
    WriteLine "Unable to find your input file " & inputFile
    WScript.Quit
End If

If objFso.FileExists( outputFile ) Then
    WriteLine "Your output file (" & outputFile & ") already exists!"
    WScript.Quit
End If

WriteLine "Input File:  " & inputFile
WriteLine "Output File: " & outputFile

Set objPPT = CreateObject( "PowerPoint.Application" )

objPPT.Visible = True
objPPT.Presentations.Open inputFile

Set objPresentation = objPPT.ActivePresentation
Set objPrintOptions = objPresentation.PrintOptions

objPrintOptions.Ranges.Add 1,objPresentation.Slides.Count
objPrintOptions.RangeType = ppShowAll

' Reference for this at http://msdn.microsoft.com/en-us/library/office/ff746080.aspx
objPresentation.ExportAsFixedFormat outputFile, ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputSlides, msoFalse, objPrintOptions.Ranges(1), ppPrintAll, "Slideshow Name", False, False, False, False, False

objPresentation.Close
ObjPPT.Quit

Sorry, I forgot the source. If you know it, let me know.

I used a portable version of ImageMagick and a portable version of GhostScript. You have to integrate GhostScript into ImageMagick in the file delegates.xml. Place GhostScript in ImageMagick folder and replace all appearances of gswin32c.exe with Ghostscript\bin\gswin32c.exe (if that is the path of your portable GhostScript).

Now just drag a ppt(x) file onto convertPowerpoint2JPG.bat and it creates a folder in the same directory where your ppt(x) resides and puts numbered JPGs in that folder.

You can download my example for trying it out yourself (Windows x64 version).

geöffnete Outlook PST Dateien sichern | how to backup open PST files

Es ist nicht ganz trivial PST Dateien zu sichern, die gerade bei Outlook geöffnet sind. Windows lässt das natürlich nicht zu, was auch Sinn macht in Bezug auf Datenkonsistenz und so weiter.
Nur was ist wenn auf Laptops immer Outlook geöffnet ist und allerhöchstens am Abend in den Standy Modus versetzt wird um dann am morgen weiter betrieben zu werden und niemals Outlook geschlossen wird? Also fallen Hilfswerkzeuge wie pfbackup weg. Dieses ermöglicht es bei schließen von Outlook die Sicherung der Dateien. Auch muss bei dem Tool die PST Dateien ausgewählt werden die gesichert werden sollen.

Das vorgestellte Skript sucht auf dem ganzen Laufwerk(en) nach PST Dateien und speichert diese in einen vorgegebenen Backup Ordner auf der eigenen Festplatte. In unserer Umgebung ist dies ein Truecrypt Container der immer als S: gemountet wird.
Um ein Backup von einer geöffneten Datei anzulegen ist es nötig eine Shadow Copy von der Festplatte anzulegen. Dies führt dazu, dass der aktuelle Stand gespeichert wird und ein kopieren möglich wird da die Datei dann nicht mehr mit einem lock versehen ist.
Als Hilfswerkzeug kommt vscsc und dosdev (in einem Microsoft Toolset enthalten) zum Einsatz.

In meinem Fall sind alle Dateien in C:\vscsc.
Diese wären:

  • dosdev.exe
  • vscsc.exe
  • findPST.vbs
  • script_c.bat
  • script_s.bat

dosdev.exe erlaubt einen so seltsame Windows Laufwerksnamen wie \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy15 auf ein Laufwerksbuchstaben zu mounten. Damit kann man dann auch in Skripten auf das Laufwerk zugreifen.

vscsc.exe erstellt die temporäre Shadow Copy vom Laufwerk. Ist das Skript durch verfällt die Shadow Copy.

findPST.vbs sucht alle PST Dateien auf dem Laufwerk das gerade als Shadow Copy existiert (Laufwerk B:) und kopiert diese ans Backupziel.

script_c.bat nimmt als Argument den Laufwerksnamen der Shadow Copy an und mountet es als Laufwerk B. Es ruft dann die findPST.vbs auf mit dem Laufwerksbuchstaben der Festplatte, die gerade also Shadow Copy vorliegt.
Man kann dem Skript leider keine Argumente übergeben, deswegen ein Skript für jedes Laufwerk.

Hier die Inhalte der Dateien. Denke diese sind selbsterklärend.

script_c.bat:

@echo off
DOSDEV B: %1
rem At this point B: is an immutable snapshot of C:, and you can copy from it.
rem You just need to write some stuff that actually copies data from B:
rem My favourite is rdiff-backup, but only robocopy can operate in backup mode
rem as a member of the Backup Operators group (/B switch), therefore bypassing
rem file permissions and security. This might be required sometimes.
rem .ost files are forbidden to appear in a snapshot
rem see HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToSnapshot
wscript findPST.vbs C:
DOSDEV /D B:

script_s.bat:

@echo off
DOSDEV B: %1
wscript findPST.vbs S:
DOSDEV /D B:

findPST.vbs:


laufwerksbuchstaben = WScript.Arguments.Item(0)
backupFolder = "S:\Secure Daten\Backup Outlook\"
backupFolderPart = "S:\Secure Daten"
strComputer = "."
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2")
QueryString = "Select * from CIM_DataFile Where Extension = 'pst' AND Drive = '" &amp; laufwerksbuchstaben &amp; "'"
'Wscript.Echo QueryString
Set re = New RegExp
Set re2 = New RegExp
With re
  .Pattern = ".*recycle.bin.*"
  .Global = True
  .IgnoreCase = True
End With 
With re2
  .Pattern = ".*S:\Secure Daten\Backup Outlook.*"
  .Global = True
  .IgnoreCase = True
End With 

Set colFiles = objWMIService.ExecQuery (QueryString)
  
' if there are no pst files found just exit the script
If colFiles.Count = 0 Then
    Wscript.Quit
End If
' if our secure drive is not mounted exit the script
If Not (objFSO.DriveExists("S:")) Then
  Wscript.Quit
End If

For Each objFile in colFiles
  filePathAndName = "B:" &amp; objFile.Path &amp; objFile.FileName &amp; "." &amp; objFile.Extension
  'filePathAndName = objFile.Drive &amp; objFile.Path &amp; objFile.FileName &amp; "." &amp; objFile.Extension
  'Wscript.Echo filePathAndName
  If Not re.Test(filePathAndName) And Not re2.Test(filePathAndName) Then ' check if pst is in recycle.bin or in backup folder
    ' create folders if they dont exist
    If Not (objFSO.FolderExists(backupFolderPart)) Then objFSO.CreateFolder(backupFolderPart)
    If Not (objFSO.FolderExists(backupFolder)) Then objFSO.CreateFolder(backupFolder)
    'Wscript.Echo "copy " &amp; filePathAndName &amp; " to " &amp; backupFolder
    objFSO.CopyFile filePathAndName , backupFolder, OverwriteExisting
  End If
'Wscript.Echo objFile.FileSize
Next

 

Um alle PST Dateien auf C: zu sichern wird der folgender Befehl ausgeführt:
vscsc.exe -exec=script_c.bat C:

Für Laufwerk S:
vscsc.exe -exec=script_s.bat S:

Nachtrag:
Ich wollte auch für das Laufwerk S: eine Shadow Copy anlegen. Es handelt sich dabei aber um ein Truecrypt Container und das ist von TrueCrypt nicht unterstützt. Ich zitiere aus der TrueCrypt „Known Issues & Limitations“:

The Windows Volume Shadow Copy Service is currently supported only for partitions within the key scope of active system encryption (e.g. a system partition encrypted by TrueCrypt, or a non-system partition located on a system drive encrypted by TrueCrypt, mounted when the encrypted operating system is running). Note: For other types of volumes, the Volume Shadow Copy Service is not supported because the documentation for the necessary API is not available.

Einen Drucker automatisiert installieren mit einem Batch Skript

Ich wusste lange nicht, wie ich einen Drucker TCP/IP Port automatisiert erstellen konnte aber bei einem nochmaligen googeln viel mir die Lösung mit den „printing admin scripts“ auf. Nach kurzem rumprobieren kam folgendes Skript dabei raus, dass 2 gleichartige Drucker die auf verschiedenen Etagen stehen einmal mit dem Postscript und das anderemal mit einem Generic PCL Treiber installiert. Damit wollen wir es den Usern einfacher machen S/W zu drucken, ohne beim Drucker was umstellen zu müssen.

<pre>@echo off

rem pcl
SET InfPath32="\\hostname\Canon iR Adv C5030i\iR5030Win7  PCL6\32BIT\Driver\pcl6\cnp60G.inf"
SET InfPath64="\\hostname\Canon iR Adv C5030i\iR5030Win7  PCL6\x64\Driver\pcl6\cnp60Ga64.inf"
rem postscript
SET InfPath32ps="\\hostname\Canon iR Adv C5030i\iR5030 Win7 PS\32BIT\Driver\CNS30G.INF"
SET InfPath64ps="\\hostname\Canon iR Adv C5030i\iR5030 Win7 PS\x64\Driver\CNS30GA64.INF"
SET PrnName3SW="Canon S/W 3. Stock"
SET PrnName6SW="Canon S/W 6. Stock"
SET PrnName3Farbe="Canon Farbe 3. Stock"
SET PrnName6Farbe="Canon Farbe 6. Stock"
SET PrnType="Canon iR-ADV C5030/5035 PS3"
SET PrnTypePCL="Canon Generic PCL6 Driver"
SET PortIP_3_Stock=192.168.xxx.xxx
SET PortIP_6_Stock=192.168.xxx.xxx

systeminfo | find "Windows 7"
if %ERRORLEVEL% == 0 goto Win7

systeminfo | find "Windows XP"
if %ERRORLEVEL% == 0 goto WinXP

:Win7
echo Running Windows 7 Script

rem check if 32 or 64 bit
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > C:\Windows\Temp\checkOS.txt
Find /i "x86" < C:\Windows\Temp\CheckOS.txt > C:\Windows\Temp\StringCheck.txt

If %ERRORLEVEL% == 0 (
    Echo "This is 32 Bit Win7"
  rem pcl 3 stock s/w
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows NT x86" -i %InfPath32%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName3SW% -m %PrnTypePCL% -r IP_"%PortIP_3_Stock%"

  rem pcl 6 stock s/w
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows NT x86" -i %InfPath32%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName6SW% -m %PrnTypePCL% -r IP_"%PortIP_6_Stock%"

  rem postscript 3 farbe
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows NT x86" -i %InfPath32ps%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName3Farbe% -m %PrnType% -r IP_"%PortIP_3_Stock%"

  rem postscript 6 farbe
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows NT x86" -i %InfPath32ps%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName6Farbe% -m %PrnType% -r IP_"%PortIP_6_Stock%"
  ) ELSE (
    Echo "This is 64 Bit Win7"
  rem pcl 3 stock s/w
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows x64" -i %InfPath64%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName3SW% -m %PrnTypePCL% -r IP_"%PortIP_3_Stock%"

  rem pcl 6 stock s/w
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows x64" -i %InfPath64%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName6SW% -m %PrnTypePCL% -r IP_"%PortIP_6_Stock%"

  rem postscript 3 farbe
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows x64" -i %InfPath64ps%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName3Farbe% -m %PrnType% -r IP_"%PortIP_3_Stock%"

  rem postscript 6 farbe
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows x64" -i %InfPath64ps%
  cscript C:\Windows\System32\Printing_Admin_Scripts\de-DE\prnmngr.vbs -a -p %PrnName6Farbe% -m %PrnType% -r IP_"%PortIP_6_Stock%")
goto exit

 

:WinXP
echo Running Windows XP Script

rem check if 32 or 64 bit
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > C:\Windows\Temp\checkOS.txt
Find /i "x86" < C:\Windows\Temp\CheckOS.txt > C:\Windows\Temp\StringCheck.txt

If %ERRORLEVEL% == 0 (
  Echo "This is 32 Bit WinXP"
  rem pcl 3 stock s/w
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows NT x86" -i %InfPath32%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName3SW% -m %PrnTypePCL% -r IP_"%PortIP_3_Stock%"

  rem pcl 6 stock s/w
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows NT x86" -i %InfPath32%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName6SW% -m %PrnTypePCL% -r IP_"%PortIP_6_Stock%"

  rem postscript 3 farbe
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows NT x86" -i %InfPath32ps%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName3Farbe% -m %PrnType% -r IP_"%PortIP_3_Stock%"

  rem postscript 6 farbe
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows NT x86" -i %InfPath32ps%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName6Farbe% -m %PrnType% -r IP_"%PortIP_6_Stock%"
  ) ELSE (
    Echo "This is 64 Bit WinXP"
  rem pcl 3 stock s/w
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows x64" -i %InfPath64%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName3SW% -m %PrnTypePCL% -r IP_"%PortIP_3_Stock%"

  rem pcl 6 stock s/w
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnTypePCL% -v 3 -e "Windows x64" -i %InfPath64%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName6SW% -m %PrnTypePCL% -r IP_"%PortIP_6_Stock%"

  rem postscript 3 farbe
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_3_Stock% -h %PortIP_3_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows x64" -i %InfPath64ps%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName3Farbe% -m %PrnType% -r IP_"%PortIP_3_Stock%"

  rem postscript 6 farbe
  cscript c:\windows\system32\prnport.vbs -a -r IP_%PortIP_6_Stock% -h %PortIP_6_Stock% -o RAW -n 9100
  cscript c:\windows\system32\prndrvr.vbs -a -m %PrnType% -v 3 -e "Windows x64" -i %InfPath64ps%
  cscript c:\windows\system32\prnmngr.vbs -a -p %PrnName6Farbe% -m %PrnType% -r IP_"%PortIP_6_Stock%"
  )
goto exit

:exit
pause</pre>

psexec workaround for installing msi packages to remote computers

Hatte einige Probleme eine msi Datei per psexec auf einen remote Rechner mit msiexec zu installieren.
Mein Befehl war „psexec.exe \\REMOTEHOST -u ADMIN -p ADMINPASSWORT -s -d msiexec /i \\APPHOST\FOLDER\7z922-x64.msi /q“. Der hat anscheinend die Datei nicht gefunden. Habe ich auf dem remote Rechner „msiexec /i \\APPHOST\FOLDER\7z922-x64.msi /q“ ausgeführt hat es aber funktioniert…

Nach langem hin und her war hab ich eine adäquate Alternative gefunden um das Problem zu umgehen. Ich mappe den Temp Ordner vom remote Rechner, kopiere die msi dort hinein und starte dann den obigen Befehl ohne UNC Pfad aber mit absoluten lokalen Pfad. Um es mir einfacher zu machen habe ich mir gleich eine batch Datei geschrieben (psexec muss im PATH sein…):

<pre>@echo off

set admin=Administrator
set passwd=
set hostname=%1
set absolutePathToFile=%2
set absolutePath=%3
set filename=%~n2
set filenameextension=%~x2

if %1!==! goto error5
if %2!==! goto error5
if %3!==! goto onefileprocessing

:folderprocessing
REM share einhängen
net use \\%hostname%\c$\Windows\Temp %passwd% /user:%admin%
if errorlevel 1 goto error1
REM gewuenschte datei auf den remote rechner kopieren
xcopy /H /E /Y %absolutePath% \\%hostname%\c$\Windows\Temp
if errorlevel 1 goto error2
REM installieren der software
psexec.exe \\%hostname% -u %admin% -p %passwd% msiexec /norestart /i C:\Windows\Temp\%filename%%filenameextension%
if errorlevel 1 goto error3
REM aushängen des shares
net use \\%hostname%\c$\Windows\Temp /d
if errorlevel 1 goto error4
REM deinstallieren von software würde so gehen
REM psexec.exe \\%hostname% -u %admin% -p %passwd% msiexec /x {61EF76AE-6CC9-4EFC-B788-6845C0BCEF00} /quiet
goto end

:onefileprocessing
REM share einhängen
net use \\%hostname%\c$\Windows\Temp %passwd% /user:%admin%
if errorlevel 1 goto error1
REM gewuenschte datei auf den remote rechner kopieren
xcopy /Y %absolutePathToFile% \\%hostname%\c$\Windows\Temp
if errorlevel 1 goto error2
REM installieren der software
psexec.exe \\%hostname% -u %admin% -p %passwd% msiexec /norestart /i C:\Windows\Temp\%filename%%filenameextension% /q
if errorlevel 1 goto error3
REM aushängen des shares
net use \\%hostname%\c$\Windows\Temp /d
if errorlevel 1 goto error4
REM deinstallieren von software würde so gehen
REM psexec.exe \\%hostname% -u %admin% -p %passwd% msiexec /x {61EF76AE-6CC9-4EFC-B788-6845C0BCEF00} /quiet

goto end
:error1
echo Fehler beim einhängen des remote ordners
:error2
echo Fehler beim kopieren auf remote machine
:error3
echo Fehler beim installieren der Software
:error4
echo Fehler beim aushängen des remote ordners
:error5
echo Bitte als ersten Parameter den Hostnamen angeben (z.B. REMOTEHOST) und als Zweiten den absoluten Pfad zur Datei die installiert werden soll (z.B. H:\apps\7z922-x64.msi)
echo In Ordnernamen duerfen keine Punkte sein...
:end</pre>

Musste noch ein drittes Argument mit aufnehmen damit ich eine Unterscheidung hab ob ich jetzt ein ganzes Verzeichnis kopieren muss oder nur eine Datei (z.B. bei der java, wo es jre1_6_0_27.msi und Data1.cab für die Installation braucht). Außerdem gabs Probleme wenn die Datei im Namen Punkte hatte. Er meinte nach dem Ersten Punkt, dass alles was danach kommt eine Dateiendung ist… also verwend ich keine Punkte im Dateinamen.

Das ganze schaut dann so aus wenn man es ausführt: