Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How to validate windows account using VBSCript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36187
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to validate windows account using VBSCript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How to validate windows account using VBSCript - 7/13/2006 5:27:57 PM   
  udaybhaskerj

 

Posts: 5
Score: 0
Joined: 7/13/2006
Status: offline
If I supply domain username and password to VBScript, it has to validate username and password.
I found following sample code on net which validates windows account, but when I run this script, it says error calling LogonUser. If any one of you have any idea on this please help the needful.  If you have any code related to which validates windows account using VBScript please update it. Thanks.  

Sub main(args)

Dim user
Dim domain
Dim password
'' set these in your environment, or here in the script
'' If you're running as a service, you will need to set these
'' as SYSTEM variables

user = GetEnvironmentVariable (TSE_ENV_PERSISTENT, "USER")
domain = GetEnvironmentVariable (TSE_ENV_PERSISTENT, "DOMAIN")
password = GetEnvironmentVariable (TSE_ENV_PERSISTENT Or TSE_ENV_CRYPTO, "PASSWORD")

'' logon as user X
Dim hToken
hToken =
LogonUser(user,domain,password,LOGON32_LOGON_BATCH,LOGON32_PROVIDER_DEFAULT)

'' Impersonate user X
Dim ilu
ilu = ImpersonateLoggedOnUser(hToken)

'' do whatever you want to do as user X
If ilu = true Then
Print ("This thread is now running as " + user)
Else
Print ("Unable to become " + user)
End If

'' all done with this user
FreeHandle(hToken)

'' terminate impersonation for this thread
RevertToSelf

End Sub
 
 
Post #: 1
 
 RE: How to validate windows account using VBSCript - 7/13/2006 11:53:07 PM   
  mbouchard


Posts: 1924
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
In our application script we use something like this.


      

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to udaybhaskerj)
 
 
Post #: 2
 
 RE: How to validate windows account using VBSCript - 7/14/2006 12:53:30 AM   
  udaybhaskerj

 

Posts: 5
Score: 0
Joined: 7/13/2006
Status: offline
Thanks for your posting. But your code doesn't solve my problem. Your code mapes a shared drive and checks whether user is valid or not. But my requirement is entirly different. I know only domain, username and password, using these three parameters I have to validate user. I searched all the relevant sites, but I coudn't find vbscript or any script to validate windows account.

(in reply to udaybhaskerj)
 
 
Post #: 3
 
 RE: How to validate windows account using VBSCript - 7/15/2006 2:12:45 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Do you have AD?

Then you would be easier to query the OU if the user exists..look at this..:

strQuery = "<" & strADsPath & _
     ">;(&(objectClass=user)(objectCategory=person)(samaccountName=" & _
     sUserName & "));userPrincipalName,cn,distinguishedName;subtree" 
       'Execute the query
   Set oRecordSet = oConnection.Execute(strQuery)
   If oRecordSet.EOF And oRecordSet.BOF Then   
      'An empty recordset was returned
       QueryActiveDirectory = "Not Found"
   Else    'Records were found; loop through them
       While Not oRecordSet.EOF
           QueryActiveDirectory = oRecordSet.Fields("distinguishedName")
           oRecordSet.MoveNext
       Wend
   End If

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to udaybhaskerj)
 
 
Post #: 4
 
 RE: How to validate windows account using VBSCript - 7/15/2006 1:58:46 PM   
  DiGiTAL.SkReAM


Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
quote:

ORIGINAL: udaybhaskerj

Thanks for your posting. But your code doesn't solve my problem. Your code mapes a shared drive and checks whether user is valid or not. But my requirement is entirly different. I know only domain, username and password, using these three parameters I have to validate user. I searched all the relevant sites, but I coudn't find vbscript or any script to validate windows account.


Maybe it is the language barrier, but I am still unclear as to what you are needing to do.
When you say 'validate windows account', what are you validating it against?  Where will the script be running?  Are you running a Windows NT4 Domain structure or AD?

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to udaybhaskerj)
 
 
Post #: 5
 
 RE: How to validate windows account using VBSCript - 7/16/2006 5:09:12 PM   
  udaybhaskerj

 

