Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Set-Shortcut($ShortcutPath, $Target)
- {
- $WshShell = New-Object -ComObject WScript.Shell
- $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
- $Shortcut.TargetPath = $target
- $Shortcut.Save()
- }
- function Get-Target($ShortcutPath)
- {
- $WshShell = New-Object -ComObject WScript.Shell
- $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
- return $Shortcut.TargetPath
- }
- Describe 'TargetPath' {
- BeforeAll {
- $ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk'
- $TargetPath = 'C:\Windows\System32\notepad.exe'
- Set-Shortcut -ShortcutPath $ShortcutPath -TargetPath $TargetPath
- }
- Context 'ProviderPath' {
- It 'Exists' {
- $ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk'
- Test-Path -Path $ShortcutPath | Should Be $true
- }
- It 'Has the correct targetPath' {
- $ShortcutPath = Join-Path (resolve-path 'TestDrive:\').ProviderPath 'Notepad.lnk'
- $TargetPath = 'C:\Windows\System32\notepad.exe'
- Get-Target -ShortcutPath $ShortcutPath | Should Be $TargetPath
- }
- }
- Context 'TestDrive' {
- It 'Exists' {
- $ShortcutPath = 'TestDrive:\Notepad.lnk'
- Test-Path -Path $ShortcutPath | Should Be $true
- }
- It 'Has the correct targetPath' {
- $ShortcutPath = 'TestDrive:\Notepad.lnk'
- $TargetPath = 'C:\Windows\System32\notepad.exe'
- Get-Target -ShortcutPath $ShortcutPath | Should Be $TargetPath
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement