Simple but goodie. Send DOS Commands from VBA. This examples assumes you have the net send service running. SP2 disables this service by default. Obviously you can send any DOS command that you like, this is just a simple example.

Send Dos Commands
-
-
Re: Send Dos Commands
Thanks, EJ. That could come in very handy.
-
Re: Send Dos Commands
Well, this is not really true.
Shell <program name> executes a program, not a command line command. So
executes that program, but it won't execute any command line instructions. Try
and see what happens.Why you can launch net.exe without specifying the full path is because the containing folder %winpath%\system32\ is defined in your PATH environment variable. Same goes for all other Windows command line tools.
However to send a command line instruction, you need to run cmd.exe with your instructions as parameter /c. For instance the following will create a text file contents.txt with the output of folder C: directory listings:
CodeDim cmd As String Dim ret As Double cmd = "cmd.exe /c dir C: > C:\contents.txt" ret = Shell(cmd, vbHide)
The cmd.exe will close itself after executing the command, so reading the returned pId will not really do you any good, so you could just as well disgard the return value -
Re: Send Dos Commands
I have been pawned. Your Geek power exceeds mine. LOL (In good fun)
-
Re: Send Dos Commands
Whats DOS?
-
-
Re: Send Dos Commands
My geek-fu is strong. Resistance is futile.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!