Posts: 5
Score: 0
Joined: 7/13/2006
Status: offline
I am really sorry for confusing you all. Let me describe the scenario in which I am going to validate windows account.
I have ISMP(version 5) installer for our product, which will create some windows services with "Log On As" windows user. So I want to validate the user credentials(username and password) to check whether he has logon rights before installer starts laying down bits and create services. Installer will be run on all versions of windows from windows98 onwards. I will not have much information about the machine on which the installer is run. The script will run in java jvm supplied by ISMP installer. 

I want to inform user if he supplies bad username or password before laying down bits by installer.

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 6
 
 RE: How to validate windows account using VBSCript - 7/16/2006 11:41:20 PM   
  mbouchard


Posts: 1924
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
If you know the domain name, you should be able to know what the domain controller name is.  if you know the domain controller name then you should be able to use my example to map a drive to the netlogon folder on the DC.

If you don't know what DC the person is connecting too, you can read this from the logonserver environment variable.  If the logonserver is the same as the pc name you would know that the person is not logged on to the domain.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to udaybhaskerj)
 
 
Post #: 7
 
 RE: How to validate windows account using VBSCript - 7/20/2006 1:02:05 AM   
  udaybhaskerj

 

Posts: 5
Score: 0
Joined: 7/13/2006
Status: offline
Hi Mike,

Thanks a lot. Your inputs helped me to validate windows account(username and password) succesfully. Thanks a lot. I will upload my script once I clean it up.

Uday.

(in reply to udaybhaskerj)
 
 
Post #: 8
 
 RE: How to validate windows account using VBSCript - 7/31/2006 6:40:28 PM   
  udaybhaskerj

 

Posts: 5
Score: 0
Joined: 7/13/2006
Status: offline
Sorry, I am posting my vbscript to validate password after long time.


Here is the script:
---------------------
Dim objRootDSE, strConfig, objConnection, objCommand, strQuery
Dim objRecordSet, objDC, objSite
Dim fso, WshNetwork, sUser, oUser, sPassword, sDomain, oDomain, mappedDrive, drive
Dim objDictionary, strComputer, objWMIService, objDisk, strDrive, freeDrive, colDisks, i
Set oArgs = WScript.Arguments
sUser = oArgs.Item(0)
aTokens = Split(sUser, "\")
sDomain = Trim(aTokens(0))
sUser = Trim(aTokens(1))
sPassword = oArgs.Item(1)
If sDomain = sUser Then
sDomain = "."
End If
'Checking free directory on which netlogon folder can be mapped
Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
objDictionary.Add objDisk.DeviceID, objDisk.DeviceID
Next
freeDrive = "Empty"
For i = 67 to 90
strDrive = Chr(i) & ":"
If objDictionary.Exists(strDrive) Then
Else
freeDrive = strDrive
Exit For
End If
Next
If freeDrive = "Empty" Then
Wscript.Quit(0)
Else
' Determine configuration context from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfig = objRootDSE.Get("configurationNamingContext")
' Use ADO to search Active Directory for ObjectClass nTDSDSA.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strQuery = "<LDAP://" & strConfig _
& ">;(ObjectClass=nTDSDSA);AdsPath;subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
' creating file system objects
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
' The parent object of each object with ObjectClass=nTDSDSA is a Domain
' Controller. The parent of each Domain Controller is a "Servers"
' container, and the parent of this container is the "Site" container.
Do Until objRecordSet.EOF
Set objDC = GetObject( _
GetObject(objRecordSet.Fields("AdsPath")).Parent)
Set objSite = GetObject(GetObject(objDC.Parent).Parent)
on error resume next
WshNetwork.MapNetworkDrive freeDrive, "\\"&objDC.cn & "\netlogon",false,sDomain&"\" & sUser, sPassword 
If fso.FolderExists(freeDrive) Then
WshNetwork.RemoveNetworkDrive freeDrive
wscript.Quit(0)
End If
objRecordSet.MoveNext
Loop
Wscript.Quit(1)
' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objDC = Nothing
Set objSite = Nothing
End If
Wscript.Quit(1)

(in reply to udaybhaskerj)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to validate windows account using VBSCript Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts