+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
Scripts Thread, NEEDED: A Script to create a text file based on user input in Coding and Web Development; Hello all, I was wondering if anyone could help me by giving me a basic VBScript to create a text ...
  1. #1

    Join Date
    Nov 2009
    Location
    somewhere
    Posts
    23
    Thank Post
    28
    Thanked 4 Times in 3 Posts
    Rep Power
    0

    NEEDED: A Script to create a text file based on user input

    Hello all,

    I was wondering if anyone could help me by giving me a basic VBScript to create a text file e.g C:\File.txt and write stuff to the txt file based on user input e.g. Name= User Input

    If anyone could give me a base script including svaing the file it would be helpful,

    Thanks

  2. #2

    featured_spectre's Avatar
    Join Date
    Nov 2008
    Posts
    12,505
    Thank Post
    1,684
    Thanked 2,054 Times in 1,491 Posts
    Blog Entries
    2
    Rep Power
    464
    you want to create something that is essentially a keylogger?

  3. #3

    Join Date
    Nov 2009
    Location
    somewhere
    Posts
    23
    Thank Post
    28
    Thanked 4 Times in 3 Posts
    Rep Power
    0
    Quote Originally Posted by nephilim View Post
    you want to create something that is essentially a keylogger?
    No my idea is to create a script ot create an unattended dcpromo file for Server 2003 e.g it asks for the Domain Name and Site Name etc and creates it like that.

  4. #4


    Join Date
    Jul 2007
    Location
    Rural heck
    Posts
    2,662
    Thank Post
    120
    Thanked 433 Times in 352 Posts
    Rep Power
    127
    You could probably do it quite easily with Autoit.

  5. Thanks to K.C.Leblanc from:

    timethrow (5th January 2012)

  6. #5

    Join Date
    Nov 2009
    Location
    somewhere
    Posts
    23
    Thank Post
    28
    Thanked 4 Times in 3 Posts
    Rep Power
    0
    Quote Originally Posted by K.C.Leblanc View Post
    You could probably do it quite easily with Autoit.
    Thanks for that I will look at it but in the meantime does anyone have just a basic script to create a text file and input stuff to it and input stuff based on user input e.g. a Message box pops up asking for the domain name.

    Thanks

  7. #6

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,824
    Thank Post
    372
    Thanked 544 Times in 507 Posts
    Rep Power
    184
    Code:
    InputString = UserInput( "Enter stuff:" )
    
    Set myFSO = CreateObject("Scripting.FileSystemObject")
    Set WriteStuff = myFSO.OpenTextFile("MyText.txt", 8, True)
    WriteStuff.WriteLine(InputString)
    WriteStuff.Close
    Try that, Not tested yet.

    Steve

  8. Thanks to Steve21 from:

    timethrow (5th January 2012)

  9. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,585
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    VBScript Scripting Techniques: Retrieving (User and Computer) Domain or Workgroup Names

    WSH - FSO (File System Object) Using CreateTextFile and WriteLine to create files

    Using the WshNetwork object and writing this to a text file:

    Code:
    DIM fso, NewsFile
    Set wshNetwork = WScript.CreateObject( "WScript.Network" )
    strComputer = wshNetwork.ComputerName
            strUserDomain = wshNetwork.UserDomain
    strUserName = wshNetwork.UserName
    
    WScript.Echo "Computer Name : " & strComputer & vbcrlf & _
     "Username : " & strUserName & vbcrlf & _
     "User Domain: " & strUserDomain
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set NewsFile = fso.CreateTextFile("c:\output.txt", True)
    NewsFile.WriteLine strComputer
    NewsFile.WriteLine strUserName
    NewsFile.WriteLine strUserDomain
    NewsFile.Close
    Not tested the above but it should

    1. Prompt you with a message box showing the currently logged on username, computer name and domain name
    2. Then write the above info into a text file called output.txt on the root of the C: Drive.
    3. If wscript.echo does not work you can use the msgbox function ie

    msgbox "Some string to output"

    4. If you have vista / windows 7 where it is a bit strict about writing files to the root of your C: Drive then if you create a folder on your C: drive that you have full access rights to you can adjust the output directory to that folder ie

    Set NewsFile = fso.CreateTextFile("c:\Directory\output.txt", True)

    Adjusted the script slightly as I did not use the variable for the domain correctly, I originally had strDomain and it should of been strUserDomain
    Last edited by mac_shinobi; 5th January 2012 at 05:00 PM.

  10. Thanks to mac_shinobi from:

    timethrow (5th January 2012)

  11. #8

    Join Date
    Nov 2009
    Location
    somewhere
    Posts
    23
    Thank Post
    28
    Thanked 4 Times in 3 Posts
    Rep Power
    0
    Quote Originally Posted by mac_shinobi View Post
    VBScript Scripting Techniques: Retrieving (User and Computer) Domain or Workgroup Names

    WSH - FSO (File System Object) Using CreateTextFile and WriteLine to create files

    Using the WshNetwork object and writing this to a text file:

    Code:
    DIM fso, NewsFile
    Set wshNetwork = WScript.CreateObject( "WScript.Network" )
    strComputer = wshNetwork.ComputerName
            strUserDomain = wshNetwork.UserDomain
    strUserName = wshNetwork.UserName
    
    WScript.Echo "Computer Name : " & strComputer & vbcrlf & _
     "Username : " & strUserName & vbcrlf & _
     "User Domain: " & strUserDomain
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set NewsFile = fso.CreateTextFile("c:\output.txt", True)
    NewsFile.WriteLine strComputer
    NewsFile.WriteLine strUserName
    NewsFile.WriteLine strUserDomain
    NewsFile.Close
    Not tested the above but it should

    1. Prompt you with a message box showing the currently logged on username, computer name and domain name
    2. Then write the above info into a text file called output.txt on the root of the C: Drive.
    3. If wscript.echo does not work you can use the msgbox function ie

    msgbox "Some string to output"

    4. If you have vista / windows 7 where it is a bit strict about writing files to the root of your C: Drive then if you create a folder on your C: drive that you have full access rights to you can adjust the output directory to that folder ie

    Set NewsFile = fso.CreateTextFile("c:\Directory\output.txt", True)

    Adjusted the script slightly as I did not use the variable for the domain correctly, I originally had strDomain and it should of been strUserDomain


    Thanks I will try and use the bas of this code to get what I am after, However what I want is quite diffrent really, Essentially I want the script to do the following, Create a new text file in C:\ called dcpromo.txt, Then I wnat it to ask you 3 questions and write the files to the text file so it would write the following to the etxt file if the question was "What would you like the AD Site to be called" and they answered "Default First Site Name" it would write the following to the txt file SiteName=USERINPUT1 etc .......

    Do you sort of see where I am coming from ??

    So thsi would be the end output file .....

    [DCInstall]
    CreateOrJoin = Create
    DomainNetBiosName = [USERINPUT1]
    NewDomainDNSName = [USERINPUT1].INTERNAL

    ReplicaOrNewDomain = Domain
    TreeOrChild = Tree
    SiteName = "[USERINPUT2]"

    SysVolPath = C:\WINNT\SYSVOL
    LogPath = C:\WINNT\LOGS
    DatabasePath = C:\WINNT\DATABASE

    DNSOnNetwork = YES
    AutoConfigDNS= YES

    RebootOnSuccess = NoAndNoPromptEither
    and if you were to replace the [USERINPUTX] with the inputs from the user it would give you the file, That is what I am trying to create
    Last edited by timethrow; 5th January 2012 at 05:30 PM. Reason: Adding more info

  12. #9

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,585
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    You could use the InputBox function as per Steve's suggestion and in my code where I have write line you could do something like :

    Dim QOne, QTwo, QThree

    QOne =InputBox("Question one for the user")
    QTwo = InputBox("Question two for the user")
    QThree = InputBox("Question three for the user")

    'Code from above snippet regards to the FSO and creating and writing to a text file

    writeline "Default First Site Name : " & QOne
    writeline "Default First Site Name : " & QTwo
    writeline "Default First Site Name : " & QThree

    Then you would literally just have to adjust the file name in the below line of code :

    Set NewsFile = fso.CreateTextFile("c:\dcpromo.txt", True)

    You can adjust the text between the quotes as needed
    Last edited by mac_shinobi; 5th January 2012 at 05:31 PM.

  13. Thanks to mac_shinobi from:

    timethrow (5th January 2012)

  14. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,585
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    So does the domain name need to be the FQDN or will your-domain be enough ?

    Also does the file need to be an inf or ini file or something along those lines as apposed to a txt file ?

    @Steve21 - Is there a better way of changing the file extension or renaming the file to be an inf or ini file instead of a txt file, presume that would be ok and that it would not muck up the formatting of the file etc ?
    Last edited by mac_shinobi; 5th January 2012 at 06:25 PM.

  15. #11

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,824
    Thank Post
    372
    Thanked 544 Times in 507 Posts
    Rep Power
    184
    Quote Originally Posted by mac_shinobi View Post
    @Steve21 - Is there a better way of changing the file extension or renaming the file to be an inf or ini file instead of a txt file, presume that would be ok and that it would not muck up the formatting of the file etc ?

    Generally it's "ok", but remember you'll have to do the sections, parameters etc too, It's not just one liners as such. And for what he's trying to do, the "cleanest" way would be encoding the entire output into the vbs, rather than find/replacing just the three items etc I'd guess

    Steve

  16. #12

    Join Date
    Nov 2009
    Location
    somewhere
    Posts
    23
    Thank Post
    28
    Thanked 4 Times in 3 Posts
    Rep Power
    0
    Also as a seperate script does anyone have a script to rename the computer based on what they say i.e Inputbox asks for new Computer Name: and they enter it and it changes it to that ??

    Thanks

  17. #13


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,811
    Thank Post
    262
    Thanked 2,969 Times in 2,183 Posts
    Rep Power
    847
    To read and write INI files you could use a VBScript from Microsoft called IniCommand.vbs (it's inside the zip file at the bottom of the page).

  18. Thanks to Arthur from:

    mac_shinobi (6th January 2012)

  19. #14

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,585
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    Quote Originally Posted by timethrow View Post
    Also as a seperate script does anyone have a script to rename the computer based on what they say i.e Inputbox asks for new Computer Name: and they enter it and it changes it to that ??

    Thanks
    You can do but if you rely on user input the computer may get renamed wrongly, how are you planning or wanting the computers to get renamed?

  20. #15

    Join Date
    Nov 2009
    Location
    somewhere
    Posts
    23
    Thank Post
    28
    Thanked 4 Times in 3 Posts
    Rep Power
    0
    Quote Originally Posted by mac_shinobi View Post
    You can do but if you rely on user input the computer may get renamed wrongly, how are you planning or wanting the computers to get renamed?
    It would be me that renames it, Its only part of a Unattended Server Build Disk I am making, It sets it to something random during instalation and then during a series of RunOnce Commands it propmts you to rename it, It would only be me or someone trusted to rename it really.

    Code:
    QOne =InputBox("Enter the new Server name e.g. MYSERVER or TST-SVR-001")
    
    Set oShell = CreateObject ("WSCript.shell") 
    
    sCCS = "HKLM\SYSTEM\CurrentControlSet\" 
     sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\" 
     sCompNameRegPath = sCCS & "Control\ComputerName\" 
    
    With oShell 
       .RegDelete sTcpipParamsRegPath & "Hostname" 
       .RegDelete sTcpipParamsRegPath & "NV Hostname" 
    
      .RegWrite sCompNameRegPath & "ComputerName\ComputerName", QOne 
       .RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", QOne 
       .RegWrite sTcpipParamsRegPath & "Hostname", QOne 
       .RegWrite sTcpipParamsRegPath & "NV Hostname", QOne 
     End With   ' oShell
    That is my current Rename PC Script, Below id my create DCPromo Script.

    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''' DO NOT CHANGE ANYTHING BELOW '''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''' SCRIPT TO CREATE IE CONFIG AND DCPROMO UNATTENDED FILE BASED ON USER INPUT '''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''' CREATED BY TIMETHR0W '''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Dim QOne, QThree
    
    'Asks the questions and uses the information given to generate the scripts
    QOne =InputBox("Please enter the name for you domain e.g. *DOMAIN* (It will then become DOMAIN.INTERNAL)")
    QThree = InputBox("What is the AD Site Name you want to use e.g. My AD Site")
    
    'Gets the current Computer Name and uses it in the scripts below
    Set wshNetwork = WScript.CreateObject( "WScript.Network" )
    strComputer = wshNetwork.ComputerName
    
    'Creates the DCPromo.txt file based on the user input above
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set NewsFile = fso.CreateTextFile("C:\SCRIPTS\DCPromo.txt", True)
    NewsFile.WriteLine "[DCInstall]"
    NewsFile.WriteLine "NewDomainDNSName=" & QOne & ".INTERNAL"
    NewsFile.WriteLine "DomainNetBiosName=" & QOne
    NewsFile.WriteLine ""
    Newsfile.WriteLine "ReplicaOrNewDomain=Domain"
    NewsFile.WriteLine "NewDomain=Forest"
    NewsFile.WriteLine "CreateOrJoin = Create"
    NewsFile.WriteLine "TreeOrChild = Tree"
    NewsFile.WriteLine "SetForestVersion = Yes"
    NewsFile.WriteLine "ConfirmGc = Yes"
    NewsFile.WriteLine ""
    NewsFile.WriteLine "DatabasePath=C:\WINNT\NTDS"
    NewsFile.WriteLine "LogPath=C:\WINNT\NTDS"
    NewsFile.WriteLine "SysvolPath=C:\WINNT\SYSVOL"
    NewsFile.WriteLine ""
    NewsFile.WriteLine "DNSOnNetwork=Yes"
    NewsFile.WriteLine "AutoConfigDNS=YES"
    NewsFile.WriteLine "SiteName=" & QThree
    NewsFile.WriteLine "DisableCancelForDnsInstall = Yes"
    NewsFile.WriteLine "CriticalReplicationOnly = Yes"
    NewsFile.WriteLine "RebootOnSuccess=NoAndNoPromptEither"
    NewsFile.Close
    'Generates the Unattended Internet Explorer Enhanced Configuration File using the Server's Name as a basis.
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set NewsFile = fso.CreateTextFile("C:\SCRIPTS\IEConfig.txt", True)
    NewsFile.WriteLine "[Components]"
    NewsFile.WriteLine "IEHardenAdmin = Off"
    NewsFile.WriteLine "IEHardenUser = Off"
    NewsFile.WriteLine ""
    NewsFile.WriteLine "[IEHardening]"
    NewsFile.WriteLine "LocalIntranetSites = http://localhost;https://localhost;http://" & strComputer & ";https://" & strComputer
    NewsFile.WriteLine "TrustedSites = http://localhost;https://localhost;http://" & strComputer & ";https://" & strComputer
    NewsFile.WriteLine ""
    NewsFile.WriteLine "[IEPopupBlocker]"
    NewsFile.WriteLine "BlockPopups = No"
    NewsFile.WriteLine "FilterLevel = Low"
    NewsFile.WriteLine "ShowInformationBar = No"
    NewsFile.Close
    
    '''
    ''' SCRIPT END, PLEASE REPORT ANY BUGS TO TIMETHROW
    '''
    The Generate Files Script works very well and generates everything correctly and is tested on Windows Server 2003
    The Rename PC Script was knocked up at 11 last night so is currently unteseted as of yet but it should work.

    I am open to any chnages you may have !!

    Thanks



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 17th November 2011, 10:02 AM
  2. Script to create a VPN connection
    By Norphy in forum Scripts
    Replies: 5
    Last Post: 20th April 2010, 12:37 PM
  3. VB Script to create folders
    By markesmith in forum Scripts
    Replies: 2
    Last Post: 26th April 2007, 04:03 PM
  4. Script to Create My Documents Subject Folders
    By SwedishChef in forum Scripts
    Replies: 15
    Last Post: 5th July 2006, 09:14 AM
  5. Script to create a local user on a XP box.
    By tosca925 in forum Scripts
    Replies: 3
    Last Post: 12th October 2005, 01:04 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •