Newbie Having trouble with this User Info script, Please help 
Author Message
 Newbie Having trouble with this User Info script, Please help

G'day all
I found this script on the web and it looks really useful but it keeps
falling over with
"VBScript runtime error: Invalid procedure call or argument" on line 81.
The line and a few before it are----

70 ' -- step through all users and write their properties
71 For each objUser in objDomain
72     s = CHR(34) & objUser.Name & CHR(34) & ","
73     objUser.GetInfo
74     For i = 0 To propcount-1
75          v = GetProp(aProps(i))
76          s = s & CHR(34) & v & CHR(34) & ","
77     Next
78     For Each objGroup In objUser.Groups
79          s = s & CHR(34) & objGroup.Name & CHR(34) &","
80     Next
81     objFile.WriteLine s
82 Next

If someone could help it would be great as this looks like a really clever
script.
I couldn't work out why the "objFile.WriteLine s" bit was failing.
the whole script is as follows
Regards
Mark

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM)
'
' NAME: <filename>
'
' AUTHOR: EPA , EPA
' DATE  : 5/03/2003
'
' COMMENT: <comment>
'
'==========================================================================

'Gets all user properties through ADSI and writes to a comma delimited file
(csv). Requires ADSI 2.5

'Script:

Set WshNetwork      = WScript.CreateObject("WScript.Network")
Set WshShell      = WScript.CreateObject("WScript.Shell")

' -- Your domain name
strDomain = GetDomain()
strDomain = InputBox("This scrip enumerates all users and" & vbCRLF &_
               "user properties and writes the output" & vbCRLF &_
               "to a comma sensitive value (CSV) file" & vbCRLF & vbCRLF &_
               "Enter the Domain Name","List Users",strDomain)
If strDomain = "" Then
     WScript.Quit
End If

' -- Your known user name
strUser = WshNetwork.UserName          ' - all properties are based on this
user

' -- Create the file on the desktop
fname = WshShell.SpecialFolders("Desktop")& "\" & strDomain &"_Users.CSV"
set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FileExists (fname) Then
     set objFile = fso.GetFile (fname)
     objFile.Delete
End If
set objFile = fso.CreateTextFile (fname, True)

' -- Get the domain object
Set objDomain = GetObject("WinNT://" & strDomain)
objDomain.Filter = Array("user")

' -- Get a known user to get a list of properties
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser)
objUser.GetInfo
propcount = objUser.PropertyCount

' -- Write a header line with property names
s = CHR(34) & "Name" & CHR(34) & ","
Dim aProps()
ReDim aProps(propcount)
For i = 1 To propcount
     Set v = objUser.Next
     aProps(i-1) = v.Name
     s = s & CHR(34) & aProps(i-1) & CHR(34) & ","
Next
s = s & CHR(34) & "Groups" & CHR(34) & ","
objFile.WriteLine s

' -- step through all users and write their properties
For each objUser in objDomain
     s = CHR(34) & objUser.Name & CHR(34) & ","
     objUser.GetInfo
     For i = 0 To propcount-1
          v = GetProp(aProps(i))
          s = s & CHR(34) & v & CHR(34) & ","
     Next
     For Each objGroup In objUser.Groups
          s = s & CHR(34) & objGroup.Name & CHR(34) &","
     Next
     objFile.WriteLine s
Next

objFile.Close
Wscript.Echo "File Created: " & fname
Wscript.Quit

Function GetProp(strWhat)
     on error resume next
     strProp = objUser.Get(strWhat)
'     If IsNull(strProp) or IsEmpty(strProp) Then
'          GetProp = "UA"
'     Else
          If varType(strProp) = 8209 Then ' login hours & objectSid
               GetProp = "?"
          Else
               GetProp = CStr(strProp)
          End If
'     End If
End Function

Function GetDomain()
     strDomain = WshNetwork.UserDomain
     If strDomain = "" Then
          strKey =
"HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Workgroup"
          strDomain = WshShell.RegRead(strKey)
     End If
     GetDomain = strDomain
End Function



Sun, 21 Aug 2005 14:04:56 GMT  
 Newbie Having trouble with this User Info script, Please help
Quote:
>"VBScript runtime error: Invalid procedure call or

argument" on line 81.

Quote:
>The line and a few before it are----
>81     objFile.WriteLine s

Try putting "()":

objFile.WriteLine (s)

Pablo



Sun, 21 Aug 2005 22:02:42 GMT  
 Newbie Having trouble with this User Info script, Please help
Hi Mark,

It seems that the first "objFile.WriteLine s" does not encounter error.

When I use the following script, and input my machine name (list users on
my local computer), it does what I want to do. Does it work for you if you
list users on local computer (not domain)?
Set WshNetwork      = WScript.CreateObject("WScript.Network")
Set WshShell      = WScript.CreateObject("WScript.Shell")

' -- Your domain name
strDomain = GetDomain()
strDomain = InputBox("This scrip enumerates all users and" & vbCRLF &_
               "user properties and writes the output" & vbCRLF &_
               "to a comma sensitive value (CSV) file" & vbCRLF & vbCRLF &_
               "Enter the Domain Name","List Users",strDomain)
If strDomain = "" Then
     WScript.Quit
End If

' -- Your known user name
strUser = WshNetwork.UserName          ' - all properties are based on this
user
WScript.Echo strUser

' -- Create the file on the desktop
fname = WshShell.SpecialFolders("Desktop")& "\" & strDomain &"_Users.CSV"
set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FileExists (fname) Then
     set objFile = fso.GetFile (fname)
     objFile.Delete
End If
set objFile = fso.CreateTextFile (fname, True)

' -- Get the domain object
Set objDomain = GetObject("WinNT://" & strDomain)
objDomain.Filter = Array("user")

' -- Get a known user to get a list of properties
WScript.Echo "WinNT://" & strDomain & "/" & strUser

' -- step through all users and write their properties
For each objUser in objDomain
     s = CHR(34) & objUser.Name & CHR(34) & ","
     objUser.GetInfo
     For i = 0 To propcount-1
          v = GetProp(aProps(i))
          s = s & CHR(34) & v & CHR(34) & ","
     Next
     For Each objGroup In objUser.Groups
          s = s & CHR(34) & objGroup.Name & CHR(34) &","
     Next
     objFile.WriteLine s
Next

objFile.Close
Wscript.Echo "File Created: " & fname
Wscript.Quit

Function GetProp(strWhat)
     on error resume next
     strProp = objUser.Get(strWhat)
'     If IsNull(strProp) or IsEmpty(strProp) Then
'          GetProp = "UA"
'     Else
          If varType(strProp) = 8209 Then ' login hours & objectSid
               GetProp = "?"
          Else
               GetProp = CStr(strProp)
          End If
'     End If
End Function

Function GetDomain()
     strDomain = WshNetwork.UserDomain
     If strDomain = "" Then
          strKey =
"HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Workgroup"
          strDomain = WshShell.RegRead(strKey)
     End If
     GetDomain = strDomain
End Function

This posting is provided "AS IS" with no warranties, and confers no rights.

Regards,

Bill Cheng
Microsoft Support Engineer
--------------------

| Newsgroups: microsoft.public.scripting.vbscript
| Subject: Newbie Having trouble with this User Info script, Please help
| Lines: 153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300

