Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. function Set-Shortcut($ShortcutPath, $Target)
  2. {
  3. $WshShell = New-Object -ComObject WScript.Shell
  4. $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
  5. $Shortcut.TargetPath = $target
  6. $Shortcut.Save()
  7. }
  8.  
  9. function Get-Target($ShortcutPath)
  10. {
  11. $WshShell = New-Object -ComObject WScript.Shell
  12. $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
  13. return $Shortcut.TargetPath
  14. }
  15.  
  16. Describe 'TargetPath' {
  17.  
  18. BeforeAll {
  19. $ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk'
  20. $TargetPath = 'C:\Windows\System32\notepad.exe'
  21.  
  22. Set-Shortcut -ShortcutPath $ShortcutPath -TargetPath $TargetPath
  23. }
  24.  
  25. Context 'ProviderPath' {
  26. It 'Exists' {
  27. $ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk'
  28. Test-Path -Path $ShortcutPath | Should Be $true
  29. }
  30.  
  31. It 'Has the correct targetPath' {
  32. $ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk'
  33. $TargetPath = 'C:\Windows\System32\notepad.exe'
  34. Get-Target -ShortcutPath $ShortcutPath | Should Be $TargetPath
  35. }
  36. }
  37.  
  38. Context 'TestDrive' {
  39. It 'Exists' {
  40. $ShortcutPath = 'TestDrive:\Notepad.lnk'
  41. Test-Path -Path $ShortcutPath | Should Be $true
  42. }
  43.  
  44. It 'Has the correct targetPath' {
  45. $ShortcutPath = 'TestDrive:\Notepad.lnk'
  46. $TargetPath = 'C:\Windows\System32\notepad.exe'
  47. Get-Target -ShortcutPath $ShortcutPath | Should Be $TargetPath
  48. }
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement