Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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)
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|