| Date: Wed, 5 Mar 2003 17:04:56 +1100
| NNTP-Posting-Host: 158.45.1.2
| X-Trace: nnrp1.ozemail.com.au 1046844296 158.45.1.2 (Wed, 05 Mar 2003
17:04:56 EST)
| NNTP-Posting-Date: Wed, 05 Mar 2003 17:04:56 EST
| Path:
cpmsftngxa08.phx.gbl!cppssbbsa01.microsoft.com!news-out.cwix.com!newsfeed.cw
ix.com!news1.optus.net.au!optus!snewsf0.syd.ops.aspac.uu.net!nnrp1.ozemail.c
om.au!53ab2750!not-for-mail
| Xref: cpmsftngxa08.phx.gbl microsoft.public.scripting.vbscript:124542
| X-Tomcat-NG: microsoft.public.scripting.vbscript
|
| G'day all
| I found this script on the web and it looks really useful but it keeps
| falling over with
| "VBScript runtime error: Invalid procedure call or argument" on line 81.
| The line and a few before it are----
|
| 70 ' -- step through all users and write their properties
| 71 For each objUser in objDomain
| 72     s = CHR(34) & objUser.Name & CHR(34) & ","
| 73     objUser.GetInfo
| 74     For i = 0 To propcount-1
| 75          v = GetProp(aProps(i))
| 76          s = s & CHR(34) & v & CHR(34) & ","
| 77     Next
| 78     For Each objGroup In objUser.Groups
| 79          s = s & CHR(34) & objGroup.Name & CHR(34) &","
| 80     Next
| 81     objFile.WriteLine s
| 82 Next
|
| If someone could help it would be great as this looks like a really clever
| script.
| I couldn't work out why the "objFile.WriteLine s" bit was failing.
| the whole script is as follows
| Regards
| Mark
|
|
|
'==========================================================================
| '
| ' VBScript Source File -- Created with SAPIEN Technologies
PrimalSCRIPT(TM)
| '
| ' NAME: <filename>
| '
| ' AUTHOR: EPA , EPA
| ' DATE  : 5/03/2003
| '
| ' COMMENT: <comment>
| '
|
'==========================================================================
|
| 'Gets all user properties through ADSI and writes to a comma delimited
file
| (csv). Requires ADSI 2.5
|
| 'Script:
|
| Set WshNetwork      = WScript.CreateObject("WScript.Network")
| Set WshShell      = WScript.CreateObject("WScript.Shell")
|
| ' -- Your domain name
| strDomain = GetDomain()
| strDomain = InputBox("This scrip enumerates all users and" & vbCRLF &_
|                "user properties and writes the output" & vbCRLF &_
|                "to a comma sensitive value (CSV) file" & vbCRLF & vbCRLF
&_
|                "Enter the Domain Name","List Users",strDomain)
| If strDomain = "" Then
|      WScript.Quit
| End If
|
|
| ' -- Your known user name
| strUser = WshNetwork.UserName          ' - all properties are based on
this
| user
|
|
| ' -- Create the file on the desktop
| fname = WshShell.SpecialFolders("Desktop")& "\" & strDomain &"_Users.CSV"
| set fso = CreateObject ("Scripting.FileSystemObject")
| If fso.FileExists (fname) Then
|      set objFile = fso.GetFile (fname)
|      objFile.Delete
| End If
| set objFile = fso.CreateTextFile (fname, True)
|
|
| ' -- Get the domain object
| Set objDomain = GetObject("WinNT://" & strDomain)
| objDomain.Filter = Array("user")
|
|
| ' -- Get a known user to get a list of properties
| Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser)
| objUser.GetInfo
| propcount = objUser.PropertyCount
|
|
| ' -- Write a header line with property names
| s = CHR(34) & "Name" & CHR(34) & ","
| Dim aProps()
| ReDim aProps(propcount)
| For i = 1 To propcount
|      Set v = objUser.Next
|      aProps(i-1) = v.Name
|      s = s & CHR(34) & aProps(i-1) & CHR(34) & ","
| Next
| s = s & CHR(34) & "Groups" & CHR(34) & ","
| objFile.WriteLine s
|
|
| ' -- step through all users and write their properties
| For each objUser in objDomain
|      s = CHR(34) & objUser.Name & CHR(34) & ","
|      objUser.GetInfo
|      For i = 0 To propcount-1
|           v = GetProp(aProps(i))
|           s = s & CHR(34) & v & CHR(34) & ","
|      Next
|      For Each objGroup In objUser.Groups
|           s = s & CHR(34) & objGroup.Name & CHR(34) &","
|      Next
|      objFile.WriteLine s
| Next
|
| objFile.Close
| Wscript.Echo "File Created: " & fname
| Wscript.Quit
|
|
|
| Function GetProp(strWhat)
|      on error resume next
|      strProp = objUser.Get(strWhat)
| '     If IsNull(strProp) or IsEmpty(strProp) Then
| '          GetProp = "UA"
| '     Else
|           If varType(strProp) = 8209 Then ' login hours & objectSid
|                GetProp = "?"
|           Else
|                GetProp = CStr(strProp)
|           End If
| '     End If
| End Function
|
|
| Function GetDomain()
|      strDomain = WshNetwork.UserDomain
|      If strDomain = "" Then
|           strKey =
| "HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Workgroup"
|           strDomain = WshShell.RegRead(strKey)
|      End If
|      GetDomain = strDomain
| End Function
|
|
|
|
|
|
|
|
|
|
|



Mon, 22 Aug 2005 14:22:18 GMT  
 Newbie Having trouble with this User Info script, Please help
Hi,

Here's my guess. The Get method used in the GetProp
function raises an error if any property is not assigned a
value (for any user). That's why the "On Error Resume
Next" statement is needed. As written, the function does
not assign a value to GetProp in this case. Then, in the
loop for users, "v" may not have a value, in which
case "s" will have two double quotes in a row. This is
interpreted as a single quote, which means "s" has
unbalanced quotes.

A quick fix (if I'm right), would be to assign a default
value to GetProp in the function. The first line of the
function could be:

GetProp = "Undefined"

Richard
http://www.RLMueller.net

Quote:
>-----Original Message-----
>G'day all
>I found this script on the web and it looks really useful
but it keeps
>falling over with
>"VBScript runtime error: Invalid procedure call or

argument" on line 81.
Quote:
>The line and a few before it are----

>70 ' -- step through all users and write their properties
>71 For each objUser in objDomain
>72     s = CHR(34) & objUser.Name & CHR(34) & ","
>73     objUser.GetInfo
>74     For i = 0 To propcount-1
>75          v = GetProp(aProps(i))
>76          s = s & CHR(34) & v & CHR(34) & ","
>77     Next
>78     For Each objGroup In objUser.Groups
>79          s = s & CHR(34) & objGroup.Name & CHR(34) &","
>80     Next
>81     objFile.WriteLine s
>82 Next

>If someone could help it would be great as this looks

like a really clever
Quote:
>script.
>I couldn't work out why the "objFile.WriteLine s" bit was
failing.
>the whole script is as follows
>Regards
>Mark

>'=========================================================
=================
>'
>' VBScript Source File -- Created with SAPIEN

Technologies PrimalSCRIPT(TM)
Quote:
>'
>' NAME: <filename>
>'
>' AUTHOR: EPA , EPA
>' DATE  : 5/03/2003
>'
>' COMMENT: <comment>
>'
>'=========================================================
=================

>'Gets all user properties through ADSI and writes to a

comma delimited file

- Show quoted text -

Quote:
>(csv). Requires ADSI 2.5

>'Script:

>Set WshNetwork      = WScript.CreateObject
("WScript.Network")
>Set WshShell      = WScript.CreateObject("WScript.Shell")

>' -- Your domain name
>strDomain = GetDomain()
>strDomain = InputBox("This scrip enumerates all users
and" & vbCRLF &_
>               "user properties and writes the output" &
vbCRLF &_
>               "to a comma sensitive value (CSV) file" &
vbCRLF & vbCRLF &_
>               "Enter the Domain Name","List
Users",strDomain)
>If strDomain = "" Then
>     WScript.Quit
>End If

>' -- Your known user name
>strUser = WshNetwork.UserName          ' - all properties
are based on this
>user

>' -- Create the file on the desktop
>fname = WshShell.SpecialFolders("Desktop")& "\" &

strDomain &"_Users.CSV"

- Show quoted text -

Quote:
>set fso = CreateObject ("Scripting.FileSystemObject")
>If fso.FileExists (fname) Then
>     set objFile = fso.GetFile (fname)
>     objFile.Delete
>End If
>set objFile = fso.CreateTextFile (fname, True)

>' -- Get the domain object
>Set objDomain = GetObject("WinNT://" & strDomain)
>objDomain.Filter = Array("user")

>' -- Get a known user to get a list of properties
>Set objUser = GetObject("WinNT://" & strDomain & "/" &
strUser)
>objUser.GetInfo
>propcount = objUser.PropertyCount

>' -- Write a header line with property names
>s = CHR(34) & "Name" & CHR(34) & ","
>Dim aProps()
>ReDim aProps(propcount)
>For i = 1 To propcount
>     Set v = objUser.Next
>     aProps(i-1) = v.Name
>     s = s & CHR(34) & aProps(i-1) & CHR(34) & ","
>Next
>s = s & CHR(34) & "Groups" & CHR(34) & ","
>objFile.WriteLine s

>' -- step through all users and write their properties
>For each objUser in objDomain
>     s = CHR(34) & objUser.Name & CHR(34) & ","
>     objUser.GetInfo
>     For i = 0 To propcount-1
>          v = GetProp(aProps(i))
>          s = s & CHR(34) & v & CHR(34) & ","
>     Next
>     For Each objGroup In objUser.Groups
>          s = s & CHR(34) & objGroup.Name & CHR(34) &","
>     Next
>     objFile.WriteLine s
>Next

>objFile.Close
>Wscript.Echo "File Created: " & fname
>Wscript.Quit

>Function GetProp(strWhat)
>     on error resume next
>     strProp = objUser.Get(strWhat)
>'     If IsNull(strProp) or IsEmpty(strProp) Then
>'          GetProp = "UA"
>'     Else
>          If varType(strProp) = 8209 Then ' login hours &
objectSid
>               GetProp = "?"
>          Else
>               GetProp = CStr(strProp)
>          End If
>'     End If
>End Function

>Function GetDomain()
>     strDomain = WshNetwork.UserDomain
>     If strDomain = "" Then
>          strKey =
>"HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Workgr
oup"
>          strDomain = WshShell.RegRead(strKey)
>     End If
>     GetDomain = strDomain
>End Function

>.



Tue, 23 Aug 2005 03:02:39 GMT  
 Newbie Having trouble with this User Info script, Please help
Hi,


http://www.rlmueller.net/Document%20Attributes.htm

My program only documents one user (or object) at a time,
but you can see all the error checking I do to handle as
many situations as possible - strings, numbers, no value,
multi-valued attributes, 64-bit values, etc. My program
outputs to the console, so you would redirect the output
to a text file. Just to show how complicated it can get.

Richard
http:www.RLMueller.net

Quote:
>-----Original Message-----
>Hi,

>Here's my guess. The Get method used in the GetProp
>function raises an error if any property is not assigned
a
>value (for any user). That's why the "On Error Resume
>Next" statement is needed. As written, the function does
>not assign a value to GetProp in this case. Then, in the
>loop for users, "v" may not have a value, in which
>case "s" will have two double quotes in a row. This is
>interpreted as a single quote, which means "s" has
>unbalanced quotes.

>A quick fix (if I'm right), would be to assign a default
>value to GetProp in the function. The first line of the
>function could be:

>GetProp = "Undefined"

>Richard
>http://www.RLMueller.net
>>-----Original Message-----
>>G'day all
>>I found this script on the web and it looks really
useful
>but it keeps
>>falling over with
>>"VBScript runtime error: Invalid procedure call or
>argument" on line 81.
>>The line and a few before it are----

>>70 ' -- step through all users and write their properties
>>71 For each objUser in objDomain
>>72     s = CHR(34) & objUser.Name & CHR(34) & ","
>>73     objUser.GetInfo
>>74     For i = 0 To propcount-1
>>75          v = GetProp(aProps(i))
>>76          s = s & CHR(34) & v & CHR(34) & ","
>>77     Next
>>78     For Each objGroup In objUser.Groups
>>79          s = s & CHR(34) & objGroup.Name & CHR(34)
&","
>>80     Next
>>81     objFile.WriteLine s
>>82 Next

>>If someone could help it would be great as this looks
>like a really clever
>>script.
>>I couldn't work out why the "objFile.WriteLine s" bit
was
>failing.
>>the whole script is as follows
>>Regards
>>Mark

>>'========================================================
=
>=================
>>'
>>' VBScript Source File -- Created with SAPIEN
>Technologies PrimalSCRIPT(TM)
>>'
>>' NAME: <filename>
>>'
>>' AUTHOR: EPA , EPA
>>' DATE  : 5/03/2003
>>'
>>' COMMENT: <comment>
>>'
>>'========================================================
=
>=================

>>'Gets all user properties through ADSI and writes to a
>comma delimited file
>>(csv). Requires ADSI 2.5

>>'Script:

>>Set WshNetwork      = WScript.CreateObject
>("WScript.Network")
>>Set WshShell      = WScript.CreateObject("WScript.Shell")

>>' -- Your domain name
>>strDomain = GetDomain()
>>strDomain = InputBox("This scrip enumerates all users
>and" & vbCRLF &_
>>               "user properties and writes the output" &
>vbCRLF &_
>>               "to a comma sensitive value (CSV) file" &
>vbCRLF & vbCRLF &_
>>               "Enter the Domain Name","List
>Users",strDomain)
>>If strDomain = "" Then
>>     WScript.Quit
>>End If

>>' -- Your known user name
>>strUser = WshNetwork.UserName          ' - all
properties
>are based on this
>>user

>>' -- Create the file on the desktop
>>fname = WshShell.SpecialFolders("Desktop")& "\" &
>strDomain &"_Users.CSV"
>>set fso = CreateObject ("Scripting.FileSystemObject")
>>If fso.FileExists (fname) Then
>>     set objFile = fso.GetFile (fname)
>>     objFile.Delete
>>End If
>>set objFile = fso.CreateTextFile (fname, True)

>>' -- Get the domain object
>>Set objDomain = GetObject("WinNT://" & strDomain)
>>objDomain.Filter = Array("user")

>>' -- Get a known user to get a list of properties
>>Set objUser = GetObject("WinNT://" & strDomain & "/" &
>strUser)
>>objUser.GetInfo
>>propcount = objUser.PropertyCount

>>' -- Write a header line with property names
>>s = CHR(34) & "Name" & CHR(34) & ","
>>Dim aProps()
>>ReDim aProps(propcount)
>>For i = 1 To propcount
>>     Set v = objUser.Next
>>     aProps(i-1) = v.Name
>>     s = s & CHR(34) & aProps(i-1) & CHR(34) & ","
>>Next
>>s = s & CHR(34) & "Groups" & CHR(34) & ","
>>objFile.WriteLine s

>>' -- step through all users and write their properties
>>For each objUser in objDomain
>>     s = CHR(34) & objUser.Name & CHR(34) & ","
>>     objUser.GetInfo
>>     For i = 0 To propcount-1
>>          v = GetProp(aProps(i))
>>          s = s & CHR(34) & v & CHR(34) & ","
>>     Next
>>     For Each objGroup In objUser.Groups
>>          s = s & CHR(34) & objGroup.Name & CHR(34) &","
>>     Next
>>     objFile.WriteLine s
>>Next

>>objFile.Close
>>Wscript.Echo "File Created: " & fname
>>Wscript.Quit

>>Function GetProp(strWhat)
>>     on error resume next
>>     strProp = objUser.Get(strWhat)
>>'     If IsNull(strProp) or IsEmpty(strProp) Then
>>'          GetProp = "UA"
>>'     Else
>>          If varType(strProp) = 8209 Then ' login hours
&
>objectSid
>>               GetProp = "?"
>>          Else
>>               GetProp = CStr(strProp)
>>          End If
>>'     End If
>>End Function

>>Function GetDomain()
>>     strDomain = WshNetwork.UserDomain
>>     If strDomain = "" Then
>>          strKey =
>>"HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Workg
r
>oup"
>>          strDomain = WshShell.RegRead(strKey)
>>     End If
>>     GetDomain = strDomain
>>End Function

>>.

>.



Tue, 23 Aug 2005 03:12:17 GMT  
 Newbie Having trouble with this User Info script, Please help
It looks like you are missing a space on line 79, when
setting the variable s.  The line should be
s = s & CHR(34) & objGroup.Name & CHR(34) & "," instead of
s = s & CHR(34) & objGroup.Name & CHR(34) &","

Quote:
>-----Original Message-----
>G'day all
>I found this script on the web and it looks really useful
but it keeps
>falling over with
>"VBScript runtime error: Invalid procedure call or

argument" on line 81.
Quote:
>The line and a few before it are----

>70 ' -- step through all users and write their properties
>71 For each objUser in objDomain
>72     s = CHR(34) & objUser.Name & CHR(34) & ","
>73     objUser.GetInfo
>74     For i = 0 To propcount-1
>75          v = GetProp(aProps(i))
>76          s = s & CHR(34) & v & CHR(34) & ","
>77     Next
>78     For Each objGroup In objUser.Groups
>79          s = s & CHR(34) & objGroup.Name & CHR(34) &","
>80     Next
>81     objFile.WriteLine s
>82 Next

>If someone could help it would be great as this looks

like a really clever
Quote:
>script.
>I couldn't work out why the "objFile.WriteLine s" bit was
failing.
>the whole script is as follows
>Regards
>Mark

>'=========================================================
=================
>'
>' VBScript Source File -- Created with SAPIEN

Technologies PrimalSCRIPT(TM)
Quote:
>'
>' NAME: <filename>
>'
>' AUTHOR: EPA , EPA
>' DATE  : 5/03/2003
>'
>' COMMENT: <comment>
>'
>'=========================================================
=================

>'Gets all user properties through ADSI and writes to a

comma delimited file

- Show quoted text -

Quote:
>(csv). Requires ADSI 2.5

>'Script:

>Set WshNetwork      = WScript.CreateObject
("WScript.Network")
>Set WshShell      = WScript.CreateObject("WScript.Shell")

>' -- Your domain name
>strDomain = GetDomain()
>strDomain = InputBox("This scrip enumerates all users
and" & vbCRLF &_
>               "user properties and writes the output" &
vbCRLF &_
>               "to a comma sensitive value (CSV) file" &
vbCRLF & vbCRLF &_
>               "Enter the Domain Name","List
Users",strDomain)
>If strDomain = "" Then
>     WScript.Quit
>End If

>' -- Your known user name
>strUser = WshNetwork.UserName          ' - all properties
are based on this
>user

>' -- Create the file on the desktop
>fname = WshShell.SpecialFolders("Desktop")& "\" &

strDomain &"_Users.CSV"

- Show quoted text -

Quote:
>set fso = CreateObject ("Scripting.FileSystemObject")
>If fso.FileExists (fname) Then
>     set objFile = fso.GetFile (fname)
>     objFile.Delete
>End If
>set objFile = fso.CreateTextFile (fname, True)

>' -- Get the domain object
>Set objDomain = GetObject("WinNT://" & strDomain)
>objDomain.Filter = Array("user")

>' -- Get a known user to get a list of properties
>Set objUser = GetObject("WinNT://" & strDomain & "/" &
strUser)
>objUser.GetInfo
>propcount = objUser.PropertyCount

>' -- Write a header line with property names
>s = CHR(34) & "Name" & CHR(34) & ","
>Dim aProps()
>ReDim aProps(propcount)
>For i = 1 To propcount
>     Set v = objUser.Next
>     aProps(i-1) = v.Name
>     s = s & CHR(34) & aProps(i-1) & CHR(34) & ","
>Next
>s = s & CHR(34) & "Groups" & CHR(34) & ","
>objFile.WriteLine s

>' -- step through all users and write their properties
>For each objUser in objDomain
>     s = CHR(34) & objUser.Name & CHR(34) & ","
>     objUser.GetInfo
>     For i = 0 To propcount-1
>          v = GetProp(aProps(i))
>          s = s & CHR(34) & v & CHR(34) & ","
>     Next
>     For Each objGroup In objUser.Groups
>          s = s & CHR(34) & objGroup.Name & CHR(34) &","
>     Next
>     objFile.WriteLine s
>Next

>objFile.Close
>Wscript.Echo "File Created: " & fname
>Wscript.Quit

>Function GetProp(strWhat)
>     on error resume next
>     strProp = objUser.Get(strWhat)
>'     If IsNull(strProp) or IsEmpty(strProp) Then
>'          GetProp = "UA"
>'     Else
>          If varType(strProp) = 8209 Then ' login hours &
objectSid
>               GetProp = "?"
>          Else
>               GetProp = CStr(strProp)
>          End If
>'     End If
>End Function

>Function GetDomain()
>     strDomain = WshNetwork.UserDomain
>     If strDomain = "" Then
>          strKey =
>"HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Workgr
oup"
>          strDomain = WshShell.RegRead(strKey)
>     End If
>     GetDomain = strDomain
>End Function

>.



Fri, 02 Sep 2005 11:42:14 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Having trouble obtaining domain name please help

2. Im having trouble obtaining domian name. Please Help

3. Newbie and having difficulties resolving this issue.Please Help Desperate

4. Having Trouble with CurDir - Please Help

5. Please help! Having trouble with data control

6. PLEASE HELP!!! Having trouble with VB5 component

7. newbie: having trouble with uniprint/gsview

8. Newbie having trouble with VBA Code in Access

9. Newbie having trouble with Object Error

10. A Newbie having trouble passing variables from one sup-procedure to another

11. New user to VB5 having trouble with data controll

12. Having trouble zipping up log files using script

 

 
Powered by phpBB® Forum Software