Reputation: 179
Hey Can any one tell me how to open power point and play slide show
I have the following code but it isnt working
$ppAdvanceOnTime = 2
$ppShowTypeKiosk = 3
$ppSlideShowDone = 5
Add-type -AssemblyName office
$Application = New-Object -ComObject powerpoint.application
$application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$path = "C:\Users\asuribha\Desktop\Web.pptx"
$presentation = $application.Presentations.open($path)
$presentation.SlideShowSettings.AdvanceMode = $ppAdvanceOnTime
$presentation.SlideShowSettings.ShowType = $ppShowTypeKiosk
$presentation.SlideShowSettings.StartingSlide = 1
$presentation.SlideShowSettings.EndingSlide = $presentation.Slides.Count
Do
{
$presenatation.SlideShowSettings.Run.View.
if (Err<>0)
{
Exit Do
}
}
until ($presenatation.SlideShowSettings.Run.View.State = $ppSlideShowDone)
$application.quit()
[gc]::collect()
[gc]::WaitForPendingFinalizers()
This code opens power point but doesnt play the slide show !!! I also have a problem with this it sometimes automatically closes the power point. Please Help me out with this
Upvotes: 5
Views: 17945
Reputation: 41
I have troubled with alot of the above from various sites and eventually found this to be the quickest and got no problems even if powerpoint wasn't running the machine it was still able to carry on. I basically wanted to run a script the receptionist could input details without any complications just an input box then on finishing it would run another powershell on the presentation screen.
here's the receptionist input powershell input.
Add-Type -AssemblyName Microsoft.VisualBasic
$PPTFile = [Microsoft.VisualBasic.Interaction]::InputBox('Enter FileName', 'Powerpoint File', "$env")
$pptx = "d:\Presentations"+($pptfile)+".pptx"
$pptx | Out-File "\\(machine name)\Scripts\Powerpoint.txt"
I can probably simplify it more later with remote run the powershell but at present as a powershell newbie I run the other script at the other end and all running fine.
Stop-Process -name "POWERPNT"
$Power = Get-Content "d:\Scripts\Powerpoint.txt"
write-output $Power
$powerptx = "/s "+($Power)
start-process powerpnt.exe -ArgumentList "$powerptx"
Upvotes: 4
Reputation: 1015
So I'm not a very big fan of powershell, but I use this script to rotate presentations on a monitor we have:
$ppt = "c:\presentation.pptx"
$new_file = "c:\new.pptx"
function runloop {
$running = get-process POWERPNT
$killed = $false
if (Test-Path $new_file) {
Write-Host "Killing"
kill -name POWERPNT
Start-Sleep -s 2
Move-Item $new_file $ppt -force
$killed = $true
}
if (!$running -or $killed) {
Write-Host "Not running"
$app = New-Object -ComObject powerpoint.application
$pres = $app.Presentations.open($ppt)
$app.visible = "msoTrue"
$pres.SlideShowSettings.Run()
$pres.visible = "msoTrue"
}
Write-Host "Done"
}
runloop;
Hacky, but it works for me. Hope this helps.
Upvotes: 1