dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
1177
share rss forum feed


jimkyle
Btrieve Guy
Premium
join:2002-10-20
Oklahoma City, OK
kudos:2
Reviews:
·AT&T Southwest

[WIN8] Batch File Scripting?

I've avoided Windows through Vista and Win7 but now must deal with Win8 and need to automate a few actions to simplify the interface on my wife's new desktop. Specifically, I need to provide a script to suspend two virtual machines in VMware Player, shut down their instances of Player itself, and then power down Win8, so that these actions can all be initiated by a single shortcut on the desktop.

In Win98 or XP Pro I would have used a batch file. However a bit of searching for "batch file" in Win8 yields no results, and my initial attempts to blunder my way through in cmd.exe haven't helped either.

Is this capability still present, and if it is, what is the command to shut down the system from the command line?

It's a strange feeling to be a newbie again, after working my way from MS-DOS 1.25 through XP Pro and writing a few books on undocumented features of the systems...
--
Jim Kyle

BlitzenZeus
Burnt Out Cynic
Premium
join:2000-01-13
kudos:3
Did you actually write the old script? Do you still have the old script? Was there changes to VMware that make this incompatible?
If anything is different it's the folder structure, the fact more people actually ran software in Vista, and newer as a user by default, not as a full admin like Win9x/XP.

Dos died ever since WinME/NT, and these days the command line is pretty much for legacy, and yes batch files still work. It might seem unfamiliar after all these years, I've written stuff I had to look back at what I did as I haven't done anything in that medium for so long.
--
I distrust those people who know so well what god wants them to do because I notice it always coincides with their own desires- Susan B. Anthony
Yesterday we obeyed kings, and bent our necks before emperors. But today we kneel only to the truth- Kahlil G.


workablob

join:2004-06-09
Houston, TX
kudos:4
Reviews:
·Comcast
reply to jimkyle
The bat file should still work but have a look at this.
»communities.vmware.com/thread/53045

It might give you some ideas.

Dave
--
I may have been born yesterday. But it wasn't at night.


jimkyle
Btrieve Guy
Premium
join:2002-10-20
Oklahoma City, OK
kudos:2
Reviews:
·AT&T Southwest
reply to BlitzenZeus
Actually there's no "old script" involved. Prior to getting the new Win8 machine, I've used VirtualBox for all my virtual machine needs (running XP Pro on Linux hosts to support my customers for database recovery services), but at the moment VBox's support for Win8 hosts is flaky when it comes to USB devices. That forced me to switch over to VMware Player, so that I could continue to sync her Ipaq with the calendar and contacts of Outlook. I installed one VM to run XP Pro so that she can continue using the older applications with which she is familiar, and another VM to provide some Linux-based games that she likes. These are the VMs involved.

Currently I'm starting them automatically by creating a shortcut for each in the start menu (I've installed Classic Shell to provide the XP-like interface automatically at power on), but shutdown is a Chinese fire drill of suspend, click "yes," kill the player, do it again for second VM, and finally use the start menu to shut down the system. I want to put it all in a script that can have a desktop shortcut so that a single double-click does the whole thing.

I did finally find a web site (»www.eightforums.com/tutorials/) that has showed me how to get the system to shut down. I can use "vmrun" to suspend the VMs. The only thing I still need to figure out is how to kill the two instances of Player but that might be handled automatically by system shutdown...

Another "newbie" question I have, though, is how to modify the PATH environment variable. All I've found so far is a dialog under User Settings, that allows edit of the per-user part of PATH but the system part is greyed out and unchangeable even though I'm logged in as a user with administrator privileged...

Thanks much for the quick response!
--
Jim Kyle


jimkyle
Btrieve Guy
Premium
join:2002-10-20
Oklahoma City, OK
kudos:2
reply to workablob
Very interesting link! I'll have to study it in depth. I've avoided the Basic-like scripting features in the past because of the security risks involved, but it might be time to explore them again...
--
Jim Kyle


aurgathor

join:2002-12-01
Lynnwood, WA
kudos:1
Reviews:
·Frontier Communi..
reply to jimkyle
Traditional batch files should work just fine in Win8. Don't know much about VMware, but shutdown is just "shutdown /s"
--
Wacky Races 2012!


mmainprize

join:2001-12-06
Houghton Lake, MI
reply to jimkyle
If i remember correctly the VMplayer does not save changes to the VM image, so the normal windows shutdown should be able to close the players during shutdown.


jimkyle
Btrieve Guy
Premium
join:2002-10-20
Oklahoma City, OK
kudos:2
Reviews:
·AT&T Southwest
If I "suspend" the guest before shutting Player down, it's essentially hibernating the guest state and when it starts again, the guest comes right back to what it was doing when suspended.

It looks as if "taskkill" in the batch file will take care of killing the two instances of Player so I'm ready to start testing it. I'll post the finished script in this thread after getting rid of any obvious bugs. Many thanks to all who have responded!!!
--
Jim Kyle


JohnInSJ
Premium
join:2003-09-22
Aptos, CA
reply to jimkyle
You could also look at PowerShell if the old batch file capabilities are insufficient. Powershell gives you access to all the .net goodness you could ever want.

It's included with Win7/8.
--
My place : »www.schettino.us


jimkyle
Btrieve Guy
Premium
join:2002-10-20
Oklahoma City, OK
kudos:2
Reviews:
·AT&T Southwest
As of this morning, it's almost working the way I envision it. However when the batch file gets to the "shutdown" command, it goes into an infinite loop repeating a previous "echo" line. Commenting out the "shutdown" line makes it do the rest of the job correctly.

There's little help on the "shutdown" command; perhaps it simply doesn't work right when called from a batch file...
--
Jim Kyle


PapaDos
Cum Grano Salis
Premium,MVM
join:2001-02-08
Lasalle, QC
kudos:3
Use shutdown.exe in the command line or rename your BAT file something different than shutdown.bat...
--
Festina Lente

Anon00
Premium
join:2001-09-25
USA
kudos:1
reply to jimkyle
said by jimkyle:

As of this morning, it's almost working the way I envision it. However when the batch file gets to the "shutdown" command, it goes into an infinite loop repeating a previous "echo" line. Commenting out the "shutdown" line makes it do the rest of the job correctly.

There's little help on the "shutdown" command; perhaps it simply doesn't work right when called from a batch file...

Post your code.

What help do you need with shutdown? Open a Command Prompt and type shutdown /?

Does right-clicking the batch file and choosing "Run As Administrator" help ?
--
"Ah, women. They make the highs higher and the lows more frequent." - Friedrich Nietzsche
"'It's the law' is just an excuse for the unintelligent and unimaginative to remain that way" - Me


jimkyle
Btrieve Guy
Premium
join:2002-10-20
Oklahoma City, OK
kudos:2
Reviews:
·AT&T Southwest
PapaDos nailed it completely! It's been years since I made such a stupid mistake, but I'm sure that's the problem. I'll fix it tomorrow and post the code then. For tonight my workaround was to create a second desktop shortcut that launches shutdown, and that works okay...
--
Jim Kyle


jimkyle
Btrieve Guy
Premium
join:2002-10-20
Oklahoma City, OK
kudos:2
Reviews:
·AT&T Southwest

1 edit
Made the changes this morning and it works as originally intended. Here's the script, still named "shutdown.bat" and launched from a desktop shortcut:
@echo off

REM echo SuspendRunningVMs Command (x64)...
REM Based on script found at »communities.vmware.com/thread/92951?tstart=0
REM Original Author: Todd Scalzott, todd.scalzott@gmail.com.
REM Modified by: Craig Slack, dcslack@yahoo.com

REM modified 21 March 2013 by Jim Kyle

SETLOCAL
ECHO Shutting system down now...

REM Specify where vmrun.exe can be located
SET WSPath="c:\Program Files (x86)\VMware\VMware VIX"

REM Get the list of currently running VMs
%WSPath%\vmrun list | FIND /V "Total running VMs:" > %temp%\vmlist.txt

REM Suspend all running VMs
FOR /F "delims=*" %%v IN (%temp%\vmlist.txt) DO CALL :SuspendVM "%%v"

:WaitLoop
ECHO Waiting...
REM Pause until no more VMs are running
%WSPath%\vmrun list | FIND "Total running VMs: 0"
IF NOT ERRORLEVEL 1 GOTO End
TIMEOUT /t 10 /nobreak
GOTO WaitLoop

:End
ENDLOCAL
ECHO All VMs suspended, powering down now.
TIMEOUT /t 5 /nobreak
shutdown.exe -s -f -t 00 -c "Good night!"
GOTO :EOF

REM Suspend a VM
:SuspendVM
REM Suspend any running VM. Workaround a "vmrun list" quirk that outputs
REM a blank line, by not trying to suspend a blank VM
IF %1x==x GOTO :EOF
ECHO Suspending %1
%WSPath%\vmrun suspend %1
REM Allow some time after suspend call (allow disk to write vmem).
REM echo Wait a little bit for the VM to commit...
TIMEOUT /t 10
GOTO :EOF

:EOF


I have a similar script named StartVMs.bat:

REM batch file to start both VMs in Win8
REM Requires vmrun to be installed (VIX package)
REM Created 3/21/2013 by Jim Kyle

SETLOCAL
SET vmcmd = "C:\Program Files (x86)\VMware\VMware VIX\vmrun.exe -T player"
SET vmdir = "C:\Users\Joanne\Documents\Virtual Machines"

REM start Xubuntu 10.04.4 VM for Linux games...
%vmcmd% start %vmdir%\games\games.vmx
TIMEOUT /t 5 /nobreak

REM then start WinXP Pro VM for legacy programs and devices...
%vmcmd% start %vmdir%"\Windows XP Professional\Windows XP Professional.vmx"

ENDLOCAL

I use this while testing other things...

--
Jim Kyle