By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

determining current version of PowerPoint

P: n/a
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?

My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer

MyDate = Today
DayOfWeek = Weekday(MyDate)

' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub

Thanks for any advise!
George Atkins

Jun 27 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?

My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer

MyDate = Today
DayOfWeek = Weekday(MyDate)

' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub

Thanks for any advise!
George Atkins

Jun 29 '07 #2

P: n/a
Sorry that I missed your post; I forgot to mark the Notify box and work has
kept me busy. I'll try this out when I get back to work, first thing. Thanks
a whole lot for the solution.
george atkins

"Newbie Coder" wrote:
George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?

My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer

MyDate = Today
DayOfWeek = Weekday(MyDate)

' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub

Thanks for any advise!
George Atkins


Jul 2 '07 #3

P: n/a
Thanks for the code. When I tried to run it, I received the following
"warning" that prevents the code from running or compiling:

"Warning 1 Function 'GetPowerPointPath' doesn't return a value on all code
paths. A null reference exception could occur at run time when the result is
used."

I'm running a standard installation of PowerPoint 2007 on an XP SP2 machine.
Do you have any troubleshooting advise? I checked for the path in the
Registry and it is correct.

George

"Newbie Coder" wrote:
George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?

My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer

MyDate = Today
DayOfWeek = Weekday(MyDate)

' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub

Thanks for any advise!
George Atkins


Jul 12 '07 #4

P: n/a
Well, I think I may have an inkling of the problem.
The function that determines the PPT path, returns the following string:
"C:\PROGRA~1\MICROS~2\Office12\POWERPNT.EXE"

Why Microsoft records these old-fashioned, truncated names is beyond me. But
I believe the ~1 and ~2 syntax is what is causing the problem. I could edit
the syntax, but as I'm going to run this on other machines, this is not a
good solution.

I revised the code to show: reg.GetValue("Path", ""). This returns a valid,
full path, but the code continues to fail with the warning previously
reported.

Any other ideas?
George

"Newbie Coder" wrote:
George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?

My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer

MyDate = Today
DayOfWeek = Weekday(MyDate)

' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() & "\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub

Thanks for any advise!
George Atkins


Jul 12 '07 #5

P: n/a
George,

In my original code I wrote:

GetValue("", "")

This gets the default value & if doesn't exist returns "". You can change the
second "" to the default path to MS Powerpoint, which will stop the error

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:7C**********************************@microsof t.com...
Thanks for the code. When I tried to run it, I received the following
"warning" that prevents the code from running or compiling:

"Warning 1 Function 'GetPowerPointPath' doesn't return a value on all code
paths. A null reference exception could occur at run time when the result is
used."

I'm running a standard installation of PowerPoint 2007 on an XP SP2 machine.
Do you have any troubleshooting advise? I checked for the path in the
Registry and it is correct.

George

"Newbie Coder" wrote:
George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up
for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?
>
My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer
>
MyDate = Today
DayOfWeek = Weekday(MyDate)
>
' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub
>
Thanks for any advise!
George Atkins
>

Jul 13 '07 #6

P: n/a
George,

' Import
Imports System.IO

To get the Long Path Name use this function:

Public Shared Function GetLongPath(ByVal path As String) As String
Dim root As String = System.IO.Path.GetPathRoot(path)
Dim folders As String() = path.Substring(root.Length). _
Split(System.IO.Path.DirectorySeparatorChar)
Dim res As String = root
Dim name As String
For Each name In folders
Dim di = New DirectoryInfo(res)
Dim fsi As System.IO.FileSystemInfo() = _
di.GetFileSystemInfos(name)
If fsi.Length = 1 Then
res = fsi(0).FullName
Else
' Error handling here
End If
Next
Return res
End Function

The above isn't my function but it works fine

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:97**********************************@microsof t.com...
Well, I think I may have an inkling of the problem.
The function that determines the PPT path, returns the following string:
"C:\PROGRA~1\MICROS~2\Office12\POWERPNT.EXE"

Why Microsoft records these old-fashioned, truncated names is beyond me. But
I believe the ~1 and ~2 syntax is what is causing the problem. I could edit
the syntax, but as I'm going to run this on other machines, this is not a
good solution.

I revised the code to show: reg.GetValue("Path", ""). This returns a valid,
full path, but the code continues to fail with the warning previously
reported.

Any other ideas?
George

