Win2K computer startup script for mapping printers. Help! 
Author Message
 Win2K computer startup script for mapping printers. Help!

Hi All,
I have with the help of you guys found enough scripts to cut and paste them
around and have a login script for users that maps drives and printers by
group membership! Great! Then someone says to me "How about a machine
startup script to connect the printers, that way a printers stay with the
pc" . Great idea, no point in me logining on in another office and having my
printers, I want the local ones.

So I need to get the MemberOf info for a computer account from Active
Directory rather than the logged on user. My problem is I do not have a list
of objects I can have a bash at. Where do I find this list? Anyway my
existing script says this... (Not written by me I must add)

Dim WSHNetwork
Dim NErr
Dim FSO
Dim strUserName  ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the
   ' user belongs

Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")

'
'------------------------------------------------------------------
'           B e g i n   M a i n   P r o c e s s i n g
'------------------------------------------------------------------
'
' Wait until the user is really logged in...
'
strUserName = ""
While strUserName = ""
  WScript.Sleep 100  ' 1/10 th of a second
  strUserName   = WSHNetwork.UserName
Wend
strUserDomain = WSHNetwork.UserDomain
'
' Read the user's account "Member Of" tab info across the network ' once
into a dictionary object.  A dictionary object offers fast ' easy access to
group membership information. '
Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
If MemberOf(ObjGroupDict, "Domain Admins") Then
  wscript.echo "Is a member of Domain Admins."
End If
DoMemberOfProcessing ObjGroupDict
wscript.quit

As you can see it works great for logged on user, can anyone help me modify
this so that I can run it as a computer startup script and find out what
groups the computer is in, once I have the ObjGroupDict file containing the
group membership for the computer my existing printer mapping routine should
work fine :-)

Anyones help on this would be so appriciated as I am fairly new to this
scripting stuff, and its amazing me so far  :-)

Thanks in advance

Russ



Sun, 02 May 2004 18:17:45 GMT  
 Win2K computer startup script for mapping printers. Help!
I a little more for you..

I have played with the WSHNetwork.UserName and changed it to ComputerName
and now it does return the correct name :-) Now the rest of the script
doesn;t work agghh!!

This bit...

Function CreateMemberOfObject(strDomain, strUserName)
'------------------------------------------------------------------
'  Given a domain name and username, returns a Dictionary
'  object of groups to which the user is a member of.
'
'  Inputs:
'
'     strDomain     - Input, NT Domain name
'     strUserName   - Input, NT username
'
   Dim  objUser, objGroup

   Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
   CreateMemberOfObject.CompareMode = vbTextCompare
   Set objUser = GetObject("WinNT://" _
   & strDomain & "/" _
   & strUserName & ",user")
   For Each objGroup In objUser.Groups
            CreateMemberOfObject.Add objGroup.Name, "-"
   Next
   Set objUser = Nothing

End Function

It's looking for the username!!! So when it gets a machine name instead it
says no such user!! How can I modify this to make to look for the machine
details instead? Help!

Thanks

Russ


Quote:
> Hi All,
> I have with the help of you guys found enough scripts to cut and paste
them
> around and have a login script for users that maps drives and printers by
> group membership! Great! Then someone says to me "How about a machine
> startup script to connect the printers, that way a printers stay with the
> pc" . Great idea, no point in me logining on in another office and having
my
> printers, I want the local ones.

> So I need to get the MemberOf info for a computer account from Active
> Directory rather than the logged on user. My problem is I do not have a
list
> of objects I can have a bash at. Where do I find this list? Anyway my
> existing script says this... (Not written by me I must add)

> Dim WSHNetwork
> Dim NErr
> Dim FSO
> Dim strUserName  ' Current user
> Dim strUserDomain ' Current User's domain name
> Dim ObjGroupDict ' Dictionary of groups to which the
>    ' user belongs

> Set WSHNetwork = WScript.CreateObject("WScript.Network")
> Set FSO = CreateObject("Scripting.FileSystemObject")

> '
> '------------------------------------------------------------------
> '           B e g i n   M a i n   P r o c e s s i n g
> '------------------------------------------------------------------
> '
> ' Wait until the user is really logged in...
> '
> strUserName = ""
> While strUserName = ""
>   WScript.Sleep 100  ' 1/10 th of a second
>   strUserName   = WSHNetwork.UserName
> Wend
> strUserDomain = WSHNetwork.UserDomain
> '
> ' Read the user's account "Member Of" tab info across the network ' once
> into a dictionary object.  A dictionary object offers fast ' easy access
to
> group membership information. '
> Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
> If MemberOf(ObjGroupDict, "Domain Admins") Then
>   wscript.echo "Is a member of Domain Admins."
> End If
> DoMemberOfProcessing ObjGroupDict
> wscript.quit

