Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
In the InitVariables section I have used a .INI file and default the name to a particular server
Once the program ends, I update/create the .INI file. If the default server should change, I can just update this file.
The program starts by grabbing your current user ID (which you can change), you can then enter your current and new password.
For those new to Dialog boxes, this program shows how to:
Disable / Enable buttons
Update Static Text
Clear Edit fields
Retrieve Edit fields into variables
Disable dialog box when a process may take a while and you need the hour glass
Detect a text change in and edit box
Trap the OK button on the dialog box
Have fun
Barry
AddExtender("WWWNT34i.DLL") ;*********************************************************************************************************************** ; Read from the INI file to get program defaults ;*********************************************************************************************************************** #DefineSubroutine InitVariables(WorkingDir) DomainName =IniReadPvt("MISC", "DOMAINNAME", "DefaultDomainHere", StrCat(WorkingDir,"Password.INI")) return #EndSubroutine ;*********************************************************************************************************************** ; Write from the INI file to get program defaults ;*********************************************************************************************************************** #DefineSubroutine WriteIniVariables(WorkingDir) DomainName =IniWritePvt("MISC", "DOMAINNAME", DomainName, StrCat(WorkingDir,"Password.INI")) return #EndSubroutine ;*********************************************************************************************************************** #DEFINESUBROUTINE ChangePassword(Handle,DialogMessage,DialogControlID,param4,param5) switch (DialogMessage) case 0 DialogProcOptions(Handle, 2, 1) ; Pass Push Button selection changes. DialogProcOptions(Handle, 5, 1) ; Text has changed break; case 2 if DialogControlID == 1 then ;Ok Hit LoginID = StrTrim(DialogControlGet(Handle, 5,3)) OldPassword = StrTrim(DialogControlGet(Handle, 7,3)) NewPassword = StrTrim(DialogControlGet(Handle, 9,3)) ConfirmPassword = StrTrim(DialogControlGet(Handle, 11,3)) if StrLen(OldPassword) == 0 then Message('Invalid Password','Your Current Password Is Invalid Password') DialogControlState(Handle, 7, 1, 0) ;Give the edit box focus return -2 end if if NewPassword <> ConfirmPassword then Message('Password Mismatch','The New Passwords You Entered Does Not Match') DialogControlState(Handle, 9, 1, 0) ;Give the edit box focus return -2 end if DialogControlSet(Handle, 12, 4, "Results: Please Wait........") ;Update Static Text DialogControlState(Handle, 1,3,2) ;turn off OK DialogProcOptions(Handle, 1000, 2) ; Set Dialog To Wait A While ErrorMode(@OFF) rslt = wntChgPswd(DomainName, LoginID, OldPassword, NewPassword) RC = LastError() ErrorMode(@CANCEL) if (RC != 0) then ErrorMsg = IntControl(34,-1,0,0,0) Msg = "Results: " if RC == 562 then Msg = StrCat(Msg,"Invalid Login ID - Your ID May Be Invalid Or Not Configured") DialogControlSet(Handle, 9, 3, "") ;New Password DialogControlSet(Handle,11, 3, "") ;Confirm Password DialogControlState(Handle, 5, 1, 0) ;Give the edit box focus end if if RC == 515 then Msg = StrCat(Msg,"Invalid Password - The Password You Entered Is Invalid") DialogControlSet(Handle, 7, 3, "") ;New Password DialogControlSet(Handle, 9, 3, "") ;New Password DialogControlSet(Handle,11, 3, "") ;Confirm Password DialogControlState(Handle, 7, 1, 0) ;Give the edit box focus end if if RC == 589 then Msg = StrCat(Msg,"Error Changing Password - Invalid Server/Domain Name") DialogControlSet(Handle, 9, 3, "") ;New Password DialogControlSet(Handle,11, 3, "") ;Confirm Password DialogControlState(Handle, 7, 1, 0) ;Give the edit box focus end if DialogControlSet(Handle, 12, 4, Msg) ;Update Static Text with error meaning Message("Error",StrCat("Password Was Not Updated ",@CRLF,'Error =', ErrorMsg)) else if rslt DialogControlSet(Handle, 12, 4, "Results: Password Successfully Changed") ;Update Static Text Message("Password","Successfully Changed!") ;blank out the controls after DialogControlSet(Handle, 7, 3, "") ;Old Password DialogControlSet(Handle, 9, 3, "") ;New Password DialogControlSet(Handle,11, 3, "") ;Confirm Password else DialogControlSet(Handle, 12, 4, "Results: Password Not Changed") ;Update Static Text Message("Password","Not changed") end if end if DialogProcOptions(Handle, 1000, 0) ; Restore Dialog return -2 end if break case 5 if DialogControlID == 9 then ;Make sure the new password has text in it t1 = StrTrim(DialogControlGet(Handle, 9,3)) ;New Password if StrLen(t1) > 0 then DialogControlState(Handle, 1,4,2) ;turn on OK else DialogControlState(Handle, 1,3,2) ;turn off OK end if end if break endswitch return -1 :Cancel return #ENDSUBROUTINE ;*********************************************************************************************************************** WorkingDir = DirGet ( ) WorkingDir = FilePath(IntControl(1004,0,0,0,0)) ; - working directory of an executable InitVariables(WorkingDir) LoginID = wntGetUser(@default) ;Get Login ID MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`Change Password For Domain / Server` MyDialogX=-01 MyDialogY=-01 MyDialogWidth=220 MyDialogHeight=137 MyDialogNumControls=012 MyDialogProcedure=`ChangePassword` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`175,119,036,012,PUSHBUTTON,DEFAULT,"&OK",1,1,2,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`139,119,036,012,PUSHBUTTON,DEFAULT,"&Cancel",2,2,0,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`007,029,204,074,GROUPBOX,DEFAULT,"Change Password",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`037,013,026,010,STATICTEXT,DEFAULT,"Login ID:",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog005=`069,011,068,012,EDITBOX,LoginID,DEFAULT,DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog006=`019,043,044,010,STATICTEXT,DEFAULT,"Old Password:",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog007=`069,039,134,012,EDITBOX,OldPassword,DEFAULT,DEFAULT,2,16,DEFAULT,DEFAULT,DEFAULT` MyDialog008=`019,063,044,010,STATICTEXT,DEFAULT,"New Password:",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog009=`069,061,134,012,EDITBOX,NewPassword,DEFAULT,DEFAULT,4,16,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`019,081,044,010,STATICTEXT,DEFAULT,"Confirm Password:",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog011=`069,079,134,012,EDITBOX,ConfirmPassword,DEFAULT,DEFAULT,6,16,DEFAULT,DEFAULT,DEFAULT` MyDialog012=`031,105,172,008,STATICTEXT,DEFAULT,"Results:",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") WriteIniVariables(WorkingDir) exit
Here's another script to change multiple domain passwords. Add/change domains in the domains.ini file included with the script. Also uses dynamic dialogs. Domains.ini
[Domain List] List=CMUTUAL,CMUTUALM,CMUTUALTEST,CUNIONS,CUNIONSMChange Domain Passwords.wbt
; ====================================================================== ; ; WinBatch Source File ; ; NAME: Change Domain Passwords ; ; AUTHOR: Adam Jongewaard , CUNA Mutual Group ; DATE : 11/1/2004 ; ; ; ======================================================================== AddExtender("wwwnt34i.dll") #DefineSubRoutine DEFAULT_Init_Variables() pb_MyD_OK = 1 pb_MyD_Close = 2 ib_MyD_DomainList = 3 ib_MyD_DomainList_list = 3 st_MyD_Domains = 4 eb_MyD_oldpw = 5 eb_MyD_newpw = 6 eb_MyD_confpw = 7 st_MyD_OldPassword = 8 st_MyD_NewPassword = 9 st_MyD_ConfirmPassword = 10 eb_MyD_username = 11 st_MyD_Username = 12 #EndSubRoutine #DefineSubRoutine Init_Dialog_Constants() ;DialogprocOptions Constants MSG_INIT = 0 ; The one-time initilization MSG_TIMER = 1 ; Timer event MSG_BUTTONPUSHED = 2 ; Pushbutton or Picturebutton MSG_RADIOPUSHED = 3 ; Radiobutton clicked MSG_CHECKBOX = 4 ; Checkbox clicked MSG_EDITBOX = 5 ; Editbox or Multilinebox MSG_FILESELECT = 6 ; Filelistbox MSG_ITEMSELECT = 7 ; Itembox MSG_COMBOCHANGE = 8 ; Combobox/Droplistbox MSG_CALENDAR = 9 ; Calendar date change MSG_SPINNER = 10 ; Spinner number change MSG_CLOSEVIA49 = 11 ; Close clicked (Enabled via Intcontrol 49) MSG_FILEBOXDOUBLECLICK = 12 ; Get double-click message on a FileListBox MSG_ITEMBOXDOUBLECLICK = 13 ; Get double-click message on an ItemBox DPO_DISABLESTATE = 1000 ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog DPO_CHANGEBACKGROUND = 1001 ; -1=GetSetting otherise bitmap or color string ;DialogControlState Constants DCSTATE_SETFOCUS = 1 ; Give Control Focus DCSTATE_QUERYSTYLE = 2 ; Query control's style DCSTATE_ADDSTYLE = 3 ; Add control style DCSTATE_REMOVESTYLE = 4 ; Remove control style DCSTATE_GETFOCUS = 5 ; Get control that has focus DCSTYLE_INVISIBLE = 1 ; Set Control Invisible DCSTYLE_DISABLED = 2 ; Set Control Disabled DCSTYLE_NOUSERDATA = 4 ; Note: Setable via DialogControlState function ONLY SPINNER control only DCSTYLE_READONLY = 8 ; Sets control to read-only (user cannot type in data) EDITBOX MULTILINEBOX SPINNER DCSTYLE_PASSWORD = 16 ; Sets 'password mode' where only *'s are displayed EDITBOX DCSTYLE_DEFAULTBUTTON = 32 ; Sets a button as a the default button PUSHBUTTON PICTUREBUTTON DCSTYLE_DIGITSONLY = 64 ; Set edit box to accept digits only EDITMOX MULTILINEBOX DCSTYLE_FLAT = 128 ; Makes a 'flat' hyperlink-looking button PUSHBUTTON PICTUREBUTTON DCSTYLE_HEIGHT = 256 ; Turns off automatic height adjustment on ItemBoxes and FileListBoxes DCSTYLE_CENTER = 512 ; Center Text in VARYTEXT and STATICTEXT Controls DCSTYLE_RIGHT = 1024 ; Right Justify Text in VARYTEXT and STATICTEXT Controls ;DialogControlSet / DialogControlGet Constants DC_CHECKBOX = 1 ; CHECKBOX DC_RADIOBUTTON = 2 ; RADIOBUTTON DC_EDITBOX = 3 ; EDITBOX MULTILINEBOX DC_TITLE = 4 ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON DC_ITEMBOXCONTENTS = 5 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_ITEMBOXSELECT = 6 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_CALENDAR = 7 ; CALENDAR DC_SPINNER = 8 ; SPINNER DC_MULTITABSTOPS = 9 ; MULTILINEBOX DC_ITEMSCROLLPOS = 10 ; ITEMBOX FILELISTBOX DC_BACKGROUNDCOLOR = 11 ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX DC_PICTUREBITMAP = 12 ; PICTURE PICTUREBUTTON DC_TEXTCOLOR = 13 ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FIELLISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX DC_ITEMBOXADD = 14 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_ITEMBOXREMOVE = 15 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_RADIOCONTROL = 16 ; RADIOBUTTON #EndSubRoutine #DefineSubRoutine DEFAULT(MyD_Handle,DMsg,DCID,resvd4,resvd5) Switch (DMsg) Case msg_init ; Dialog Initialization username = Environment("USERNAME") MyDialogCaption=`Change Domain Passwords for %username%` domains = StrReplace(IniReadPvt("Domain List","List","",StrCat(DirGet(),"domains.ini")),",",@TAB) DialogControlSet(MyD_Handle,eb_MyD_username,dc_editbox,username) DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) DialogControlSet(MyD_Handle,ib_MyD_DomainList,DC_ITEMBOXCONTENTS,domains) DialogProcOptions(MyD_Handle, msg_closevia49,-1) ; Close selected (IntControl(49....) (1-On, 0-Off). DialogProcOptions(MyD_Handle, dpo_disablestate,0) ; Dialog Disable (1-Disable, 2-Wait cursor, 0-Enable). DialogProcOptions(MyD_Handle, dpo_changebackground,-1) ; Change Dialog Background (Bitmap File or RGB String). DialogProcOptions(MyD_Handle, msg_buttonpushed,1) ; PushButton/PictureButton. DialogProcOptions(MyD_Handle, msg_itemselect,1) ; ItemBox. DialogProcOptions(MyD_Handle, msg_editbox,1) ; EditBox or Multi-LineBox. Break Case msg_closevia49 ; Close Break Case msg_editbox ; Edit/MultiLine Box Switch(DCID) Case eb_MyD_oldpw oldpw = DialogControlGet(MyD_Handle,eb_MyD_oldpw,dc_editbox) If newpw <> "" && oldpw <> "" && confpw <> "" && DomainList <> "" && username <> "" Then DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_REMOVESTYLE,DCSTYLE_DISABLED) Else DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) Break Case eb_MyD_newpw newpw = DialogControlGet(MyD_Handle,eb_MyD_newpw,dc_editbox) If newpw <> "" && oldpw <> "" && confpw <> "" && DomainList <> "" && username <> "" Then DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_REMOVESTYLE,DCSTYLE_DISABLED) Else DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) Break Case eb_MyD_confpw confpw = DialogControlGet(MyD_Handle,eb_MyD_confpw,dc_editbox) If newpw <> "" && oldpw <> "" && confpw <> "" && DomainList <> "" && username <> "" Then DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_REMOVESTYLE,DCSTYLE_DISABLED) Else DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) Break Case eb_MyD_username username = DialogControlGet(MyD_Handle,eb_MyD_username,dc_editbox) If newpw <> "" && oldpw <> "" && confpw <> "" && DomainList <> "" && username <> "" Then DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_REMOVESTYLE,DCSTYLE_DISABLED) Else DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) Break EndSwitch Break Case msg_itemselect ; Item Box Switch(DCID) Case ib_MyD_DomainList DomainList = DialogControlGet(MyD_Handle,ib_MyD_DomainList,dc_itemboxselect) DomainList_list = DialogControlGet(MyD_Handle,ib_MyD_DomainList,dc_itemboxcontents) If newpw <> "" && oldpw <> "" && confpw <> "" && DomainList <> "" && username <> "" Then DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_REMOVESTYLE,DCSTYLE_DISABLED) Else DialogControlState(MyD_Handle,pb_MyD_OK,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) Break EndSwitch Break Case msg_buttonpushed ; PushButtion Switch(DCID) Case pb_MyD_OK nSelection = DialogControlGet(MyD_Handle,pb_MyD_OK,dc_title) If newpw <> confpw Then Message("Try Again","The new password you entered does not match.") Break EndIf If newpw == oldpw Then Message("Try Again","The old password and new password specified are the same. You must use a different password.") Break EndIf If StrLen(newpw) < 6 Then Message("Try Again","The new password you entered is not greater than 6 characters.") Break EndIf If StrScan(newpw,"1234567890",1,@FWDSCAN) == 1 Then Message("Try Again","The new password you entered must start with a letter.") Break EndIf succ = 0 For i = 1 to ItemCount(DomainList,@TAB) Domain = ItemExtract(i,DomainList,@TAB) ErrorMode(@OFF) rslt = wntChgPswd(Domain, username, oldpw, newpw) ErrorMode(@CANCEL) If rslt == 1 Then succ = succ + 1 Else tryagain = AskYesNo("Change Password - Fail","Password for %Domain% domain not changed successfully. Would you like to try again?") If tryagain == @YES Then Message("Note:","When selecting domains to change passwords for, be sure to exclude any that were already changed successfully.") Break Else Message("Password not being changed...","Remeber that the %domain% domain password was not changed for %username%.") EndIf EndIf Next Message("Change Password - Success",StrCat("Password for %succ% of ",ItemCount(DomainList,@TAB)," domain(s) changed successfully.")) Return(-2) Case pb_MyD_Close nSelection = DialogControlGet(MyD_Handle,pb_MyD_Close,dc_title) Return(-1) EndSwitch Break EndSwitch Return -2 #EndSubRoutine IntControl(49,3,0,0,0) DEFAULT_Init_Variables() Init_Dialog_Constants() MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`Change Domain Password` MyDialogX=057 MyDialogY=116 MyDialogWidth=294 MyDialogHeight=093 MyDialogNumControls=012 MyDialogProcedure=`DEFAULT` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`213,073,036,012,PUSHBUTTON,DEFAULT,"OK",1,6,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`129,073,036,012,PUSHBUTTON,DEFAULT,"Close",0,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`005,011,100,074,ITEMBOX,DomainList,DEFAULT,DEFAULT,5,DEFAULT,"Microsoft Sans Serif|6656|40|34","0|0|0",DEFAULT` MyDialog004=`005,003,030,008,STATICTEXT,DEFAULT,"Domains",DEFAULT,4,DEFAULT,"Microsoft Sans Serif|6656|40|34","0|0|0",DEFAULT` MyDialog005=`169,025,116,012,EDITBOX,oldpw,DEFAULT,DEFAULT,2,16,DEFAULT,DEFAULT,DEFAULT` MyDialog006=`169,041,116,012,EDITBOX,newpw,DEFAULT,DEFAULT,3,16,DEFAULT,DEFAULT,DEFAULT` MyDialog007=`169,057,116,012,EDITBOX,confpw,DEFAULT,DEFAULT,4,16,DEFAULT,DEFAULT,DEFAULT` MyDialog008=`123,027,044,008,STATICTEXT,DEFAULT,"Old Password",DEFAULT,8,DEFAULT,"Microsoft Sans Serif|6656|40|34","0|0|0",DEFAULT` MyDialog009=`121,043,046,008,STATICTEXT,DEFAULT,"New Password",DEFAULT,9,DEFAULT,"Microsoft Sans Serif|6656|40|34","0|0|0",DEFAULT` MyDialog010=`111,059,056,008,STATICTEXT,DEFAULT,"Confirm Password",DEFAULT,10,DEFAULT,"Microsoft Sans Serif|6656|40|34","0|0|0",DEFAULT` MyDialog011=`169,009,116,012,EDITBOX,username,DEFAULT,DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog012=`135,011,032,008,STATICTEXT,DEFAULT,"Username",DEFAULT,12,DEFAULT,"Microsoft Sans Serif|6656|40|34","0|0|0",DEFAULT` ButtonPushed=Dialog("MyDialog")
Article ID: W16514
File Created: 2005:02:18:12:21:12
Last Updated: 2005:02:18:12:21:12