3

We have a program here that requires every user to have a shortcut on their desktop that points to an ini file. Each file is unique to the user. Recently, we've done a new install of the application on a separate server. I'd like to be able to run a script on the client computers that will look at the current shortcut, alter the server name, then save it to the same location.

I reckon powershell will be necessary for this. Something to the effect of:

$oldargs = # Pull out the args from the current shortcut using voodoo magic
$args = $oldargs -replace "server1", "server2"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\app.lnk")
$Shortcut.TargetPath = "%ProgramFiles%\appdir\app.exe"
$Shortcut.Arguments = "$args"
$Shortcut.WorkingDirectory = "%ProgramFiles%\appdir"
$Shortcut.IconLocation = "%ProgramFiles%\appdir\pic.ico"
$Shortcut.Save()

Really, I'm just lost on how I pull out the arguments from the current shortcut arguments.

4

How about:

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\oldapp.lnk")
$oldargs = $Shortcut.Arguments
$Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\newapp.lnk")
$Shortcut.TargetPath = "%ProgramFiles%\appdir\app.exe"
$Shortcut.Arguments = $oldargs -replace "server1", "server2"
$Shortcut.WorkingDirectory = "%ProgramFiles%\appdir"
$Shortcut.IconLocation = "%ProgramFiles%\appdir\pic.ico"
$Shortcut.Save()
| improve this answer | |
  • It's very close. Playing with it, hang on. – Justin Feb 7 '14 at 19:45
  • $oldargs is coming in as a blank var – Justin Feb 7 '14 at 19:51
  • tried $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\oldapp.lnk") $oldargs = $Shortcut.Arguments echo $oldargs – Justin Feb 7 '14 at 19:55
  • It's working for me and a .LNK file I made w/ Explorer on Windows 7 Professional x86. – Evan Anderson Feb 7 '14 at 19:56
  • Working with W8, x64. Looking at it, I don't see a reason this shouldn't work though. – Justin Feb 7 '14 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.