Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 06-05-08   #1 (permalink)
Security Sleuth
 
Raptors06's Avatar
 
intel ati

Join Date: Feb 2006
Posts: 428

Rep: 38 Raptors06 is acknowledged by some
Unique Rep: 35
Folding Team Rank: 567
Trader Rating: 3
Default Windows Batch Scripting

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
I'm using VBScript to write the code and then making a batch script calling the VB file. If anyone knows of an easier way (or website/cheap, GOOD book) to do this, I'm all ears. I've only been doing this about a day and a half. I'm just looking for something like cout from C++ or system.out.println for Java. Thanks in advance.
__________________
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."

System: My System
CPU
E6600 @ 3.0 w/1.350 (333x9) L651B
Motherboard
P5B-Deluxe
Memory
2 x 1GB Ballistix DDR2-800 @ 1000 (4-4-4-12)
Graphics Card
Gigabyte 3870 (900/1100)
Hard Drive
320GB 7200.10
Sound Card
Onboard
Power Supply
PC P&C 610
Case
KingWin PoS
CPU cooling
TRUE w/ FM121 *LAPPED*
GPU cooling
Zalman VF-1000
OS
Triple Boot (Vista, Ubuntu, BackTrack 3.0 Linux)
Monitor
19" ViewSonic FPD
Raptors06 is offline I fold for Overclock.net   Reply With Quote
Old 06-05-08   #2 (permalink)
Using more Linux everyday
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: University of Virginia
Posts: 1,260

Rep: 137 BiG O is acknowledged by manyBiG O is acknowledged by many
Unique Rep: 111
Trader Rating: 2
Default

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.

System: My System
CPU
Q6700
Motherboard
Blood Iron
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1Gaming Soundcard
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Tuniq Tower 120
GPU cooling
Stock
OS
Vista Ultimate x64 SP, openSUSE 11.0, Xubuntu 8.04
Monitor
Hanns-G 28" & Dell Ultrasharp 19" widescreen
BiG O is offline Overclocked Account   Reply With Quote
Old 06-05-08   #3 (permalink)
Programmer
 
intel ati

Join Date: Aug 2006
Location: Moscow, ID
Posts: 157

Rep: 10 Safetydan Unknown
Unique Rep: 9
Folding Team Rank: 1130
Trader Rating: 1
Default

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

System: Monster v2
CPU
Q6600 G0
Motherboard
GA-P35-DS3L
Memory
2GB Crucial Ballistix
Graphics Card
Saphire Radeon x1900XTX
Hard Drive
WD 320GB
Sound Card
x-fi extreme music (modded)
Power Supply
OCZ 700W
Case
Gigabyte 3D aurora
CPU cooling
TR Ultra-120 Extreme
GPU cooling
vf900
OS
Windows XP
Monitor
2x Acer 22" WS
Safetydan is offline I fold for Overclock.net   Reply With Quote
Old 06-06-08   #4 (permalink)
New to Overclock.net
 
Join Date: May 2008
Location: Nottingham, UK
Posts: 24

Rep: 7 Stormwolf Unknown
Unique Rep: 5
Trader Rating: 0
Default

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
Stormwolf is offline   Reply With Quote
Old 06-07-08   #5 (permalink)
PC Gamer
 
magus.tsf's Avatar
 
amd ati

Join Date: Mar 2008
Location: Deepest Wales
Posts: 150

Rep: 22 magus.tsf is acknowledged by some
Unique Rep: 19
Trader Rating: 0
Default

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.

System: My System
CPU
Phenom 9600 BE
Motherboard
Asus M3A32-MVP Deluxe
Memory
4 GB DDR2 800 OCZ HTC Reaper
Graphics Card
Watercooled Saphire 1GB 3870 X2
Hard Drive
2 x WD 500GB SATA 2
Sound Card
Onboard 8.1 channel
Power Supply
Zalman 850 Watt Heatpipe cooled
Case
Gigabyte Mercury 3D
CPU cooling
Water
GPU cooling
EK Full Cover Waterblock
OS
Vista Ultimate
Monitor
32" HD TFT on HDMI
magus.tsf is offline   Reply With Quote
Reply

Tags
batch, code output, vbscript



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 03:22 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.15245 seconds with 9 queries