Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: Windows Scripts and Batch Files .: VB Script to Check if Local User account Exists

VB Script to Check if Local User account Exists

 

Description: Checks to see if a local user account exists on a pc.

Option Explicit

'On Error Resume Next

'Define Variables
Dim CompName1, objEnvVar1, OSName1, RunNetUser, Fso, FileExist, Line1, CMD
Dim TempDir, OpenFile, Line1Test

' Set up an Instance of the WScript.Shell Object and access Env var Computer Name
Set objEnvVar1 = WScript.CreateObject("WScript.Shell")
OSName1 = objEnvVar1.ExpandEnvironmentStrings("%OS%")
CompName1 = objEnvVar1.ExpandEnvironmentStrings("%ComputerName%")
CMD = objEnvVar1.ExpandEnvironmentStrings("%ComSpec% /K")
TempDir = objEnvVar1.ExpandEnvironmentStrings("%Temp%")

RunNetUser = ObjEnvVar1.Run(CMD & " Net User ChangetoRequiredUserName > %Temp%\NetUser.txt" , 0, False)

WScript.Sleep 1000

Set Fso = Createobject("Scripting.FileSystemObject")
FileExist = Fso.FileExists(TempDir & "\NetUser.txt")
If FileExist = True Then
Set OpenFile = Fso.OpenTextfile(TempDir & "\NetUser.txt", 1)
Do While OpenFile.AtEndOfStream = False
Line1 = Openfile.ReadAll
Loop
If line1 = "" Then
MsgBox "User Account Does Not Exist"
Else
MsgBox "User Account Exists"
End If
End If

Set CompName1=Nothing
Set objEnvVar1=Nothing
Set OSname1=Nothing
Set RunNetUser=Nothing
Set Fso=Nothing
Set FileExist=Nothing
Set Line1=Nothing
Set CMD=Nothing
Set TempDir=Nothing
Set OpenFile=Nothing
Set Line1Test=Nothing

'On Error Goto 0

WScript.Quit


How helpful was this article to you?

Related Articles

article VB Script to Add Domain User to Local Administrators - Requires Local Admin Rights
  Description: Takes a domain user...

(No rating)  3-24-2008    Views: 185   
article HOW to assign a Logon Script to a Profile for a Local User in Windows 2003
How to Assign a Logon Script to a User's...

(No rating)  6-3-2008    Views: 87   
article How To Assign a Logon Script to a Profile for a Local User in Windows Server 2003
How to Assign a Logon Script to a User's...

(No rating)  5-16-2008    Views: 117   

User Comments

Add Comment
No comments have been posted.