|
| 1 | +# |
| 2 | +# $Product --> "Visual PLB 10.8" |
| 3 | +# $ShortcutName --> "Visual PLB" |
| 4 | +# $Workingdir --> "c:\Sunbelt\plbwin.108\code" |
| 5 | +# $Target --> "c:\Sunbelt\plbwin.108\code\plbwin.exe" |
| 6 | +# $Plcarg --> " -h c:\Sunbelt\plbwin.108\code\watch.plc" |
| 7 | +# $Showlog --> "on" optional |
| 8 | +# |
| 9 | +# .\makeonelink.ps1 "Visual PLB 10.8" "Visual PLB" "c:\Sunbelt\plbwinX.108\code" "c:\Sunbelt\plbwin.108\code\plbwin.exe" |
| 10 | +# .\makeonelink.ps1 "Visual PLB 10.8" "Visual PLB" "c:\Sunbelt\plbwinX.108\code" "c:\Sunbelt\plbwin.108\code\plbwin.exe" " -h c:\Sunbelt\plbwin.108\code\watch.plc" |
| 11 | +# |
| 12 | +# Test Command line Sample: |
| 13 | +# |
| 14 | +# $Product --> "Visual PLB 10.8" |
| 15 | +# $ShortcutName --> "Test_Notepad" |
| 16 | +# $Workingdir --> "C:\Windows\System32" |
| 17 | +# $Target --> "notepad.exe" |
| 18 | +# $Plcarg --> empty/not used |
| 19 | +# $Showlog --> "on" optional |
| 20 | +# |
| 21 | +# .\makeonelink.ps1 "Visual PLB 10.8" "Test_Notepad" "C:\Windows\System32" "notepad.exe" |
| 22 | +# |
| 23 | +param ( $Product, $ShortcutName, $Workingdir, $Target, $Plcarg, $Showlog ) |
| 24 | + |
| 25 | +# Create WScript.Shell COM object |
| 26 | +$WshShell = New-Object -ComObject WScript.Shell |
| 27 | + |
| 28 | +# |
| 29 | +# Show Input parameters |
| 30 | +# |
| 31 | +if ( $Showlog -eq "on" ) { |
| 32 | +Write-Host "*****************************" |
| 33 | +Write-Host "Product: '$Product'" |
| 34 | +Write-Host "ShortcutName: '$ShortcutName'" |
| 35 | +Write-Host "Workingdir: '$Workingdir'" |
| 36 | +Write-Host "Target: '$Target'" |
| 37 | +Write-Host "Plcarg: '$Plcarg'" |
| 38 | +Write-Host "Showlog: '$Showlog'" |
| 39 | +} |
| 40 | + |
| 41 | +# Make Desktop Directory |
| 42 | +# |
| 43 | + $Path = "$env:USERPROFILE\Desktop\$Product" |
| 44 | + if ( Test-Path $Path -PathType Container ) { |
| 45 | + if ( $Showlog -eq "on" ) { |
| 46 | + Write-Host "Directory exist: '$Path'!" |
| 47 | + } |
| 48 | + } else { |
| 49 | + mkdir $Path |
| 50 | + if ( $Showlog -eq "on" ) { |
| 51 | + Write-Host "Created Directory '$Path'!" |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | +# Define the shortcut path |
| 56 | +$ShortcutPath = "$env:USERPROFILE\Desktop\$Product\$ShortcutName.lnk" |
| 57 | + |
| 58 | +# Create the shortcut object |
| 59 | +$Shortcut = $WshShell.CreateShortcut($ShortcutPath) |
| 60 | + |
| 61 | +# Set the target path (the program or file to run) |
| 62 | +$Shortcut.TargetPath = "$Target" |
| 63 | +$Shortcut.Arguments = "$Plcarg" |
| 64 | + |
| 65 | +# (Optional) Set other shortcut properties |
| 66 | +$Shortcut.WorkingDirectory = "$Workingdir" |
| 67 | +$Shortcut.WindowStyle = 1 # 1 = Normal, 3 = Maximized, 7 = Minimized |
| 68 | +$Shortcut.Description = "Launch '$ShortcutName'" |
| 69 | +$Shortcut.IconLocation = "$Target,0" |
| 70 | + |
| 71 | +# Save the shortcut to the desktop |
| 72 | +$Shortcut.Save() |
| 73 | +# |
| 74 | +# End |
| 75 | +# |
0 commit comments