Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Windows Batch Scripting
New Posts  All Forums:Forum Nav:

Windows Batch Scripting

post #1 of 5
Thread Starter 
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 & "\
oot\\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.
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 3570K Asrock Z77 Gigabyte 6850 G.Skill F3-12800CL9 
Hard DriveOptical DriveOSMonitor
WD Caviar Black Asus 24x DVD-RW Multi Win 7, CentOS, BT 5.0 RC2, Mac OSX 10.7.4 Dual Asus VH236H 
KeyboardPowerCaseMouse
Saitek Eclipse PC P&C 610 KingWin Logitech Optical TracBall 
Mouse Pad
A drug company generic black pad 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 3570K Asrock Z77 Gigabyte 6850 G.Skill F3-12800CL9 
Hard DriveOptical DriveOSMonitor
WD Caviar Black Asus 24x DVD-RW Multi Win 7, CentOS, BT 5.0 RC2, Mac OSX 10.7.4 Dual Asus VH236H 
KeyboardPowerCaseMouse
Saitek Eclipse PC P&C 610 KingWin Logitech Optical TracBall 
Mouse Pad
A drug company generic black pad 
  hide details  
Reply
post #2 of 5
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.
post #3 of 5
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.
Monster v2
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-P35-DS3L HD 4850 6GB Crucial Ballistix 
Hard DriveOSMonitorKeyboard
WD 320GB Windows 7 Ultimate (64bit) 2x Acer 22" WS Logitech g15 
PowerCaseMouse
OCZ 700W Gigabyte 3D aurora Logitech Mx510 
  hide details  
Reply
Monster v2
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-P35-DS3L HD 4850 6GB Crucial Ballistix 
Hard DriveOSMonitorKeyboard
WD 320GB Windows 7 Ultimate (64bit) 2x Acer 22" WS Logitech g15 
PowerCaseMouse
OCZ 700W Gigabyte 3D aurora Logitech Mx510 
  hide details  
Reply
post #4 of 5
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
post #5 of 5
nvm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom 9600 BE Asus M3A32-MVP Deluxe Watercooled Saphire 1GB 3870 X2 4 GB DDR2 800 OCZ HTC Reaper 
Hard DriveOptical DriveOSMonitor
2 x WD 500GB SATA 2 2 x SATA DVD-RW Vista Ultimate 32" HD TFT on HDMI 
KeyboardPowerCaseMouse
Saitek Eclipse II Zalman 850 Watt Heatpipe cooled Gigabyte Mercury 3D Genius Navigator 525 
Mouse Pad
Desk 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom 9600 BE Asus M3A32-MVP Deluxe Watercooled Saphire 1GB 3870 X2 4 GB DDR2 800 OCZ HTC Reaper 
Hard DriveOptical DriveOSMonitor
2 x WD 500GB SATA 2 2 x SATA DVD-RW Vista Ultimate 32" HD TFT on HDMI 
KeyboardPowerCaseMouse
Saitek Eclipse II Zalman 850 Watt Heatpipe cooled Gigabyte Mercury 3D Genius Navigator 525 
Mouse Pad
Desk 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Windows Batch Scripting