"Newbie Coder" wrote:
George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up
for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?
>
My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer
>
MyDate = Today
DayOfWeek = Weekday(MyDate)
>
' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub
>
Thanks for any advise!
George Atkins
>

Jul 13 '07 #7

P: n/a
Thanks much for both tips. I'll plug this in. Have a nice weekend!
George

"Newbie Coder" wrote:
George,

' Import
Imports System.IO

To get the Long Path Name use this function:

Public Shared Function GetLongPath(ByVal path As String) As String
Dim root As String = System.IO.Path.GetPathRoot(path)
Dim folders As String() = path.Substring(root.Length). _
Split(System.IO.Path.DirectorySeparatorChar)
Dim res As String = root
Dim name As String
For Each name In folders
Dim di = New DirectoryInfo(res)
Dim fsi As System.IO.FileSystemInfo() = _
di.GetFileSystemInfos(name)
If fsi.Length = 1 Then
res = fsi(0).FullName
Else
' Error handling here
End If
Next
Return res
End Function

The above isn't my function but it works fine

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:97**********************************@microsof t.com...
Well, I think I may have an inkling of the problem.
The function that determines the PPT path, returns the following string:
"C:\PROGRA~1\MICROS~2\Office12\POWERPNT.EXE"

Why Microsoft records these old-fashioned, truncated names is beyond me. But
I believe the ~1 and ~2 syntax is what is causing the problem. I could edit
the syntax, but as I'm going to run this on other machines, this is not a
good solution.

I revised the code to show: reg.GetValue("Path", ""). This returns a valid,
full path, but the code continues to fail with the warning previously
reported.

Any other ideas?
George

"Newbie Coder" wrote:
George,
>
Here's a way to do it:
>
Imports Microsoft.Win32
Imports System.Diagnostics.Process
>
#Region "Get PowerPoint Path"
>
Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
>
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function
>
#End Region
>
#Region "Get Day Of Week"
>
Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function
>
#End Region
>
#Region "Run PowerPoint Presentation"
>
Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub
>
I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in
>
Hope this helps,
>
--
Newbie Coder
(It's just a name)
>
>
>
"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up
for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?

My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer

MyDate = Today
DayOfWeek = Weekday(MyDate)

' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub

Thanks for any advise!
George Atkins

>
>
>


Jul 13 '07 #8

P: n/a
George,

Have a great weekend too

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:D2**********************************@microsof t.com...
Thanks much for both tips. I'll plug this in. Have a nice weekend!
George

"Newbie Coder" wrote:
George,

' Import
Imports System.IO

To get the Long Path Name use this function:

Public Shared Function GetLongPath(ByVal path As String) As String
Dim root As String = System.IO.Path.GetPathRoot(path)
Dim folders As String() = path.Substring(root.Length). _
Split(System.IO.Path.DirectorySeparatorChar)
Dim res As String = root
Dim name As String
For Each name In folders
Dim di = New DirectoryInfo(res)
Dim fsi As System.IO.FileSystemInfo() = _
di.GetFileSystemInfos(name)
If fsi.Length = 1 Then
res = fsi(0).FullName
Else
' Error handling here
End If
Next
Return res
End Function

The above isn't my function but it works fine

--
Newbie Coder
(It's just a name)

"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:97**********************************@microsof t.com...
Well, I think I may have an inkling of the problem.
The function that determines the PPT path, returns the following string:
"C:\PROGRA~1\MICROS~2\Office12\POWERPNT.EXE"
>
Why Microsoft records these old-fashioned, truncated names is beyond me.
But
I believe the ~1 and ~2 syntax is what is causing the problem. I could
edit
the syntax, but as I'm going to run this on other machines, this is not a
good solution.
>
I revised the code to show: reg.GetValue("Path", ""). This returns a
valid,
full path, but the code continues to fail with the warning previously
reported.
>
Any other ideas?
George
>
>
>
"Newbie Coder" wrote:
>
George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microso ft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,

--
Newbie Coder
(It's just a name)



"GeorgeAtkins" <Ge**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Greetings!
I wrote a small Exe that simply runs Shell to load PowerPoint and
launch a
particular file, depending on the day of the week. However, it was set
up
for
office 2003 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?
>
My current, ineffecient code:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer
>
MyDate = Today
DayOfWeek = Weekday(MyDate)
>
' Launch the powerpoint file for the current day of the
week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub
>
Thanks for any advise!
George Atkins
>


Jul 13 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.