timethrow Posted January 5, 2012 Posted January 5, 2012 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
featured_spectre Posted January 5, 2012 Posted January 5, 2012 you want to create something that is essentially a keylogger?
timethrow Posted January 5, 2012 Author Posted January 5, 2012 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.
K.C.Leblanc Posted January 5, 2012 Posted January 5, 2012 You could probably do it quite easily with Autoit. 1
timethrow Posted January 5, 2012 Author Posted January 5, 2012 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
Steve21 Posted January 5, 2012 Posted January 5, 2012 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 1
mac_shinobi Posted January 5, 2012 Posted January 5, 2012 (edited) 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: 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") [b]Set NewsFile = fso.CreateTextFile("c:\output.txt", True) [/b]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 Edited January 5, 2012 by mac_shinobi 1
timethrow Posted January 5, 2012 Author Posted January 5, 2012 (edited) 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: 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") [b]Set NewsFile = fso.CreateTextFile("c:\output.txt", True) [/b]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 Edited January 5, 2012 by timethrow Adding more info
mac_shinobi Posted January 5, 2012 Posted January 5, 2012 (edited) 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 Edited January 5, 2012 by mac_shinobi 1
mac_shinobi Posted January 5, 2012 Posted January 5, 2012 (edited) 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 ? Edited January 5, 2012 by mac_shinobi
Steve21 Posted January 5, 2012 Posted January 5, 2012 @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
timethrow Posted January 5, 2012 Author Posted January 5, 2012 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
Arthur Posted January 5, 2012 Posted January 5, 2012 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). 1
mac_shinobi Posted January 6, 2012 Posted January 6, 2012 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?
timethrow Posted January 6, 2012 Author Posted January 6, 2012 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. 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. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''' 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
mac_shinobi Posted January 6, 2012 Posted January 6, 2012 Simple script to rename : Rename a Computer and Computer Account (VBScript) more complicated one that queries the machine type ie laptop or desktop, then queries the bios for the serial number and then renames the computer Dynamically Renaming a Computer with VBScript - Steve Thompson I would test them on one machine ref renaming to ensure it is renaming the computer correctly etc and then go from there.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now