Pregunta

I am trying to generate a shortcut for every printer I have on a print server. The idea is to be able to email these shortcuts to people and when they click on them, it automatically installs that printer for them.

I've populated an array from a list of printer names exported from the print server:

$list = @((get-contnet $home\dekstop\plist.txt))

I then created a method to create a shortcut:

function Make-Shortcut
{
param ([string]$dest, [string]$source)
$WshShell = New-Object -comObject Wscript.Shell
$Shortcut = $WshShell.CreateShortcut($dest)
$Shortcut.TargetPath = $Source
$Shortcut.Save()
}

The function works fine. I was able to create standard shortcuts with no problem.

This next part is where I am getting stuck:

foreach ($i in $list)
{
Make-Shortcut "C:\pshort\$i.lnk" "C:\Windows\System32\rundll32.exe 
printui.dll,PrintUIEntry /in /q /n\\printserver\$i"
}

When this runs, it does generate a shortcut with the same name as the printer for each printer on the list. However, the problem comes in at the target path. Instead of

C:\Windows\System32\rundll32.exe printui.dll,PrintUIEntry /in /q /n\\printserver\printername

it changes it to:

C:\Windows\System32\rundll32.exe printui.dll,PrintUIEntry \in \q \n\printserver\printername

The three problems with this are:

  1. It is reversing the forward slash for the parameters
  2. It is removing one of the backslashes preceding the server name
  3. It is adding quotes to both sides. I need the quotes to come off for the shortcut to work properly.

I assume this is happening because Powershell thinks I am trying to make a standard shortcut and thinks I made mistakes while typing out the path.

I have tried putting a ` in front of each forward slash hoping the escape character would prevent it from reversing it, but no luck. I also tried using a hyphen for each parameter but that did not work either.

Is there anyway to stop this from happening? Or is there perhaps a better way to try to accomplish what I am trying to do?

¿Fue útil?

Solución

You need to add arguments to the com object

Try adding a new param $arguments to your Make-Shortcut function and do:

Make-Shortcut "C:\pshort\$i.lnk" "C:\Windows\System32\rundll32.exe" 
"printui.dll,PrintUIEntry /in /q /n\\printserver\$i"

add this in your function:

$Shortcut.Arguments = $arguments

So the link is created successfully ... but I have no idea if it works :)

Otros consejos

Completely different answer but in a standard windows environment simply clicking a hyperlink to \printserver\printer will add a shared printer to someone's system?

So an email that simply lists :

\\PrintServer\Printer01
\\PrintServer\Printer02
\\PrintServer\Printer03

Would probably do the job just as well.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top