Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logon script Mark D. MacLachlan poss help 3

Status
Not open for further replies.

FISKO

Technical User
Aug 30, 2005
113
GB
Hi I have been fiddling around with Marks brill script and wondered if any one can help?
I wish to have an input box for the UserName and for it to then place this in the place of the user string. I post my effort below Thanks






'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT:
' Maps and disconnects drives
'
'
'==========================================================================




ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'Grab the user name
UserString ="fisk"
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)



'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next

'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
WSHNetwork.MapNetworkDrive "k:", "\\GANDALF\pupils\" & UserString,True
'MAPS a general share
WSHNetwork.MapNetworkDrive "U:", "\\gandalf\pupils",True


' THIS goes after USERSTRING WSHNetwork.UserName


'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing


'Quit the Script
wscript.quit
 
I think HTAs rock. I'm getting some good notoriety within MS for an internal App I wrote as an HTA. They are a nice way to give your scripts a friendlier interface.

I hope you find this post helpful.

Regards,

Mark
 
Thanks Mark,
Having problems with the ( variables in a sub that binds to the user object and changes the password. )
will keep trying and possibly post my code and errors. Thanks.
 
Hi Mark really stuck, changed and fiddled with the code so much I think i've lost the thread.

strComputer = "gandalf"
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer _
(strComputer, "root\cimv2", "bungaymiddle\UserString", "Userpassword")
objWMIServices.Security_.ImpersonationLevel = 3

my server is called gandalf
the domain is bungaymiddle.local
OU testbed
have I set the above ok?
thanks
 
You need to alter this section:

(strComputer, "root\cimv2", "bungaymiddle\UserString", "Userpassword")

to be something like this:

(strComputer, "root\cimv2", "bungaymiddle\" & UserString, Userpassword)

I hope you find this post helpful.

Regards,

Mark
 
Thanks Mark, Iwill now have to wait until Monday to try your suggestion. It is so close to working. The HTA/vbs works perfectly in all other respects, It opens in a fixed position to the right bottom of the desktop with No way of the user moving or closing it. It maps the drive and on logging off Disconects, its only the password bit that is bugging me.
When the Loggon, Logooff, Change password is all working ok I intend to have it open full screen with just the Username Password inputs and the logon button,At succesful logon have the HTA move to the Bottom Right with just the logoff change password buttons and at logoff return to the start full screen. Thanks for all your fantastic help with this project.
 
Just be kind and post the final results for other to benefit from OK?

I hope you find this post helpful.

Regards,

Mark
 
Hi Mark still getting an, access denied on the password reset. any ideas
 
Not without seeing your entire code.

I hope you find this post helpful.

Regards,

Mark
 
Thanks Mark, I post below......
-----------------------------------------------------------

' NAME: QuickLogon.hta
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 18 Apr 06
'
' COMMENT:
' Maps and disconnects drives (changes password for logged in user)
-----------------------------------------------------------

(code)





<head>
<title>Bungay Middle School</title>
<HTA:APPLICATION
APPLICATIONNAME="HTALogin"
SCROLL="no"
SINGLEINSTANCE="yes"
CAPTION="yes"
ShowInTaskbar="NO"

BORDER = "thin"
BorderStyle = Complex
>

<SCRIPT LANGUAGE="VBScript">

Sub Window_onLoad


'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True

next
End Sub




Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,objWMIServices, Path


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

Sub MapDrives
On Error Resume Next
Dim UserString, UserPassword, WSHNetwork
UserString = login.Value
UserPassword = password.Value

Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.MapNetworkDrive "P:", "\\gandalf\testbed\" & UserString,True, UserString,UserPassword




'Clear the boxes now that we are done using the info
login.Value = ""
password.Value =""
UserString=Nothing
UserPassword=Nothing


window.resizeTo 370,270
window.moveTo 650,490
End Sub


Sub disconnectdrives


'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
next

end sub

Sub changepassword
'WMI impersonation
strComputer = "gandalf"
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer _
(strComputer, "root\cimv2", "bungaymiddle\" & UserString, Userpassword)
objWMIServices.Security_.ImpersonationLevel = 3






Dim objNTUser,groupname
UserString = InputBox ("Enter Username to set password for.")
newPass = InputBox ("What should the password be?")
Set objNTUser = GetObject("WinNT://BUNGAYMIDDLE.LOCAL/" & UserString &",User")
objNTUser.SetPassword newPass

If err then
msgbox "Error Encountered"
else
msgbox "Password Set!"
End if

end sub

</SCRIPT>


<body bgcolor="cyan"><center>
<h1><font color="BLUE" face="Times New Roman" size="6">Bungay Middle School</h1>
<table align="center">
<tr><td>User Number:</td><td><input type="text" name="login" size="5" maxsize="5"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" size="30"></td></tr>
<tr><td colspan="2" align="center"><input id=runbutton type="button" value="Logon" name="run_button"

onClick="MapDrives"></td></tr>

<tr><td colspan="4" align="center"><input id=runbutton type="button" value="logoff" name="run_button"

onClick="disconnectdrives"></td></tr>


<tr><td colspan="6" align="center"><input id=runbutton type="button" value="change password" name="run_button"

onClick="changepassword"></td></tr>

</td></tr>
</table>


<p>
<span id = "DataArea"></span>
</center></body>

(code/)

PS is there a way of stopping this being closed via Alt+F4?
or refreshing if it is closed.
Thanks
 
Haven't forgotten about you. Just unable to test at the moment. Hope to have a solution for you soon.

I hope you find this post helpful.

Regards,

Mark
 
Thanks still trying this end to sort it. thanks
 
Hi I am begining to think that there is no way round the problem, I have searched and tried several scripts but with no luck so far, However I am still looking....
 
Sorry I have not had any time to set up a test environment to mimick this.I have a suggestion for you though.

You could create an Intranet page that does this. Set the authentication to Basic so it prompts the user.

I hope you find this post helpful.

Regards,

Mark
 
Thanks for your input, I may carry on but without the password reset, and hope that I can sort that later.Can I get this to run as a script from the server on machine startup? Any ideas on the Alt + F4 problem to stop people closing the HTA,

Only the GOOD die young,
Me? I,m here forever!
 
You can add the HTA to the All Users Startup folder or create a login script that launches it.

No way I know of to prevent it from being closed, but you cna check if it is running on a scheduled task and launch if it is not (will have a minor performance hit). I posted code you can use to see if it is running in this thread: thread329-1215754

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top