#169668 - 2006-10-20 09:10 PM
Re: Inputing users/groups into scripts
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
I am posting my script to try and make my intentions more clear. The red line is where my knowledge lacks (OK, one of the places my knowledge lakcs!) And I'll take a moment to say I really appreciate all the people who have the talent to creat UDFs and who post them in the UDF libraries for us newbies!
Code:
;NAME AddStudentToXeroxPrinterGroup.kix ;AUTHOR Jeremy Schubert ;PURPOSE Allows to add students to the Xerox printer group which will allow the students ;to print to that printer.
Break On $System = CreateObject("Kixtart.System")
If Not $System $nul= MessageBox("KiXforms Not Initiated. This Script Will Now Close.","Error",16) Quit() EndIf
HTMLInputBox("Please enter the user name of the student to be added to the Xerox Printer Group.", "Add Students To Xerox Printer Group","Names","SUBMIT","","","CANCEL","")
$usernames=names ;value of the box that shows in the HTMLInputBox function
For Each $username in $usernames " GroupAdd (CSSDSTU, GG047-XeroxPrinter, $username) Next
While $Form.Visible $nul = Execute($Form.DoEvents) Loop Exit 1
Function HTMLInputBox() - Displays an Input-Box via IE
; Function HTMLInputBox() - Displays an Input-box via IE ; ; Author: Steve O ; posted as UDF by NTDOC ; Posted in Beta forum - http://www.kixtart.org/ubbthreads/showthreaded.php?Cat=0&Number=77407 ; ; ACTION: Displays an Input-box that allows a user to input a string. This box is HTML based and ; uses the Internet Explorer Application object. ; ; SYNTAX: HTMLInputBox("HTML Message", OPTIONAL "Window Title","Default Value","Button Text","Text Color", ; "Background Color", "Alt Button Text","Alt Button Return Value") ; ; Version: 1.0 ; ; Date: Sep 27 2001 ; ; Date Revised: ; ; Revision Reason: ; ; PARAMETERS: ; HTML Message: The message for the Input Box. ex: What is your favorite color? ; Note: This can accept any HTML code, so go to town! Also Note: the tag is enabled, so if you want to do ; custom HTML, put as the first tag. ; Window Title: ( OPTIONAL ) The title of the HTML Input Box Window. If blank, defaults to "Question...". ; Default Value: ( OPTIONAL ) The default value for the box which will show when the box appears. ; If blank, defaults to blank. ; Button Text: ( OPTIONAL ) The text on the main button. If blank, default is "SUBMIT". ; Text Color: ( OPTIONAL ) The color of text on the input box. If blank, this defaults to black. ; Note: This can be overridden by including additional HTML tags in the HTML Message. ; Background Color: ( OPTIONAL ) The color of the background of the HTML form. Defaults to silver. ; Alt Button Text: ( OPTIONAL ) If this is specified, an alternate button will appear on the form and ; if clicked, the function will (by default) return "-1". This is useful as a "HELP" button, or ; for many other purposes. ; Alt Button Return Value: ( OPTIONAL ) If the Alt button is needed, and -1 is a potential legitimate ; return value for the main submit button, you can specify an alternate return value for the alternate button. ; ; REMARKS: ; This has been tested by the author on Win 98 and Win 2k machines. It should require at least IE 4.0 ; to function, however it does not check the IE version before executing. ; ; RETURNS: ; The string in the text box, or another value if the "Alternate button" is pressed. The alternate value ; defaults to -1, but can be changed by specifying the "Alt Button Return Value". ; ; Dependencies: IE, KiXtart 4.x ; ; EXAMPLE: ; HTMLInputBox("What is your favorite color?","Color Quiz","Red","Submit Me!","Black","Yellow","I don't know!!!") ; ; Source:
Function HTMLInputBox($L_Prompt, OPTIONAL $L_Title,$L_DefaultValue,$L_ButtonText,$L_TextColor,$L_BGColor,$L_AltButtonText,$L_AltButtonReturnValue) Dim $HTML, $AppIE, $SF If $L_Title = "" $L_Title = "Question..." EndIf If $L_ButtonText = "" $L_ButtonText = "Submit" EndIf If $L_AltButtonReturnValue = "" $L_AltButtonReturnValue = -1 EndIf Select Case $L_TextColor = "Black" $L_TextColor = "000000" Case $L_TextColor = "Silver" $L_TextColor = "C0C0C0" Case $L_TextColor = "Gray" $L_TextColor = "808080" Case $L_TextColor = "White" $L_TextColor = "FFFFFF" Case $L_TextColor = "Maroon" $L_TextColor = "800000" Case $L_TextColor = "Red" $L_TextColor = "FF0000" Case $L_TextColor = "Purple" $L_TextColor = "800080" Case $L_TextColor = "Fuchsia" $L_TextColor = "FF00FF" Case $L_TextColor = "Green" $L_TextColor = "008000" Case $L_TextColor = "Lime" $L_TextColor = "00FF00" Case $L_TextColor = "Olive" $L_TextColor = "808000" Case $L_TextColor = "Yellow" $L_TextColor = "FFFF00" Case $L_TextColor = "Navy" $L_TextColor = "000080" Case $L_TextColor = "Blue" $L_TextColor = "0000FF" Case $L_TextColor = "Teal" $L_TextColor = "008080" Case $L_TextColor = "Aqua" $L_TextColor = "00FFFF" Case $L_TextColor = "" $L_TextColor = "000000" EndSelect Select Case $L_BGColor = "Black" $L_BGColor = "000000" Case $L_BGColor = "Silver" $L_BGColor = "C0C0C0" Case $L_BGColor = "Gray" $L_BGColor = "808080" Case $L_BGColor = "White" $L_BGColor = "FFFFFF" Case $L_BGColor = "Maroon" $L_BGColor = "800000" Case $L_BGColor = "Red" $L_BGColor = "FF0000" Case $L_BGColor = "Purple" $L_BGColor = "800080" Case $L_BGColor = "Fuchsia" $L_BGColor = "FF00FF" Case $L_BGColor = "Green" $L_BGColor = "008000" Case $L_BGColor = "Lime" $L_BGColor = "00FF00" Case $L_BGColor = "Olive" $L_BGColor = "808000" Case $L_BGColor = "Yellow" $L_BGColor = "FFFF00" Case $L_BGColor = "Navy" $L_BGColor = "000080" Case $L_BGColor = "Blue" $L_BGColor = "0000FF" Case $L_BGColor = "Teal" $L_BGColor = "008080" Case $L_BGColor = "Aqua" $L_BGColor = "00FFFF" Case $L_BGColor = "" $L_BGColor = "C0C0C0" EndSelect $HTML = '' + '' + '' + $L_Title + '' + $L_Prompt + '' + ' ' + '' $AppIE = CreateObject("InternetExplorer.Application") ;Set IE Object Properties $appIE.top = 30 $appIE.left = 30 $appIE.height = 350 $appIE.width = 500 $appIE.addressbar = 0 $appIE.menubar = 0 $appIE.toolbar = 0 $appIE.statusbar = 0 $appIE.resizeable = 0 $appIE.navigate("about:blank") While $AppIE.busy <> 0 And @ERROR = 0 Loop ;Write the HTML code to the document $AppIE.document.write($HTML) While $AppIE.busy <> 0 And @ERROR = 0 Loop ;Make IE visible and set focus $AppIE.visible = 1 $SF = SetFocus("about:blank - Microsoft Internet Explorer") $AppIE.document.GetElementById("Answer").focus Dim $L_LastBoxValue,$L_LastBoxValueCache While $appIE.document.GetElementById("Submitted").value = 0 If $appIE.document.GetElementById("Submit").value = " " + $L_ButtonText + " " If $appIE.document.GetElementById("Answer").value <> "" $L_LastBoxValue = $appIE.document.GetElementById("Answer").value If $L_LastBoxValue <> "" $L_LastBoxValueCache = $L_LastBoxValue EndIf EndIf EndIf Loop If $AppIE.document.GetElementById("Submitted").value = 2 $HTMLInputBox = $L_AltButtonReturnValue Else $HTMLInputBox = $L_LastBoxValueCache EndIf $AppIE.QUIT $AppIE = "" EndFunction GroupAdd() - Ads a User/Group to a Group Global/Local
Code: --------------------------------------------------------------------------------
;NAME GroupAdd ; ;AUTHOR ??? ; ;ACTION Add's a object (user or group) to a group (global or local) ; ;SYNTAX GroupAdd(Target, Group, Object To add) ; ;PARAMETERS Target ; The Domain name or Workstation To work with. For faster workstation ; execution, include the Domain Name that the workstation is a meber of. ; ; "Kixtart/beanbag" would be working with the workstation Beanbag In the ; Kixtart domain ; ; Group ; The Group you want To add To ; ; Object To add ; This can be a local group or a userid, depending on what type of group ; the Group variable is. Always try To give the full name of the object. ; ; ;RETURNS @ERROR code ; ;REMARKS ADSI com object must be installed. ; ;EXAMPLES ;this adds the domain user "testuser" To the Global group "Domain Admins" ; $nul = groupadd("kixtart","Domain admins","testuser") ; ; ;this adds the user "testuser" In the domain "kixtart" To the local administrators ; ;group on the workstation beanbag ; $nul = Groupadd("kixtart/beanbag", "administrators", "kixtart\testuser") Function GroupAdd($Target, $Group, $ObjToAdd) Dim $target, $group, $OBJToAdd, $obj, $objhome If SubStr($target,1,2) = '\\' $target = SubStr($target,3,Len($target)) EndIf If InStr($objtoadd,'\') <> 0 $objtoadd = Split($objtoadd,'\') If UBound($objtoadd) <> 1 Exit 13 EndIf $objhome = $objtoadd[0] $obj = $objtoadd[1] Else $objhome = $target $obj = $objtoadd EndIf $group = GetObject('WinNT://' + $target + '/' + $group) If VarType($group) = 9 And @ERROR = 0 $group.Add ('WinNT://'+$objhome+'/'+$obj) Else $GroupAdd = @ERROR Exit @ERROR EndIf $GroupAdd = @ERROR Exit @ERROR EndFunction
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|