Question

assign default printer based on computer's group membership

Asked by: junior15

I have been looking through previously asked questions that are closely related to mine, but haven't been able to find a suitable answer.

Here is what I've got:

Windows 2000 Active Directory domain with OU's for each physical site.
Servers running Windows 2000 and Windows 2003 Server
Workstations running Windows 2000 Pro and Windows XP Pro
Login scripts running via GPO's

In one of my locations, I've got 5 printers being installed via the login script. The problem I've got is that I would like to setup the default printer based on the computer rather than the person because I have some people that login to multiple computers and I would like their default printer to be the one that is closest to whichever computer they login to.

So far, the solutions that I have rejected include the following:
--checking IP address - all the computers in the area are on the same subnet so I can't pick out computers based on IP
--based on computer names - while this is close, I would like to refrain from putting specific computer names in  my scripts because then anytime a computer moves or I add a new one, I have to edit my scripts.

What I want to be able to do is have it based on group names. I have added the computers in question to a group in AD so if I could setup something in the login script to check to see if the computer was a member of this group, that would work. The only problem is that I don't know how to do this. I am using ifmember to determine if users are members of specific groups, but I need something for computers.

I am not the only administrator for this site and I also don't want to have to modify my script everytime I add or move computers so if anybody can suggest something that would work based on the computer's group membership, or if anybody could come up with another option that isn't computer specific, I would greatly appreciate it.

Thanks,
Daniel

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-01-04 at 10:48:34ID21261512
Tags

printer

,

default

,

group

,

computer

,

based

Topic

Windows NT Networking

Participating Experts
2
Points
300
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Logon that tests for OU membership.
    I have been looking for a way to create a logon.bat file that will allow me that ability to test for OU membership. Using the IFMEMBER will allow me to test for Group Membership...but we have an excessive number of groups. To consolidate the # of users I put them in OU's. T...
  2. Map printers to computer OU
    I work for a school system where we have a few computers in each classroom. The students move from class to class through out the day. The computers are in OU's that are room specific and the students are in a students OU. I am looking for a way to map printers based on th...
  3. Assign group membership based on OU
    hello, I was wondering if it is possible to assign distribution/security group membership to a user based on the organizational unit they are placed in. The idea is that I create a OU for a department, once I place that user in the department they automatically get resources ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: BlueDevilFanPosted on 2005-01-07 at 03:24:50ID: 12981810

Hi, Daniel.

Here's a script (VBScript) that should handle this for you.  It tests to see if a computer is a member of a given group.  If it is, then it sets the default printer, otherwise it does nothing.  I put this together quickly and have not tested it yet (I'm not in a position to at the moment).  

'Script Begins Here
Dim objNetwork, objComputer, strDomain, strComputerName
strDomain = "DomainName"
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = objNetwork.ComputerName
Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputerName & ",computer")
If IsGroupMember(strDomain, "MyGroup") Then
    objNetwork.SetDefaultPrinter "PrinterName"
End If
Set objNetwork = Nothing
Set objComputer = Nothing
Wscript.Quit

Function IsGroupMember(strDomain, strGroup)
    Dim objGroup
    Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
    If objGroup.IsMember(objComputer.ADsPath) Then
        IsGroupMember = True
    Else
        IsGroupMember = False
    End If
    Set objGroup = Nothing
End Function

 

by: junior15Posted on 2005-01-07 at 07:12:31ID: 12983902

