Some Useful Scripts from Readers

Readers sometimes send me scripts, tips, and suggestions for articles. I appreciate this a lot, and if you have an idea for a WindowsDevCenter article that could benefit other readers, feel free to
and I'll be glad to work your idea into a future article.

In this vein, I thought I'd share with you two scripts sent in by readers so you can benefit from their expertise in Windows scripting. These scripts are presented as is, with no warranties, because you may need to customize them for your own Windows environment.

Remotely Enabling Remote Desktop

This first script harks back to an article I wrote called Windows Server Hacks: Remotely Enable Remote Desktop. My idea was this: What if you've deployed a Windows Server 2003 box in a remote location but forgot to enable Remote Desktop on it so you can administer it remotely? In my article I showed a Registry hack you can use to do this, after which you have to reboot the remote machine to have it take effect. But reader Ronni Pedersen, an infrastructure specialist in Denmark, wrote a script that accomplishes this without a reboot! Here is Ronni's email, along with his script:

Default Printers and Roaming Profiles

This second script was sent to me by Pierre, a network administrator based in Montreal. Pierre had read two articles I wrote for WindowsNetworking.com (here and here) about managing printers using Group Policy, and wanted to share a script he wrote to set default printers for users with roaming user profiles. Here is Pierre's email in full, along with his script, which you can customize to meet your needs:

Excuse my English, it's not very good. I read a lot in windowsnetworking.com and other leading network administration sites. But I didn't find a way that satisfies me to control default printer in a roaming profile.

I did something on my network:

I build a Computer Group for each printer with global security group in active directory.

I put each desired computer object in a predefined Computer Group.

I build a policy for every printer witch I assign the specified Computer Group to that policy applies.

I put a script on each computer startup logon script folder that set a computer environment variable set to the name of the desired default printer.

I have a default logon script that read the environment variable and set the default printer to the profile.

Example:

Create a global security group with the name of a printer "DeskJet HP 895c (Parts Counter) Group"

Put inside every computer object that you want to have this default printer.

Create a new policy name "Default DeskJet HP 895c (Parts Counter) Group Policy"

Disable the user configuration setting and remove the apply policy to authenticated users.

------------------- Start ------------------------
Set objShell = WScript.CreateObject("WScript.Shell")
Set colSystemEnvVars = objShell.Environment("System")
'colSystemEnvVars("DefaultPrinter") = "The exact
Name of the printer set in printer control panel"
colSystemEnvVars("DefaultPrinter") = "DeskJet HP 895c (Parts Counter)"
-------------------- End -------------------------
Inside the default logon script add this command:
------------------- Start ------------------------
'(this code set the default printer to the "DefaultPrinter")
If WshShell.ExpandEnvironmentStrings("%DefaultPrinter%") = "" then
Else
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter WshShell.ExpandEnvironmentStrings("%DefaultPrinter%")
End if
------------------- End -------------------

In the company I have 5 printers. So I have 5 global security groups + 5 policies + 1 default logon script. With that I can define 5 different default printers for unlimited computer and users. Tested on w2k & wxp.