Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


  • Content count

  • Donations

  • Joined

  • Last visited

Community Reputation

0 Neutral

About navyjax2

  • Birthday 10/20/1979

Contact Methods

  • AIM
  • Website URL
  1. See http://www.vbforums.com/showthread.php?t=502947 for sending an attachment from a URL. You can save a string to a textfile using a StreamWriter command, then take that file using the methods at that link and attach it (basically similar to what you saw at your link, just using an string fileUrl = "http://localhost/mytextfile.txt"; string[] fileName = fileUrl.Split('/'); string file = fileName[fileName.Length - 1]; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileUrl); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); // Use the file name found by splitting on the URL Attachment data = new Attachment(stream, file, response.ContentType); // Add the information for the file ContentDisposition disposition = data.ContentDisposition; disposition.FileName = file; disposition.CreationDate = File.GetCreationTime(file); disposition.ModificationDate = File.GetLastWriteTime(file); disposition.ReadDate = File.GetLastAccessTime(file); // Add the file attachment to this e-mail message. message.Attachments.Add(data); kind of method.) You can't take a simple string and send it as an attachment without it becoming a file in-between, at some point. Just write your string/text to a text file. (Above code assumes anonymous authentication to the URL. Can also use Windows authentication by passing request.Credentials = CredentialCache.DefaultCredentials) -Tom
  2. Add User Hta

    Well, I had meant that I was indeed trying it all together, sorry that wasn't clear. I found out the reason for the error, though. If you don't commit the creation of the user to Active Directory first, it has no object to assign a password to. So you have to do a objUser.SetInfo BEFORE you can do a objUser.SetPassword strPassword So now I'm building the rest of my HTA - I'm including stuff like the Password will never expire and User cannot change password checkboxes. Still have the group thing to try to incorporate, too. I don't know where the groups like "Domain Admins", etc. (the global groups) live at to get a "CN=" name in the first place. I've got a box that will poll the groups (local and global) from earlier code of yours: Function ComputerGroups() strComputer = "." Set ObjList = document.getElementById("groupSelect") Set colGroups = GetObject("WinNT://" & strComputer) colGroups.Filter = Array("group") For Each objGroup In colGroups set oOption = document.createElement("OPTION") ObjList.Options.add oOption oOption.innerText = objGroup.Name oOption.value = CT If CT MOD 2 Then oOption.style.backgroundcolor = "#C9C9C9" oOption.style.color = "#3A3A3A" Else oOption.style.backgroundcolor = "#E9E9E9" oOption.style.color = "#235779" End If CT = CT + 1 Next CT = 0 End Function I declared "CT" up there as a global variable = 0 in my JavaScript, which includes a window.onload=function() { ComputerGroups(); }, just for those that might be trying to integrate the above into their own functions. The above is used by a selectbox on the form itself: <SELECT id="groupSelect" name="groupSelect" class="SelectBox"> <OPTION value="0"></OPTION> </SELECT><BR> Can the oOption.value be set to the group CN name instead of CT? How would it retrieve that automatically? Tom
  3. Add User Hta

    Yeah, that will give the value of the password box (though in my case I have to reference document.getElementById("pword").value for an <INPUT type="password" ID="pword" name="pword" /> tag), but I knew how do get that. I set the following: dim strPassword strPassword = document.getElementById("pword") but if I were to try to build a user with the following: dim userAccount, firstName, lastName firstName = document.getElementById("F_Name") lastName = document.getElementById("L_Name") userAccount = Left(firstName,1) & lastName ' First Initial, Last Name Set objUser = objContainer.Create("User", "cn=" & userAccount) objUser.Put "samAccountName",userAccount objUser.Put "givenName",firstName objUser.Put "sn",lastName objUser.SetPassword strPassword it's that last line that will cause an error. Why is that? I also tried objUser.SetPassword(strPassword) which I would think would work from http://www.microsoft.com/technet/scriptcen...04/hey1015.mspx, but it didn't. Error is "There is no such object on the server." and the user is not created in the specified OU, where, if I leave just that line out, it will be. Tom
  4. Add User Hta

    Looks good - the user was added with a first initial, last name user account. I did have to correct some single-quotes that should've been double-quotes, but that's ok I found out that was what was causing my errors when running your HTA scripts before. A couple of issues I'm trying to resolve - 1) Assigning a password. I created a textbox, i.e. "<INPUT type="password" id="pWord" /> and am trying to use something like Set objUser = objContainer.Create("User", "cn=" & userAccount) objUser.setPassword document.getElementById("pWord").text (where userAccount is the variable holding the username to be given to my user) but it would come back with an error on the line number containing that, and if I commented that line out, the error would go away. I'd just like to be able to give a user a generic password and it not me that of the domain admin running the script, and would like to not have to change it once the user is made. and 2) Adding groups to the user as it is created - I found some code that's supposed to let you do this, but it seems like it's different if you are using local groups Set colAccounts = GetObject("WinNT://" & strComputer & "") Set objGroup = GetObject("WinNT://" & strComputer & "/" & A3 & ",group") objGroup.Add(objUser.ADsPath) vs. global groups strGroup = "CN=" & groupName Set objGroup = GetObject("LDAP://" & strGroup & strDNSDomain) Set objUser = GetObject("LDAP://CN=" & fullName & "," & strOUs & strDNSDomain) objGroup.add(objUser.ADsPath) . Is there a generic assignment string either way, or a way to tell which way you should go, that I could base off of a drop-down box's value without a lot of effort to tell which is which? Thanks, Tom
  5. Add User Hta

    The HTA Applications didn't work for me, kept giving me "Do you want to keep running scripts on this page?" errors, but the EXE was great! I didn't know what the "Local Users" section was for, though... it doesn't really apply to the account you are going to create. Just for follow-on to what your program does, might be nice to have a First Name and Last Name box, then make the user name automatically be the first initial and last name (i.e. John Doe = jdoe), and have that populate into the account on creation. Just a thought. I saw you put a lot of work into this. I'm developing something similar. Code I'm using for the above is similar to: (In HTML page where I get my information from:) <INPUT type="textbox" id="txtFirstName" size="30" /> <INPUT type="textbox" id="txtLastName" size="30" /> <INPUT type="button" value="Add User" onclick="addUser()" /> (In the SCRIPT section:) Sub addUser() 'Establish user info dim firstName, lastName, userAccount, fullName dim objRootLDAP, objString, objContainer, objUser, objShell firstName = document.getElementById("txtFirstName").value lastName = document.getElementById("txtLastName").value userAccount = Left(firstName,1) & lastName fullName = firstName & " " & lastName ' Bind to Active Directory Set objRootLDAP = GetObject("LDAP://rootDSE") objString = "LDAP://OU=Test,DC=DOMAIN,DC=com" Set objContainer = GetObject(objString) 'Build user Set objUser = objContainer.Create("User", "cn=" & userAccount) objUser.Put "samAccountName", userAccount objUser.Put "givenName", fullName objUser.SetInfo ' Optional section to launch Active Directory Uses and Users Set objShell = CreateObject("WScript.Shell") objShell.Run "%systemroot%\system32\dsa.msc" Set objContainer = Nothing WScript.Quit End Sub I have a drop-down similar to yours, also, for the groups that I just hard-coded with values.... been having trouble getting the group listing dynamically and applying it, but otherwise above is the basics for anyone that is trying to get started somewhere. -Tom