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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a HTA GUI for my VBScipts

Status
Not open for further replies.

yellowartist

IS-IT--Management
Aug 5, 2007
19
0
0
US
I am trying to add a GUI to run a few scripts from. I have decided to use HTA. I am not very familiar with HTA, and I'm getting better as VBScript. Here is the HTA code I have so far...

Code:
<head>
<title>Employee Separations</title>

<HTA:APPLICATION 
     APPLICATIONNAME="Employee Separations"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     BORDER = "THICK"
     MAXIMIZEBUTTON = "YES"
     mINIMIZEBUTTON = "YES"
     WINDOWSTATE="maximize"
>

</head>
<script language="VBScript">
    Sub GetWorkLog_excel
'Option Explicit
'on error resume next
'Dim objGroup, objuser, objExcel, iRow, strUser, iCol
'dim strExcelPath, objApp, strGroupName
'Dim StrDay, StrYear, StrMonth

StrMonth = Month(Date)
strYear = Right(Year(Date),2)
StrDay = Day(Date)


strExcelPath = "uncpath" & StrMonth & StrDay & StrYear & "_" & "work_Log" & ".xls"

set objExcel = CreateObject("Excel.Application")

' Create a new workbook.
objExcel.Workbooks.Add
' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Name = "Work_Log"
' Populate spreadsheet cells with user attributes.

Set objGroup = GetObject("LDAP://CN=GG_ES_ACCT_ADMIN,OU=Groups,DC=domain,DC=com")


Set objExcel = CreateObject("Excel.Application")
With objExcel
  .SheetsInNewWorkbook = 1
  .Workbooks.Add
  .Visible = false
   iRow=1

For Each strUser in objGroup.Member
    Set objUser =  GetObject("LDAP://" & strUser)
    .Cells(irow,1) = ("User Name: " & objUser.CN)
    .Cells(irow,3) = ("Role ID: " & objUser.sAMAccountName)
    .Cells(irow,5) = ("Object(s): " & objUser.distinguishedName)
    .Cells(irow,7) = ("Home Drive: " & objUser.homeDirectory)
    .Cells(irow,9) = ("Mailbox Store: " & objUser.homeMDB)
    .Cells(irow,11) = ("ALIAS: " & objuser.mailNickname)
'   .Cells(irow,13) = ("Email Address(es): " & Join(objUser.proxyAddresses))
'   .Cells(irow,15) = ("Groups: " & Join(objUser.memberof))

   irow=irow + 1
Next
End With
 
' Save the spreadsheet, close the workbook and exit.
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
'WScript.Echo "Spreadsheet Created"



'Set objApp = CreateObject("WScript.Shell") 

'objApp.Run "cmd /C net use n: uncpath& n: & EnumerateMembers" 

    End Sub

    Sub GetEnumerateMembers


strExcelPath = "uncpath"

set objExcel = CreateObject("Excel.Application")

' Create a new workbook.
objExcel.Workbooks.Add
' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Name = "Separations"
' Populate spreadsheet cells with user attributes.

Set objGroup = GetObject("LDAP://CN=GG_ES_ACCT_ADMIN,OU=Groups,OU=KBS,DC=Domain,DC=com")

Set objExcel = CreateObject("Excel.Application")
With objExcel
  .SheetsInNewWorkbook = 1
  .Workbooks.Add
  .Visible = false
   irow=1

 For Each strUser in objGroup.Member
    Set objUser =  GetObject("LDAP://" & strUser)
    .Cells(iRow,1) = objUser.CN
    .Cells(iRow,2) = objUser.sAMAccountName
    .Cells(iRow,3) = objUser.displayName
    .Cells(iRow,4) = objUser.Name
    .Cells(iRow,5) = objUser.distinguishedName
    .Cells(iRow,6) = objUser.mail
    .Cells(iRow,7) = objUser.extensionAttribute5
    .cells(iRow,8) = objuser.userPrincipalName
    .Cells(iRow,9) = objUser.GivenName
    .cells(iRow,10) = objuser.sn
    .cells(iRow,11) = objuser.Getex("proxyAddresses")
    .cells(iRow,12) = Strdate
    irow=irow + 1
 Next
End With

' Save the spreadsheet, close the workbook and exit.
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
'WScript.Echo "Spreadsheet Created"


Set objApp = CreateObject("WScript.Shell") 

    End Sub
</script>

<body>
<BODY bgColor=#cccccc>


<H><Center><B><BIG> KBS Employee Separations</BIG></B></Center></H>

<P><B>Step One: Create The Work Log </B><BR><BR>
<b>This will create an excel file and pull in the following information: <BR>
OBJECT(s):</b><I> (Active Directory’s DistinguishedName for each user” </i><BR>
<b>HOME DRIVE:</b><I>(Users home directory in Active Directory) </i><BR>
<B>MAILBOX STORE:</b><I> (User’s complete mailbox location and store)</i><BR>
<B>ALIAS: </b><I>(Users Email Alias)</i><BR>
<B>Global Groups:</b><I> (All global groups listed on the users account)</i><BR><BR></p>


<input type="button" value="WorkLog" name="run_button"  onClick="GetWorkLog_excel">
<BR>
<BR>

<p><B>Step Two: Process The Accounts </B><BR><BR>
<B>This will modify the accounts in Active Directory. </B><BR>
<B>It will do the following:</B><BR>
<B>1. Change the Account ID by adding a “1” in front of the existing ID. </B><BR>
<I>     i.e. SMITH32H will be changed to 1SMITH32H </I><BR>
<B>2. Add the current date in front of the Display Name.</B><BR>
<I>     i.e. Harrold Smith will be changed to 08/10/07 Harrold Smith</I><BR>
<B>3. Add “EXEMPT” to custom attribute 5</B><BR>
<B>4. Resets the users password</B><BR>
<B>5. Hide the user from the GAL</B><BR>
<B>6. Add mail restrictions and set to only receive from “*DL Email Team</B><BR>
<B>7. Add to the GG_KBS_ES group. </B><BR>
<B>8. Remove from PROXY_USERS, VPN, and SEAM global groups if found on the account.</B><BR></p>
<BR>
<B>Date:</B> <input type="text" id="strdate" value=""><BR>
<BR>


<input type="button" value="Modify Accounts" name="run_button"  onClick="GetEnumerateMembers">

</body>

I am receeiving an error when launching the "WorkLog" button. The error is:

Line: 50
Char: 5
Error: Could not complete the operation due to error 80005000.

Line 50 is: Set objUser = GetObject("LDAP://" & strUser)

Character 5 is the "s"

Any assistance is greatly appreciated!

Thanks.
 
It needs to be something like

Set objUser = GetObject("LDAP://" & strUser.ADSPath) or something that will provide the distinguished name of the user which you aren't currently providing.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
The return type of .member may be very different depending on how many members exist in the group or none. In order to preserve the construction of "for each strUser in xxx" construction, this is what you can rewrite the section involved.
[tt]
'... etc etc
[red]'[/red]For Each strUser in objGroup.Member
[blue]dim amembers 'array of members, put this dim upper is needed
select case typename(objGroup.Member)
case "Empty"
amembers=array()
case "String"
amembers=array(objGroup.Member)
case "Variant()"
amembers=objGroup.Member
case else
amembers=array()
end select[/blue]
For Each strUser in [blue]amembers[/blue]
Set objUser = GetObject("LDAP://" & strUser)
'etc etc...
Next
'etc etc...
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top