I have several scripts/registry edits that I wish to apply to certain user accounts. Users will only get a selected one or two depending on the access i wish them to have.
How can I add more than one script or registry edit to selected user accounts in Windows Server 2003?
This conversation is currently closed to new comments.
maybe i m barking up the wrong tree but ran across this at microsoft scripting support: How Can I Run a Script Against a Range of IP Addresses? Q Hey, Scripting Guy! I?d like to run a script against all the computers on a subnet. Is there a way to do that without having to hardcode all the IP addresses into the script?
-- RB
A Hey, RB. Based on your email, it sounds like you have a setup similar to this: you have a subnet with IP addresses ranging from 192.168.1.1 to 192.168.1.254. You?d like to create a script that will start with the first IP address, run some code against that computer, move on to the second address, run that same code, and continue in this same vein until you?ve hit each and every computer. Furthermore, you?d like to do that in as few lines of code as possible, and without having to hardcode a couple hundred IP addresses.
So is there a way to do this? Of course there is, and it?s actually easier than you think.
To start with, let?s show you how to loop through a range of IP addresses. This is sample code, so all it does is echo the name of each IP address. After we explain how this script works, then we?ll show you a more practical example:
For i = intStartingAddress to intEndingAddress strComputer = strSubnet & i Wscript.Echo strComputer Next
No, really, that?s the entire script. We start by assigning some variables: intStartingAddress gets assigned the value 1; intEndingAddress gets assigned the value 254; and strSubnet gets assigned the value 192.168.1. (note the period after the 1). As you might have guessed, these values will serve as the building blocks for constructing our IP addresses.
After assigning the variables, we create a For-Next loop that runs from 1 (intStartingAddress) to 254 (intEndingAddress). Why do we loop from 1 to 254? That?s easy: that?s your IP range. What if your IP range is 192.168.1.7 to 109.168.1.54? No problem: use the exact same loop, but just change the value of intStartingAddress to 7 and intEndingAddress to 54.
Inside our loop, we concatenate the string value 192.168.1. with the current value of our loop variable (i). The first time we run through the loop ? when i equals 1 ? we combine 192.168.1. and 1. And guess what? That gives us value of 192.168.1.1, which just happens to be our first IP address. The last time we run through the loop, we?ll combine 192.168.1. and 254, giving us the value of our last IP address, 192.168.1.254. Run this script, and you?ll get output like this:
For i = intStartingAddress to intEndingAddress strComputer = strSubnet & i
Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_OperatingSystem") For Each objItem in ColItems Wscript.Echo strComputer & ": " & objItem.Caption Next
Next
As you can see, we again set the value of the variable strComputer to an IP address. We then simply connect to the WMI service on the computer represented by that address. That?s an easy thing to do, because WMI can connect to computers using IP addresses as well as using computer names.
Now we?d like to add one more little wrinkle. You mentioned in your email that there are a few IP addresses you?d like to exclude, IP addresses that probably represent routers or something. Okey-doke. Here?s a modified script that uses a Select Case statement to exclude certain computers:
intEndingAddress = 254 strSubnet = "192.168.1."
For i = intStartingAddress to intEndingAddress Select Case i Case 10 Case 50 Case 100
Case Else strComputer = strSubnet & i Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_OperatingSystem") For Each objItem in ColItems Wscript.Echo strComputer & ": " & objItem.Caption Next
End Select Next
Notice what happens when the value of i (the last octet in the IP address) is equal to 10, 50, or 100. That?s right: nothing happens. If a computer has an IP address of 192.168.1.10, 192.168.1.50, or 192.168.1.100, nothing happens; no WMI code will run, and the script will simply loop around. The WMI code will execute only for computers that have IP addresses other than those three. A simple but effective way to exclude specific IP addresses from the WMI portion of the script.
Why not just use Group Policy. It provides for Startup/Shutdown/Logon/Logoff scripts. You can have multiple scripts run synchronously or asynchronously. If synchronously the order can be changed as well. Assign the policy to an OU containing the users. If the reg edits are standard then they may have Group Policy settings. If not then save the reg file to a shared dir. and call it from the script.
The other option is to write a script and use the ifmember.exe. It is available here:
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
Multiple Scripts
How can I add more than one script or registry edit to selected user accounts in Windows Server 2003?