Any ideas why I can't for the life of me get any code samples of any code
whether VB or dos commands using rundll32, to remotely set a default printer
on a Windows XP computer. I am using the code below:

strComputer = "remotecomputername"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'PrinterName'")

For Each objPrinter in colInstalledPrinters
objPrinter.SetDefaultPrinter()
Next

but it simply executes silently and does NOT set the default printer on the
remote machine. The values are not updated in this sample to show actual
computer or printer names. All the samples I find on this function execute,
but do not perform the required action on the remote PC. They work perfectly
fine locally.

So I guess my question is this even a supported function of VB and WMI to
remotely set a default printer? Is this a limitation or by design issue
where you just can't do that? And if so, does anyone have any suggestions on
how to accomplish this. I am trying to script the deletion of local printers
from Windows XP machines, the installation of new printer server based
printer shares on Server 2003, and the selecting of a default printer. I
have everything else working, but can't for the life of me get anything I try
to remotely set a default printer.

any help is greatly appreciated.

Thanks

RE: VB to remotely set default printer by RemS

RemS
Thu Aug 30 14:44:01 PDT 2007

"ACE-Joe" wrote:

> Any ideas why I can't for the life of me get any code samples of any code
> whether VB or dos commands using rundll32, to remotely set a default printer
> on a Windows XP computer. I am using the code below:
>
> strComputer = "remotecomputername"
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colInstalledPrinters = objWMIService.ExecQuery _
> ("Select * from Win32_Printer Where Name = 'PrinterName'")
>
> For Each objPrinter in colInstalledPrinters
> objPrinter.SetDefaultPrinter()
> Next
>
> but it simply executes silently and does NOT set the default printer on the
> remote machine. The values are not updated in this sample to show actual
> computer or printer names. All the samples I find on this function execute,
> but do not perform the required action on the remote PC. They work perfectly
> fine locally.
>
> So I guess my question is this even a supported function of VB and WMI to
> remotely set a default printer? Is this a limitation or by design issue
> where you just can't do that? And if so, does anyone have any suggestions on
> how to accomplish this. I am trying to script the deletion of local printers
> from Windows XP machines, the installation of new printer server based
> printer shares on Server 2003, and the selecting of a default printer. I
> have everything else working, but can't for the life of me get anything I try
> to remotely set a default printer.
>
> any help is greatly appreciated.
>
> Thanks

Choosing a printer as the default printer is a user prefered setting.
These settings are saved in the HKEY_CURRENT_USER key in the registry (which
is a copy of the user's-SID-subkey in HKEY_USERS).

When you logged on remotely using other credentials as the user that is
currently logged on to the console, the user specific changes you make are
saved in an other userprofile on the computer (your profile on that
computer).

If you want to change the default printer remotely for the currently
logged-on user, You must do that by changing registry values in the
'HKEY_USERS' key in the SID-subkey of this user. This subkey is visible for
you because of the fact that the user is logged-on.

For accessing the right subkey, the script has to determine the SID of the
current logged-on user first.

see here an example how to add remotely a printer for the users and make it
his/her default printer *in realtime*.
http://www.petri.co.il/forums/showthread.php?p=61627#post61627

\Rems

RE: VB to remotely set default printer by ACEJoe

ACEJoe
Fri Aug 31 05:08:03 PDT 2007

Thank you! That is very helpful. My only stumbling block now is that I also
want to remove all local printers before installing the print server based
printers. My problem is that I have computers which have the adobe printer
installed for creating PDF files. So it also removes these! I'm so close!
Thanks again!

"\RemS" wrote:

> "ACE-Joe" wrote:
>
> > Any ideas why I can't for the life of me get any code samples of any code
> > whether VB or dos commands using rundll32, to remotely set a default printer
> > on a Windows XP computer. I am using the code below:
> >
> > strComputer = "remotecomputername"
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> >
> > Set colInstalledPrinters = objWMIService.ExecQuery _
> > ("Select * from Win32_Printer Where Name = 'PrinterName'")
> >
> > For Each objPrinter in colInstalledPrinters
> > objPrinter.SetDefaultPrinter()
> > Next
> >
> > but it simply executes silently and does NOT set the default printer on the
> > remote machine. The values are not updated in this sample to show actual
> > computer or printer names. All the samples I find on this function execute,
> > but do not perform the required action on the remote PC. They work perfectly
> > fine locally.
> >
> > So I guess my question is this even a supported function of VB and WMI to
> > remotely set a default printer? Is this a limitation or by design issue
> > where you just can't do that? And if so, does anyone have any suggestions on
> > how to accomplish this. I am trying to script the deletion of local printers
> > from Windows XP machines, the installation of new printer server based
> > printer shares on Server 2003, and the selecting of a default printer. I
> > have everything else working, but can't for the life of me get anything I try
> > to remotely set a default printer.
> >
> > any help is greatly appreciated.
> >
> > Thanks
>
> Choosing a printer as the default printer is a user prefered setting.
> These settings are saved in the HKEY_CURRENT_USER key in the registry (which
> is a copy of the user's-SID-subkey in HKEY_USERS).
>
> When you logged on remotely using other credentials as the user that is
> currently logged on to the console, the user specific changes you make are
> saved in an other userprofile on the computer (your profile on that
> computer).
>
> If you want to change the default printer remotely for the currently
> logged-on user, You must do that by changing registry values in the
> 'HKEY_USERS' key in the SID-subkey of this user. This subkey is visible for
> you because of the fact that the user is logged-on.
>
> For accessing the right subkey, the script has to determine the SID of the
> current logged-on user first.
>
> see here an example how to add remotely a printer for the users and make it
> his/her default printer *in realtime*.
> http://www.petri.co.il/forums/showthread.php?p=61627#post61627
>
> \Rems