Thank you for the response. This looks like it might just do what I want it to do. I do have two questions.
First, this will work for Windows 2000 as well as Windows XP, right (I don't see why it wouldn't, but one solution I tried was supposed to work for both but didn't work for Windows 2000)?
Second, what modifications would I have to make to the above if I wanted to just add the printers rather than set a default printer (in some cases I'm connecting 4 or 5 printers)? I had originally wanted to set the default printer, but there are some users that have local printers and I don't want to override their default printer settings by assigning them a network printer as their default printer. Since the first printer that gets added gets set as the default, then just by adding the printer I want as the default printer before I add the other network printers, I should be OK.
I'm currently implementing a very convoluted method of searching text files that isn't working out so well so this script will be a very welcome change.

Thank you,
Daniel

 

by: BlueDevilFanPosted on 2005-01-07 at 08:12:53ID: 12984600

Good morning, Dan.

I just tested the code, first chance I've had, and found one error.  Change this line

    If objGroup.IsMember(objComputer.ADsPath) Then

to

    If objGroup.IsMember(objComputer.ADsPath & "$") Then

in the IsGroupMember function.

Yes, this should work for both 2000 and XP.  I've tested on XP and can vouch for it there.  Unfortunately, I don't have a 2000 PC connected to my AD network so I can't test there.  To add a printer connection instead of setting one as default, switch this command

    objNetwork.SetDefaultPrinter "PrinterName"

to

    objNetwork.AddPrinterConnection "\\Server\PrinterName"

 

by: junior15Posted on 2005-01-07 at 20:18:04ID: 12990622

I'll give this a try tomorrow when I get to work and let you know how it goes.

Thanks for the input.

 

by: junior15Posted on 2005-01-08 at 15:13:46ID: 12994503

OK, I got the scripts working, but I'm not sure how to integrate them into my current scripts. Since I'm using batch files to do everything else, I'm not quite sure how to get these scripts to run when I want them to.

If you could take a look at what I've got, and give me some suggestions, I would appreciate it.

Here is what I've got. One main OU that I manage. That OU contains 6 other OUs which represent the 6 sites that I'm responsible for. Two of these OUs are in the same building and on the same IP subnet, but the rest are all at different sites, in their own building and have their own unique IP subnet.

Right now, my GPO is applied to the main OU and that is where my login script is running from. Here is what it is doing:

-Checks if user is in the Main OU admins group, if yes, maps admin shared folders to X:, Y:, and Z:.
-Checks through each "OU Users" group (a group that contains all the users for that OU/site) and maps the public folder on the file server at that site to P: (so if a user is in the OU3 Users group, it would map P: to \\ou3server\public)
-Checks  if user is in a Shared Folders group and maps S: to \\OU2\Shared
-Determines which site the user is at based on IP address (the two OUs that are on the same subnet are considered the same site for this purpose)
-based on location (determined above by IP address), connect network printers (this is where the vbs scripts are called)

I've modified my login script to show where the scripts would run that would map the printers, but I have some special needs for Site 2 that I'm not sure how to implement using these scripts. Here is what I need:

-For the computers in the front office of the first floor, connect only the one printer in that office
-For the computers in the back office of the first floor, connect only the one printer in that office
-For the computers on the second floor:
     -for the computers near computer 0014, connect to the local printer connected to that computer
     -for the computers in bob's office, connect to the printers in that office
     -for the computers in the back office, connect to the printers in that office
     -for all the computers on the 2nd floor, connect to the two general use network printers (in addition to the other printers they are already connected to)
-Connect the two general use network printers to all computers that don't match any of the other groups (laptops that move from site to site are my target here)

I hope this is not too confusing or convoluted. If this is too much to handle here, just let me know and I'll try to find the answer else where.

Thank you for any help you can provide.
Daniel

@echo off

net use /persistent:no

IfMember.exe "OU1 Admins"
if Not Errorlevel 1 GOTO DoneOU1TAdmins

net use x: /delete
net use y: /delete
net use z: /delete

net use x: \\ou1-fs\d$
net use y: \\ou2-fs\d$
net use z: \\io\e$

echo %computername%,%username%,%date%,%time%,%ipadd%,%location%,%LOGONSERVER% >>"Z:\logs\computers\%computername%.csv"
echo %computername%,%username%,%date%,%time%,%ipadd%,%location%,%LOGONSERVER% >>"Z:\logs\users\%username%.csv"
:DoneOU1Admins

IfMember.exe "OU2 Admins"
if Not Errorlevel 1 GOTO DoneOU2Admins

net use y: /delete
net use z: /delete

net use y: \\ou2-fs\d$
net use z: \\appserver\e$

echo %computername%,%username%,%date%,%time%,%ipadd%,%location%,%LOGONSERVER% >>"Z:\logs\computers\%computername%.csv"
echo %computername%,%username%,%date%,%time%,%ipadd%,%location%,%LOGONSERVER% >>"Z:\logs\users\%username%.csv"
:DoneOU2Admins


REM **** Map public directory for OU4

IfMember.exe "OU4 Users"
if Not Errorlevel 1 GOTO DoneOU4Users
net use g: /delete
net use g: \\ou4-fs\public
:DoneOU4Users


REM **** Map public directory based on primary user group membership

net use p: /delete

IfMember.exe "OU1 Users"
if Errorlevel 1 net use p: \\ou1-fs\public

IfMember.exe "OU2 Users"
if Errorlevel 1 net use p: \\ou2-fs\public

IfMember.exe "OU3 Users"
if Errorlevel 1 net use p: \\ou3-fs\public

IfMember.exe "OU5 Users"
if Errorlevel 1 net use p: \\ou5-fs\public

IfMember.exe "OU6 Users"
if Errorlevel 1 net use p: \\ou6-fs\public


REM **** Map shared folder on ou2-fs if needed

IfMember.exe "OU2 Shared"
if Not Errorlevel 1 GOTO doneOU2Shared
net use s: /delete
net use s: \\ou2-fs\shared
:doneOU2Shared




REM **** use IP address to determine location

for /F "tokens=2 delims=:" %%K in ('ipconfig ^| find /I "IP Address"') do set IPADD=%%K
REM Site 1 subnet is 10.10.101.0/24
IF /I %IPADD% LSS 10.10.101 GOTO invalid ELSE
IF /I %IPADD% LSS 10.10.101.9 GOTO Site1 ELSE
REM Site 3 subnet is 10.10.115.0/24
IF /I %IPADD% LSS 10.10.115 GOTO invalid ELSE
IF /I %IPADD% LSS 10.10.115.9 GOTO Site3 ELSE
REM Site 5 subnet is 10.10.27.0/24
IF /I %IPADD% LSS 10.10.27 GOTO invalid ELSE
IF /I %IPADD% LSS 10.10.27.9 GOTO Site5 ELSE
REM Site 2 subnet is 10.12.0.0/16
IF /I %IPADD% LSS 10.12 GOTO invalid ELSE
IF /I %IPADD% LSS 10.12.9 GOTO Site2 ELSE
REM Site 3 subnet is 192.168.69.0/24
IF /I %IPADD% LSS 192.168.69 GOTO invalid ELSE
IF /I %IPADD% LSS 192.168.69.9 GOTO Site3 ELSE
GOTO invalid


REM **** Setup printers based on location of PC

:Site1
set LOCATION=Site1

REM connect pam's locally shared printer to computers in that office
cscript connect_ou1_printers_pam.vbs
REM connect all network printers at site 1
cscript connect_ou1_printers.vbs

GOTO FinishLocation

:Site3
set LOCATION=Site3

REM connect printer connected to pc 0004 to computers in that office
cscript connect_ou3_printers_0004.vbs
REM connect all network printers at site 3
cscript connect_ou3_printers.vbs

GOTO FinishLocation

:Site6
set LOCATION=Site6
GOTO FinishLocation

:Site4
set LOCATION=Site4
REM connect all network printers at site 4
cscript connect_ou4_printers.vbs
GOTO FinishLocation

:Site2
set LOCATION=Site2

REM connect only the printer in the front office (don't run other scripts)
cscript connect_site2_printers_1st_front.vbs
REM connect only the printer in the back office (don't run other scripts)
cscript connect_site2_printers_1st_back.vbs
REM connect printer connected to computer 0014 to computers in that office
cscript connect_site2_printers_2nd_0014.vbs
REM connect printers in bob's office to computers in that office
cscript connect_site2_printers_2nd_bob.vbs
REM connect printers in the back office to computers in that office
cscript connect_site2_printers_2nd_back.vbs
REM connect general use printers to all computer on the 2nd floor
cscript connect_site2_printers_2nd.vbs

GOTO FinishLocation

:invalid
REM **** Not logged in at one of our sites.
set Location=Unknown
GOTO FinishLocation

:FinishLocation

:Done

 

by: junior15Posted on 2005-01-08 at 15:17:53ID: 12994513

One other thing I forgot about is that I need to use a logoff script to disconnect any printers that were connected during logon. I can't just disconnect all network printers because some people use their laptops at other sites and I don't want to disconnect any printers they have setup manually.

I know how to disconnect the printers, I just don't know the best way to only disconnect the printers that I connected.

Thanks
Daniel

 

by: BlueDevilFanPosted on 2005-01-09 at 13:28:23ID: 12998433

You could set this information into an environment variable and then read it when you run the logoff script.  Or you could write it to a text file.

I'm going to have to go through the batch file a couple of times in order to answer your other question.

 

by: junior15Posted on 2005-01-09 at 15:47:29ID: 12999158

Writing the printers to a text file was what I thought of doing. I figured that as each printer is connected in the login script, that printer name is written to a text file on the computer and then the logoff script just reads each of the printers from that text file and removes the printer and then deletes the text file.

Thanks again for all your time and effort on this. I really appreciate the help.
Daniel

 

by: BlueDevilFanPosted on 2005-01-09 at 15:53:00ID: 12999183

Sure, Daniel.  Glad I was able to help out.

 

by: junior15Posted on 2005-01-11 at 08:30:45ID: 13015297

BlueDevilFan:

Did you have a chance to look over my script to see if it was possible to change it all over to a vbs script rather than a batch file? The main part that I'm not sure how to do and haven't really been able to find an example of is  the part that determines the site by the IP address. Also, how would I about writing the printers that get connected to a text file so that I can read that text file during logoff?

Thanks again for the help.
Daniel

 

by: BlueDevilFanPosted on 2005-01-11 at 19:48:07ID: 13020949

Daniel,

No, not yet.  I wasn't thinking that you wanted to convert the whole batch file, I was thinking you just wanted to know where best to put the script I posted.  Actually, I believe that converting the whole script sounds easier.  I'll try and get to this tomorrow, though it may well be tomorrow evening.  

You can write the printer information to a file like this:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\PrinterInfo.Txt")
.
.
objNetwork.AddPrinterConnection "\\Server\PrinterName"
objFile.WriteLine "\\Server\PrinerName"
.
.
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing

Then when you're ready to disconnect them, you use this:

Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\PrinterInfo.Txt")
While Not objFile.AtEndOfStream()
    objNetwork.RemovePrinterConnection objFile.ReadLine
Wend
objFile.Close
Set objFile = Nothing
objFSO.DeleteFile "C:\PrinterInfo.Txt"
Set objFSO = Nothing

 

by: BlueDevilFanPosted on 2005-01-12 at 19:03:21ID: 13030927

Daniel,

Here's your batch file converted to a script.  I couldn't test the entire script easily since my environment is so much different than yours.  I'm pretty confident it will work, but there might be a few syntax errors or typos.


'Script Begins Here
Const ForAppending = 8

Set objShell = Wscript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = objNetwork.ComputerName
strUserName = objNetwork.UserName
strDomain = objNetwork.UserDomain
If IsGroupMember(strDomain, "OU1 Admins") Then
    objNetwork.RemoveNetworkDrive "x:", True
    objNetwork.RemoveNetworkDrive "y:", True
    objNetwork.RemoveNetworkDrive "z:", True
    objNetwork.MapNetworkDrive "x:", "\\ou1-fs\d$"
    objNetwork.MapNetworkDrive "x:", "\\ou2-fs\d$"
    objNetwork.MapNetworkDrive "x:", "\\io\e$"
    WriteLogRecords
End If
If IsGroupMember(strDomain, "OU2 Admins") Then
    objNetwork.RemoveNetworkDrive "y:", True
    objNetwork.RemoveNetworkDrive "z:", True    
    objNetwork.MapNetworkDrive "y:", "\\ou2-fs\d$"
    objNetwork.MapNetworkDrive "z:", "\\appserver\e$"
    WriteLogRecords
End If
'**** Map public directory for OU4
If IsGroupMember(strDomain, "OU4 Users" Then
    objNetwork.RemoveNetworkDrive "g:", True
    objNetwork.MapNetworkDrive "g:", "\\ou2-fs\public"
End If
'**** Map public directory based on primary user group membership
objNetwork.RemoveNetworkDrive "p:", True
If IsGroupMember(strDomain, "OU1 Users") Then
    objNetwork.MapNetworkDrive "p:", "\\ou1-fs\public"
End If
If IsGroupMember(strDomain, "OU2 Users") Then
    objNetwork.MapNetworkDrive "p:", "\\ou2-fs\public"
End If
If IsGroupMember(strDomain, "OU3 Users") Then
    objNetwork.MapNetworkDrive "p:", "\\ou3-fs\public"
End If
If IsGroupMember(strDomain, "OU5 Users") Then
    objNetwork.MapNetworkDrive "p:", "\\ou5-fs\public"
End If
If IsGroupMember(strDomain, "OU6 Users") Then
    objNetwork.MapNetworkDrive "p:", "\\ou6-fs\public"
End If
'**** Map shared folder on ou2-fs if needed
If IsGroupMember(strDomain, "OU2 Shared") Then
    objNetwork.RemoveNetworkDrive "s:", True
    objNetwork.MapNetworkDrive "p:", "\\ou2-fs\shared"
End If
strIPAddr = objShell.Environment("SYSTEM").Item("IPAddr")
arrIPOctets = Split(strIPAddr)
If arrIPOctets(0) = "10" Then
    If arrIPOctets(1) = "10" Then
        If arrIPOctets(2) = "101" Then
            If CInt(arrIPOctets(3)) >= 0 And CInt(arrIPOctets(3)) <= 24 Then
                'This PC is in Site 1
                objShell.Environment("SYSTEM").Item("Site") = "1"
            End If
        ElseIf arrIPOctets = "115" Then
            If CInt(arrIPOctets(3)) >= 0 And CInt(arrIPOctets(3)) <= 24 Then
                'This PC is in Site 3
                objShell.Environment("SYSTEM").Item("Site") = "3"
            End If
        ElseIf arrIPOctets = "27" Then
            If CInt(arrIPOctets(3)) >= 0 And CInt(arrIPOctets(3)) <= 24 Then
                'This PC is in Site 5
                objShell.Environment("SYSTEM").Item("Site") = "5"
            End If
        End If
    ElseIf arrIPOctets(1) = "12" Then
        If arrIPOctets(2) = "0" Then
            If CInt(arrIPOctets(3)) >= 0 And CInt(arrIPOctets(3)) <= 16 Then
                'This PC is in Site 2
                objShell.Environment("SYSTEM").Item("Site") = "2"
            End If
        End If
    End If
ElseIf arrIPOctets(0) = "192" Then
    If arrIPOctets(1) = "168" Then
        If arrIPOctets(2) = "69" Then
            If CInt(arrIPOctets(3)) >= 0 And CInt(arrIPOctets(3)) <= 24 Then
                'This PC is in Site 3
                objShell.Environment("SYSTEM").Item("Site") = "3"
            End If
        End If
    End If
End If
Set objShell = Nothing
Set objNetwork = Nothing
Set objFSO = Nothing
Wscript.Quit

Function IsGroupMember(strDomain, strGroup)
    Dim objGroup
    Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
    If objGroup.IsMember(objComputer.ADsPath) Then
        IsGroupMember = True
    Else
        IsGroupMember = False
    End If
    Set objGroup = Nothing
End Function

Sub WriteLogRecords()
    Set objLogFile1 = objFSO.OpenTextFile("z:\logs\computers\" & strComputerName & ".csv", ForAppending)
    Set objLogFile2 = objFSO.OpenTextFile("z:\logs\users\" & strUserName & ".csv", ForAppending)
    strMessage = strComputerName & "," & strUserName & "," & Date & "," & Time & "," & _
        objShell.Environment("SYSTEM").Item("IPAddr") & "," & _
        objShell.Environment("SYSTEM").Item("Location")  & "," & _
        objShell.Environment("SYSTEM").Item("LogonServer")
    objLogfile1.WriteLine strMessage
    objLogfile2.WriteLine strMessage
    objLogFile1.Close
    objLogFile2.Close
    Set objLogFile1 = Nothing
    Set objLogFile2 = Nothing
End Sub

 

by: junior15Posted on 2005-01-12 at 21:17:17ID: 13031517

Thank you so much. I'll try it out in the next few days and let you know.

I apprecaite all the time you've put into this for me.

 

by: junior15Posted on 2005-01-27 at 15:32:14ID: 13158425

BlueDevilFan,

I finally got a chance to take a look at what you posted for me. I got everything working up until the section that determines the site based on the IP address.  I got an out of range error on the split command. When I did an echo of the strIPAddr variable, it was empty.

From what I can tell, his line assigns the IP to the variable:
       strIPAddr = objShell.Environment("SYSTEM").Item("IPAddr")

I seached google to find something referring to the IPAddr environment variable that this line appears to be referencing and I couldn't find anything so I'm not sure how this line works. I was able to find another script that would get the IP address from ipconfig and could incorporate that into this script, but if there is a better way, that would be nice.

If you could clarify this for me, I'd appreciate it.

Thanks,
Daniel

 

by: BlueDevilFanPosted on 2005-01-28 at 07:58:29ID: 13164306

Hi, Daniel.

Sorry, I must've gotten questions confused or I was cutting and pasting from code snippets and didn't paste in everything.  There are two ways I know of to get the IP Address.  The first way is the one you found when you searched Google.  Using it you use the wscript.shell object to shell out and run the IPConfig command, echoing the output to a file.  You then open the resulting file and search it for the line that begins with "IP Address".  Read everything to the right of the colon and you have the IP address.  The other way uses WMI (Windows Management Instrumentation).  The code for that looks something like this:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True", , 48)
For Each objItem In colItems
    strIPAddr = objItem.IPAddress(0)
    If strIPAddr <> "0.0.0.0" Then
        Exit For
    End If
Next

Both approaches suffer from a flaw though.  If the computer in question happens to have two, or more, IP addresses, then you'll get one, but perhaps not the right one.  The only definitive way around that is to know the exact name of the NIC whose IP address you want and modify the command to get the IP for just that one NIC.

 

by: junior15Posted on 2005-01-30 at 16:56:51ID: 13179073

Hi BlueDevilFan,

OK, I've got the script in place and I'm pretty sure it's working pretty well now. I had to make a few changes, but it was a good excercise for me to figure out how it all worked.

Thanks again for all the help on this.

Daniel

 

by: BlueDevilFanPosted on 2005-01-30 at 17:57:14ID: 13179346

Cool.  Glad I was able to help out.  This was an interesting question.

 

by: MHCCPosted on 2005-03-29 at 12:49:18ID: 13656341

I cannot get this script to work for me.  It keeps saying that I have an "unspecified error" on the line where the first "GetObject" appears.  It happens when I run my version of the script and the author's original version.  I do not know what is causing this as the error is "unspecified." Other than that the script seems to look all right.  If I could just figure out what is causing this error then I would be very happy.  Thanks again for any help you can give.

Jason

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...