> As you can see it works great for logged on user, can anyone help me
modify
> this so that I can run it as a computer startup script and find out what
> groups the computer is in, once I have the ObjGroupDict file containing
the
> group membership for the computer my existing printer mapping routine
should
> work fine :-)

> Anyones help on this would be so appriciated as I am fairly new to this
> scripting stuff, and its amazing me so far  :-)

> Thanks in advance

> Russ



Sun, 02 May 2004 18:51:22 GMT  
 Win2K computer startup script for mapping printers. Help!

Asked and answered when you posted the question to my online forum......

Clarence
--
Win32Scripting...
Not that one by Duke Publishing. The ORIGINAL!
Over 500 scripts and over 50 COM objects to download and use FREE of charge.
Also check out the public online forum and chat rooms for community based
technical support.

http://cwashington.netreach.net

Quote:

> I a little more for you..

> I have played with the WSHNetwork.UserName and changed it to ComputerName
> and now it does return the correct name :-) Now the rest of the script
> doesn;t work agghh!!

> This bit...

> Function CreateMemberOfObject(strDomain, strUserName)
> '------------------------------------------------------------------
> '  Given a domain name and username, returns a Dictionary
> '  object of groups to which the user is a member of.
> '
> '  Inputs:
> '
> '     strDomain     - Input, NT Domain name
> '     strUserName   - Input, NT username
> '
>    Dim  objUser, objGroup

>    Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
>    CreateMemberOfObject.CompareMode = vbTextCompare
>    Set objUser = GetObject("WinNT://" _
>    & strDomain & "/" _
>    & strUserName & ",user")
>    For Each objGroup In objUser.Groups
>             CreateMemberOfObject.Add objGroup.Name, "-"
>    Next
>    Set objUser = Nothing

> End Function

> It's looking for the username!!! So when it gets a machine name instead it
> says no such user!! How can I modify this to make to look for the machine
> details instead? Help!

> Thanks

> Russ



> > Hi All,
> > I have with the help of you guys found enough scripts to cut and paste
> them
> > around and have a login script for users that maps drives and printers by
> > group membership! Great! Then someone says to me "How about a machine
> > startup script to connect the printers, that way a printers stay with the
> > pc" . Great idea, no point in me logining on in another office and having
> my
> > printers, I want the local ones.

> > So I need to get the MemberOf info for a computer account from Active
> > Directory rather than the logged on user. My problem is I do not have a
> list
> > of objects I can have a bash at. Where do I find this list? Anyway my
> > existing script says this... (Not written by me I must add)

> > Dim WSHNetwork
> > Dim NErr
> > Dim FSO
> > Dim strUserName  ' Current user
> > Dim strUserDomain ' Current User's domain name
> > Dim ObjGroupDict ' Dictionary of groups to which the
> >    ' user belongs

> > Set WSHNetwork = WScript.CreateObject("WScript.Network")
> > Set FSO = CreateObject("Scripting.FileSystemObject")

> > '
> > '------------------------------------------------------------------
> > '           B e g i n   M a i n   P r o c e s s i n g
> > '------------------------------------------------------------------
> > '
> > ' Wait until the user is really logged in...
> > '
> > strUserName = ""
> > While strUserName = ""
> >   WScript.Sleep 100  ' 1/10 th of a second
> >   strUserName   = WSHNetwork.UserName
> > Wend
> > strUserDomain = WSHNetwork.UserDomain
> > '
> > ' Read the user's account "Member Of" tab info across the network ' once
> > into a dictionary object.  A dictionary object offers fast ' easy access
> to
> > group membership information. '
> > Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
> > If MemberOf(ObjGroupDict, "Domain Admins") Then
> >   wscript.echo "Is a member of Domain Admins."
> > End If
> > DoMemberOfProcessing ObjGroupDict
> > wscript.quit

> > As you can see it works great for logged on user, can anyone help me
> modify
> > this so that I can run it as a computer startup script and find out what
> > groups the computer is in, once I have the ObjGroupDict file containing
> the
> > group membership for the computer my existing printer mapping routine
> should
> > work fine :-)

> > Anyones help on this would be so appriciated as I am fairly new to this
> > scripting stuff, and its amazing me so far  :-)

> > Thanks in advance

> > Russ



Mon, 03 May 2004 00:25:28 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. why does this script fail when I assign it to COMPUTER startup script

2. Win2K Startup/Shutdown scripts

3. Startup Script to install Printer

4. Help with Mapping of a dos printer for Terminal Server

5. Mapping shared printers with a Logon Script.

6. removing mapped printer in log-in script

7. Mapping home directory for win98 client on win2K server

8. printer mapping via script

9. Mapping shared printers with a Logon Script.

10. Active Directory User and Computers mappings for ADSI

11. Drive Mapping based on Computer Name

12. Map a shared folder to my computer

 

 
Powered by phpBB® Forum Software