Some Useful Scripts from Readersby Mitch Tulloch
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:
A comment to your article: "Windows Server Hacks: Remotely Enable Remote Desktop".
FYI: This can be done a whole lot easier...
I've created this script, that'll do the trick...
And we don't need to reboot the server!
'======================================================== 'Script name: EnableRemoteDesktop.vbs 'Author: Ronni Pedersen 'Last modified: 14/01-2005 'Version: 1.04 '======================================================== '======================================================== strComputer = InputBox ("Target Computer", "Enable Remote Desktop", default, 100, 100) strBruger = InputBox ("Username (DOMAIN\Administrator)", "Enable Remote Desktop", default, 100, 100) strPass = InputBox ("Password", "Enable Remote Desktop", default, 100, 100) '======================================================== strNameSpace = "root\cimv2" strClass = "Win32_TerminalServiceSetting" Const ENABLE_CONNECTIONS = 1 Const DISABLE_CONNECTIONS = 0 Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objSWbemServices = objSWbemLocator.ConnectServer (strComputer, strNameSpace, strBruger, strPass) Set colClass = objSWbemServices.ExecQuery("Select * from " & strClass) For Each objTing in colClass errAngivelse = objTing.SetAllowTSConnections(ENABLE_CONNECTIONS) Next If errAngivelse = 0 THEN Wscript.echo "Remote Desktop is now enabled on " + strComputer Else Wscript.echo "Houston, we have a problem...!!!" End If '======================================================== ' End of Script '========================================================
If you have questions about this 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.
- 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.
- Adding the computer group and select apply group policy.
- \Add in the computer startup script folder a script name "Set Default DeskJet HP 895c (Parts Counter).vbs"
The content of this script "Set Default DeskJet HP 895c (Parts Counter).vbs" is:
------------------- 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.
Again, if you have any questions about this script,
Return to the Windows DevCenter.