Sep 232011
 

I’m not a fan of doing tedious things over and over, so I try to engineer around the problems, if possible. I’ve sanitized the scripts below a little, but the general idea is still there. We had a medication dispensing cart that didn’t have a bulk user manager, so all user accounts had to be created through the GUI. That would really suck… so I made a list of accounts in Excel, made some autohotkey shortcuts to run a few vbscripts to throw keypresses into a VNC session. I used autoit to handle mouse movements because the recorder tool that comes with it is just too easy to use.

http://www.autoitscript.com/site/autoit/
http://www.autohotkey.com

Anyhoo, what follows is a peek behind the curtain.

My AutoHotKey config

----------------------------------------
#a::
RunWait C:WindowsSystem32wscript.exe C:Usersyour_user_hereDesktopAutoInputuseraddstart.vbs
Runwait C:WindowsSystem32wscript.exe C:Usersyour_user_hereDesktopAutoInputenter.vbs
RunWait "C:Usersyour_user_hereDesktopAutoInputpnclick.exe"
Runwait C:WindowsSystem32wscript.exe C:Usersyour_user_hereDesktopAutoInputconfirm.vbs

return

#q::
RunWait C:WindowsSystem32wscript.exe C:Usersyour_user_hereDesktopAutoInputuseraddstart.vbs
Runwait C:WindowsSystem32wscript.exe C:Usersyour_user_hereDesktopAutoInputenter.vbs
RunWait "C:Usersyour_user_hereDesktopAutoInputrnclick.exe"
Runwait C:WindowsSystem32wscript.exe C:Usersyour_user_hereDesktopAutoInputconfirm.vbs

return

#w::
RunWait C:WindowsSystem32wscript.exe C:Usersyour_user_hereDesktopAutoInputenteruserbyname.vbs
RunWait "C:Usersyour_user_hereDesktopAutoInputpwreset.exe"

return


----------------------------------------

This part opens the add user dialog.
useraddstart.vbs

----------------------------------------
Set objShell = WScript.CreateObject("WScript.Shell")

Wscript.Sleep 300

objShell.SendKeys "{tab}"
Wscript.Sleep 20
objShell.SendKeys "{tab}"
Wscript.Sleep 20
objShell.SendKeys "{tab}"
Wscript.Sleep 20
objShell.SendKeys "{enter}"


----------------------------------------

This part switches to excel and copies the next cell down in the list. It then pastes it into the appropriate fields in the add user dialog.
enter.vbs

----------------------------------------

Set objShell = WScript.CreateObject("WScript.Shell")

objShell.AppActivate "Microsoft Excel"

Wscript.Sleep 500
objShell.SendKeys "{down}"
Wscript.Sleep 20
objShell.SendKeys "^c"
Wscript.Sleep 20

objShell.AppActivate "TargetComputerName ( 123.123.123.123 )"

Wscript.Sleep 500

objShell.SendKeys "^v"
Wscript.Sleep 20
objShell.SendKeys "{tab}"
Wscript.Sleep 20
objShell.SendKeys "^v"
Wscript.Sleep 20
objShell.SendKeys "{tab}"
Wscript.Sleep 20
objShell.SendKeys "{tab}"
Wscript.Sleep 20
objShell.SendKeys "^v"

Wscript.Sleep 200
objShell.AppActivate "TargetComputerName ( 123.123.123.123 )"


----------------------------------------

This part clicks the preset for RN accounts.
rnclick.au3

Advertisement:
----------------------------------------

#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

_WinWaitActivate("TargetComputerName ( 123.123.123.123 )","")
MouseClick("left",819,551,1)
MouseClick("left",1087,775,1)

#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
	WinWait($title,$text,$timeout)
	If Not WinActive($title,$text) Then WinActivate($title,$text)
	WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---

#endregion --- Au3Recorder generated code End ---


----------------------------------------

This part clicks the preset for LPN accounts
pnclick.au3

----------------------------------------
#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

_WinWaitActivate("TargetComputerName ( 123.123.123.123 )","")
MouseClick("left",690,597,1)
MouseClick("left",1095,770,1)

#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
	WinWait($title,$text,$timeout)
	If Not WinActive($title,$text) Then WinActivate($title,$text)
	WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---

#endregion --- Au3Recorder generated code End ---



----------------------------------------

This part confirms the selection.
confirm.vbs

----------------------------------------

Set objShell = WScript.CreateObject("WScript.Shell")

objShell.AppActivate "TargetComputerName ( 123.123.123.123 )"

Wscript.Sleep 500
objShell.SendKeys "{left}"
Wscript.Sleep 20
objShell.SendKeys "{enter}"
Wscript.Sleep 20


Set wshell=CreateObject("Wscript.Shell")
wshell.run "cmd /C " & chr(34) & "@echo " & chr(7) & chr(34),0,True

Wscript.Sleep 200
objShell.AppActivate "TargetComputerName ( 123.123.123.123 )"

----------------------------------------

This part copies the username out of excel and pastes it into the search box, then opens the user account.
enterbyusername.vbs

----------------------------------------

Set objShell = WScript.CreateObject("WScript.Shell")

objShell.AppActivate "Microsoft Excel"

Wscript.Sleep 900
objShell.SendKeys "{down}"
Wscript.Sleep 60
objShell.SendKeys "^c"
Wscript.Sleep 60

objShell.AppActivate "TargetComputerName ( 123.123.123.123 )"

Wscript.Sleep 700

objShell.SendKeys "^v"
Wscript.Sleep 60
objShell.SendKeys "{enter}"


Wscript.Sleep 700
objShell.AppActivate "TargetComputerName ( 123.123.123.123 )"

----------------------------------------

This part presses the reset password button and clicks yes to confirm.
pwreset.au3

----------------------------------------

#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

_WinWaitActivate("TargetComputerName ( 123.123.123.123 )","")
MouseClick("left",941,772,1)
MouseClick("left",853,579,1)

#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
	WinWait($title,$text,$timeout)
	If Not WinActive($title,$text) Then WinActivate($title,$text)
	WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---

#endregion --- Au3Recorder generated code End ---
----------------------------------------

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)