1.

Solve : Run a program before shutting computer down??

Answer»

I would like to write a batch file that runs an application before shutting the COMPUTER down. The application would take about a minute to complete, then computer can shut itself down.

thanksShutdown command in the .bat file? The code is relatively easy to make:

Code: [Select]@echo off
start application
ping localhost 240 >nul
shutdown /s

That should start the application, and then give it enough time to complete then it will shutdown.Quote from: BatchFileCommand on January 12, 2009, 06:28:49 AM

The code is relatively easy to make:

Code: [Select]@echo off
start application
ping localhost 240 >nul
shutdown /s

That should start the application, and then give it enough time to complete then it will shutdown.

That would bring an error(you wouldn't see it because there is no PAUSE). Shutdown /s doesn't exist, it's -s .Quote
Shutdown /s doesn't exist

That's because you use xp. I use vista. Quote from: BatchFileCommand on January 12, 2009, 04:28:47 PM
Quote
Shutdown /s doesn't exist

That's because you use xp. I use vista.

and so will everybody that ever uses your program, I take it.If I had a program that was worth giving out to people, I always make an xp version. Locbtran didn't specify EXACTLY what OS he had, so to make sure, you could have had 2 seperate code boxes, one which states it's for vista, the other for XP...(Or any other OS).I have also used a program called Xecutor but it costs money for commercial use. Free for private use.

http://english.xecutor.de/It's like my program hyperfolder with a few goodies . I could make a program even better in 15 days.It isn't hard to just make this VBS


Quote from: Sidewinder on DECEMBER 27, 2008, 10:06:47 AM
Quote
Can VBScript shut down a PC?

Yes. This little snippet will shutdown the local computer.

Code: [Select]strComputer = "."
Set objWMIService = GetObject_
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next

Quote
Can it shut down all PCs on a LAN?

Only if the PC's are part of a domain. This little snippet will shutdown 3 computers on the network.

Code: [Select]arrComputer = Array("Computer1", "Computer2", "Computer3")

For Each strComputer In arrComputer
Set objWMIService = GetObject _
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next
Next

If none of these are helpful, check out PsTools, specifically PsExec. VBScript can launch a new process with the Run method.

Good luck.



and then use it in a batch file- run the program, then run the script.Quote from: BC_Programmer on January 13, 2009, 06:14:35 PM
It isn't hard to just make this VBS


Quote from: Sidewinder on December 27, 2008, 10:06:47 AM
Quote
Can VBScript shut down a PC?

Yes. This little snippet will shutdown the local computer.

Code: [Select]strComputer = "."
Set objWMIService = GetObject_
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next

Quote
Can it shut down all PCs on a LAN?

Only if the PC's are part of a domain. This little snippet will shutdown 3 computers on the network.

Code: [Select]arrComputer = Array("Computer1", "Computer2", "Computer3")

For Each strComputer In arrComputer
Set objWMIService = GetObject _
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next
Next

If none of these are helpful, check out PsTools, specifically PsExec. VBScript can launch a new process with the Run method.

Good luck.



and then use it in a batch file- run the program, then run the script.

This is how I incorporate VBS into a batch file.

echo 'visual basic script' >> script.vbs

I need to do this for every SINGLE line of code.
Is there a quicker way of doing this?

thank youQuote
This is how I incorporate VBS into a batch file.

echo 'visual basic script' >> script.vbs

I need to do this for every single line of code.
Is there a quicker way of doing this?

I've seen this technique posted on the boards and I'm puzzled why anyone would do this. Using batch code to output a VBScript seems overly complex when the script has characters that are specially used by the batch interpreter. All those pesky escape characters.

Why not write the code in an editor, save the script with a vbs extension and then call the script from the batch file?

Code: [Select]call cscript drive:\path\scriptname.vbs



By creating a separate file for the VBScript, you can call the script from multiple batch files without having to reinvent the wheel.

Good luck.



Discussion

No Comment Found