Archiv der Kategorie: IT

PowerShell Outlook Scripting

This small PowerShell example opens my Outlook and searches for a inbox folder called „Planungen“.
It’s going through all mail and processes them if they have special keywords in them like Planung and KAR. If there are keywords like NB or Nachberechnung it’s not processed. Then it saves the attachment to a temporary Directory and uses pscp to copy it over to a linux machine. It uses my Windows kerberos key to authenticate via GSSAPI so I don’t need a RSA Key or password. It’s executed each day as a scheduled job. Neat, isn’t it?

$filepath = "C:\temp\"
$date = get-date -format d
$time = get-date -format h-mm
$log = "C:\Temp\Logs\parameterpflege_" + $date + "_" + $time + ".log"

$olFolderInbox = 6 
$outlook = new-object -com outlook.application; 
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox)
$planungsordner=$inbox.Folders | where-object { $ -eq "Planungen" }
$messages = $planungsordner.items 

foreach($message in $messages){
  If ($message.subject -match ".*Planung.*" -And $message.subject -match ".*KAR.*" -And $message.UnRead -eq "$true" -And (!($message.subject -match ".*NB.*" -Or $message.subject -match ".*Nachberechnung.*"))) {
    Start-Transcript -Force -Path $log
    write-host "bearbeite Mail ""$subject"""
    # save attachment
    $message.attachments|foreach {
      $attachmentname = $_.filename
      If ($attachmentname.Contains("doc")) {
        Write-Host "save $attachmentname to $filepath"
        $_.saveasfile((Join-Path $filepath $attachmentname)) 
    # mark as read so it's not gonna processed again
    $message.UnRead = $false
    $docfile = "$filepath" + $attachmentname
    Write-Host "kopiere $docfile nach $linux_user@$linux_path"
    &$pscp_path $docfile $linux_user@$linux_path

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

Const msoFalse = 0   ' False.
Const msoTrue = -1   ' True.

Const ppFixedFormatIntentScreen = 1 ' Intent is to view exported file on screen.
Const ppFixedFormatIntentPrint = 2  ' Intent is to print exported file.

Const ppFixedFormatTypeXPS = 1  ' XPS format
Const ppFixedFormatTypePDF = 2  ' PDF format

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.

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

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.

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."
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
End If

If objFso.FileExists( outputFile ) Then
    WriteLine "Your output file (" & outputFile & ") already exists!"
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
objPresentation.ExportAsFixedFormat outputFile, ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputSlides, msoFalse, objPrintOptions.Ranges(1), ppPrintAll, "Slideshow Name", False, False, False, False, False


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).

get WebLogic working with Apache as reverse proxy (mod_proxy)

There is Oracle Reports running on a WebLogic Server. I want it to run on https but for some reason I don’t know it wasn’t working for the Internet Explorer 11 (and maybe other versions too). IE11 just timed out and never displayed any html nor could be establish a connection. It worked with Chrome and Firefox.
As a fast workaround I thought, lets install a Apache and make the ssl stuff there and proxy it to the WebLogic http listening address. Both WebLogic and Apache are on the same machine, so no problem with using the http port.

With the usual Apache config for mod_proxy:

ProxyPass /reports http://somedomain.tld:7002/reports
ProxyPassReverse /reports http://somedomain.tld:7002/reports

Those lines weren’t enough because I could still see links to http://somedomain.tld:7002/reports* embedded within the html code.
With enabling additional options and rewriting html I thought it could be managed:

SetOutputFilter proxy-html
ProxyHTMLEnable On
ProxyHTMLExtended On
ProxyHTMLURLMap http://somedomain.tld:7002/reports https://somedomain.tld/reports

Most of the links worked now but there were still pages not displaying correctly. Those pages just had

&lt;base href="https://somedomain.tld/reports/rwservlet/getfile/HW-NW8428FX-mIL4832KDA-==/0jsdfUjid.htm"&gt;

in it.

Without the Apache proxy it was something like:

&lt;base href="http://somedomain.tld:7002/reports/rwservlet/getfile/HW-NW8428FX-mIL4832KDA-==/0jsdfUjid.htm"&gt;

whole page content

After googling I finally found a solution… Simple tell WebLogic that there is a proxy in front of it 🙂
In short:

  • enable „WebLogic Plug-In Enabled“ in Domain Structure > Environment > Servers > managed01 > Configuration General > Advanced
  • write in your hostname in „Frontend Host:“ and set your https port in „Frontend HTTPS Port:“ Domain Structure > Environment > Servers > managed01 > Protocols > HTTP
  • save changes and restart WebLogic
  • set an additional header within your Apache config: RequestHeader set WL-Proxy-SSL true
  • restart Apache
  • it should work now 🙂

How to import your SMS from Android to Jolla

I found a quite nice tutorial online that explains all the steps you have to take to do the job.
I couldn’t copy the mmssms.db database like he was doing it.
I had to change to a root shell on my android and copy it to somewhere else on the filesystem and give it other permissions to get it to my machine.
The only thing I „improved“ is the shell one liner (see below) export from the sqlite mmssms.db that marks the newlines in sms the correct way so the tool Harmattan-SMS-Boat can make its job just fine.

sqlite3 "$1" \
"select address,type,datetime(date/1000, 'unixepoch','localtime'),datetime(date/1000, 'unixepoch','localtime'),body from sms;" | \
sed -e 's;^\([^|]\+\)|1|\(.*\);\1|IN|\2;' -e 's;^\([^|]\+\)|2|\(.*\);\1|OUT|\2;' -e '/^[A-Za-z0-9+]*|[IN|OUT]/! s;^; ;' | \
sed 's/|/;/g'

flash alternative for streaming sites -> ViewTubePlus

If you don’t like the performance impact that flash causes or you simply can’t use the flash plugin for some reason there is a chance you can still watch your loved videos on several streaming sites.
It is a greasemonkey userscript that searches for the video and replaces the flash player with a custom player where you can play the video with the browser internal html5 video player or a video plugin like the one from vlc player.
Currently those sites are supported:

Currently the script adds ViewTube support for:


It is some kind of a standalone addition to ViewTube. Just that this script is for some more websites.

That’s how a video on xtube looks with the totem video plugin for firefox:

If you want a specific site supported, you can say it in the comments and/or provide the code for it 🙂

In general I recommend the totem video player on *nix systems or HTML5 on all systems, because it caches the video on disk and you can let it puffer. The vlc plugin just puffers for about some seconds and then stops downloading the file any further.

– In conjunction with noscript it’s not working that well because some pornsites have different domains/IPs for videos and you have to allow javascript access to them as well in order to make it work.
– I experience difficulties with VLC Media Player Plugin with Windows 7 and Linux. It wants to load the full movie/video before it wants to play it. So it’s not really streaming. At least for Linux I can recommend the Totem Plugin.

See the readme for the original tool on which plugins to use and what browsers are supported etcetera:

# 2016-08-05  – fixed xtube, xvideos
# 2016-02-23 – quickfix xtube, fixed ashemaletube
# 2015-12-15 – changed xhamster regex
# 2015-09-12 – refix redtube
# 2015-09-09 – added support for zdf Mediathek
# 2015-09-08 – fixed redtube
# 2015-08-12 – fixed xhamster
# 2015-08-03 – fixed pornhub
# 2015-07-16 – changing xtube code
# 2015-07-15 – adding subdomains for pronhub, youporn(gay), tube8
# 2015-07-07 – fucked up regex for xvideos 😉
# 2015-07-06 – fixing gaytube, adding subdomains for xvideos
# 2015-06-29 – fixed gaytube
# 2015-06-24 – changed youporn code to not use xmlhttprequest in order to work with EasyLists blocking rules
# 2015-06-08 – fixed veehd
# 2015-05-20 – fixed, tube8, pornhub, youporn
# 2015-04-22 – fixed language specific tube8 domains
# 2015-03-03 – fixed tube8
# 2015-02-14 – fixed xhamster
# 2015-02-08 – fixed redtube, tube8
# 2015-02-07 – refixed veehd
# 2015-02-06 – fixed veehd, flashx
# 2015-02-02 – fixed hornoxe, fast(stream|video), pornhub
# 2015-01-22 – fixed pornhub
# 2015-01-20 – divxstage top level domain added
# 2015-01-19 – fixed nowvideo, novamov
# 2014-11-07 – fixed youporn, pornhub, redtube, tube8
# 2014-06-27 – fixed pornhub code

Bundestag rtmp

Merke für das nächste Mal…:
rtmpdump -r "rtmp://" -a "13014bundestag" -y "mp4:ondemand/3777parlamentsfernsehen/archiv/app144277506/145293313/2418549/2418549_h264_720_400_2000kb_baseline_de_2192.mp4" -o "Redebeitrag von Dr. Matthias Zimmer (CDU_CSU) am 06.06.2013 um 17:04 Uhr (243. Sitzung, TOP 7).mp4"

Packard Bell EasyNote TK85 backlight bei Linux

Falls die Hintergrundbeleuchtung nicht mit den Funktionstasten geändert werden kann ist möglicherweise ein kleine Änderung an einer grub Datei schon des Rätsels Lösung.
Im Forum hat ein User folgenden Vorschlag gemacht:

Bei mir hat folgendes geholfen:

Option "RegistryDwords" "EnableBrightnessControl=1"

In der

Section "Device"

in der /etc/X11/xorg.con einfügen. Ansonsten noch


in deiner /etc/default/grub beim Punkt


hinzufügen 😉


Zusätzlich zu acpi_osi=Linux habe ich noch die Option acpi_backlight=vendor dazugenommen.

Die Änderung in der xorg.conf war überflüssig und habe ich wieder entfernt… Übrigens auf einem Ubuntu 13.10.

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.


@echo off
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:


@echo off
wscript findPST.vbs S:


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:\\" & strComputer & "\root\cimv2")
QueryString = "Select * from CIM_DataFile Where Extension = 'pst' AND Drive = '" & laufwerksbuchstaben & "'"
'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
End If
' if our secure drive is not mounted exit the script
If Not (objFSO.DriveExists("S:")) Then
End If

For Each objFile in colFiles
  filePathAndName = "B:" & objFile.Path & objFile.FileName & "." & objFile.Extension
  'filePathAndName = objFile.Drive & objFile.Path & objFile.FileName & "." & 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 " & filePathAndName & " to " & backupFolder
    objFSO.CopyFile filePathAndName , backupFolder, OverwriteExisting
  End If
'Wscript.Echo objFile.FileSize

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:

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.