|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Windows Batch Scripting
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Security Sleuth
|
I've been playing around with batch scripting (trying to make this job easier for someone else when I leave this job while making myself more marketable in the process) to automate tasks for listing computer startup commands, adding printers, listing ports, adding users to Active Directory, etc. However, I cannot figure out exactly how to output the results of the "echo" commands to a file or command window or anything else.
For instance, I wrote a script for listing computer startup commands in the event that one of the employees downloads something malicious. However, each thing that is returned ends up opening in a Windows message, requiring you to click "ok" about five thousand times. The command outputs the command, location, name of the user requesting the command, and setting ID. So, this happens for each thing called during start up. So you can see where this would get annoying for each time that a Window requires the user to click "ok". Anyone have any idea how to output the results into a file or into one continuous window rather than a separate window every time? Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colStartupCommands = objWMIService.ExecQuery _
("Select * from Win32_StartupCommand")
For Each objStartupCommand in colStartupCommands
Wscript.Echo "Command: " & objStartupCommand.Command
Wscript.Echo "Location: " & objStartupCommand.Location
Wscript.Echo "Name: " & objStartupCommand.Name
Wscript.Echo "Setting ID: " & objStartupCommand.SettingID
Next
__________________
Crucial Ballistix Club ![]() Does Not Compute. Error 666. Please reboot Universe.exe and try again.
Katie Couric, while interviewing a Marine sniper, asked: "What do you feel when you shoot a Terrorist?". The Marine shrugged and said: "A slight recoil."
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Using more Linux everyday
Join Date: Jul 2007
Location: University of Virginia
Posts: 1,260
Rep: 137
![]() ![]() Unique Rep: 111
Trader Rating: 2
|
Have you considered storing everything in an array and then just echoing the array? I'm not too familiar with VB, but I'm sure it can be done. So at the end of your script there, when you're echoing. Rather than print it out like that, first store it to an array. Once it completes, then echo out the array.
here's a little tut on arrays in vbscript: http://www.tizag.com/vbscriptTutoria...riptarrays.php Just make an array of strings instead of printing the strings out like you are now.
__________________
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Programmer
|
I'm not sure that I have this right so here's what I think you're doing, please correct me if I got it wrong:
You have written a program in VB which you are calling from a .bat file. The .bat file takes the results from the VB script and outputs them. In this case all you need to do to redirect your output to a file is put " > filename" after the command which is doing the output. However the dialog that's popping up sounds to me like something that would be created in the VB script. I can't say that I've done much with VB, and I haven't used VB script at all... But this link claims to know how.
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which." Douglas Adams
|
|||||||||||||
|
|
|
|
#4 (permalink) |
|
New to Overclock.net
|
I think you need to concatenate your strings and echo the output once.
Have a look here - the example given seems pretty similar to what you're trying to achieve http://www.microsoft.com/technet/scr....mspx?mfr=true |
|
|
|
|
|
#5 (permalink) | |||||||||||||
|
PC Gamer
|
nvm
__________________
The Black Mesa Survivors Club Aoccdrnig to a rscheearch at an Elingsh uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht frist and lsat ltteer is at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae we do not raed ervey lteter by itslef but the wrod as a wlohe.
|
|||||||||||||
|
|
|
![]() |
| Tags |
| batch, code output, vbscript |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|