
Testing for NT Group membership within VB Script
I just wrote a small script (function) That test if the current user
is a member of the local administrators group, and returns a true or
false .
I hope I'll help you .
Enjoy Ido
Here is the script :
-----------------------------------------------
set WshShell = wscript.createobject("wscript.shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
IfIsAdmin() = True Then
msgbox "The Current User : "+Username+ " Has local Admin Privlige"
End If
Function IsAdmin()
Dim Outfile ,Line ,Retcode
on Error Resume Next
Const ForReading = 1, ForWriting = 2
temp = wshshell.expandenvironmentstrings("%TEMP%")
Username = wshshell.expandenvironmentstrings("%USERNAME%")
Username = LCase(Username)
Retcode = WshShell.run("cmd.exe /c %windir%\system32\net localgroup
administrators > %temp%\192837465.ini 2>&1", 0, True)
Set OutFile = Fso.OpenTextFile(temp+"\192837465.ini", ForReading)
Do While OutFile.AtEndOfStream <> True
Line = OutFile.ReadLine
Trim(Line)
Line = LCase(Line)
If Line = Username then
IsAdmin = True
Exit Do
End If
Loop
If IsAdmin <> True Then
IsAdmin = False
End If
OutFile.Close
fso.DeleteFile(temp+"\192837465.ini")
End Function
-----------------------------------------------------------
<Testing for NT Group membership within VB Script>:
I am writing a network logon script and want to test if the person
logging on is a member of an NT security group, and map their network
drives accordingly. I know in a batch file I could use the ifmember
utility that comes with the NT resource kit, but I am trying to find a
way of doing the same thing within a .vbs. Any suggestions?
Thanks
Richard