Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script to send PC to standby/sleep??

1,185 views
Skip to first unread message

Davy

unread,
Jul 31, 2012, 1:27:32 PM7/31/12
to
I am using Windows XP Pro and each night run a scheduled VBS
script which run NTBackup. At the end of the backup I would
like to put the host PC and a networked PC into the
'standby' power saving mode.
Anybody know of some script I can add to the end of the
backup script to achieve this?

Dave "Crash" Dummy

unread,
Jul 31, 2012, 2:12:27 PM7/31/12
to
I don't know of any way to do it directly with script, but you could
use the sctipr to run a third party utility like NirCmd that can put the
computer in standby mode.
http://www.nirsoft.net/utils/nircmd.html
Gibson Research Wizmo is another such utility
http://www.grc.com/wizmo/wizmo.htm
--
Crash

"Never underestimate the power of the Dark Side."
~ Obi-Wan Kenobi ~

Davy

unread,
Aug 1, 2012, 5:35:16 AM8/1/12
to
Davy <Da...@me.com> wrote in news:XnsA0A1BBC0884D9DavyS@
216.196.109.145:
I forgot to add that I can put the computer into standby by
running a DOS command. If I knew how to run a command from
within a VBS script. e.g.
C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState
0,1,0

I would also need to find a way to check that the backup has
finished before going into standby.

Ruediger Roesler

unread,
Aug 1, 2012, 9:03:43 AM8/1/12
to
Davy <Da...@me.com> typed:
It depends on what the backup program does if it is finished. If it quits
itself, the process can be interrogated by means of a WMI method. For
example:

Function IsRunning(ByVal strXName)
With GetObject("winmgmts:")
IsRunning = CBool(wmi.ExecQuery("Select * from Win32_Process " &_
"where Name = '" & strXName & "'").Count)
End With
End Function

In addition the name or an other unique property of this application is
required to detect the presence of it. The return value of this function
above is *false* if the application was quit and *true* if not.

The loop to manage this could look like this one:

Do While IsRunning("MyBackup.exe")
WScript.Sleep 30000
Loop

Then you can call the sleep mode:

With CreateObject("WScript.Shell")
.Run "rundll32.exe powrprof.dll,SetSuspendState"
End With

--
ЯR

Ruediger Roesler

unread,
Aug 1, 2012, 9:12:42 AM8/1/12
to
Davy <Da...@me.com> typed:

[Sorry, in my former message there was an error, therefore I have
cancelled it, but I think it is not possible in this group to cancel
messages.]
It depends on what the backup program does if it is finished. If it quits
itself, the process can be interrogated by means of a WMI method. For
example:

Function IsRunning(ByVal strXName)
With GetObject("winmgmts:")
IsRunning = CBool(.ExecQuery("Select * from Win32_Process " & _
"where Name = '" & strXName & "'").Count)
End With
End Function

In addition the name or an other unique property of this application is
required to detect the presence of it. The return value of this function
above is false if the application was quit and true if not.

Davy

unread,
Aug 2, 2012, 5:14:20 AM8/2/12
to
Ruediger,
well if that works then it seems to solve both problems at
once!
I will need to do a bit of studying to understand the 'with'
and then run some tests. Will reply with results
thanks
Davy

"Ruediger Roesler" <worm.co...@nospam.arcornews.de> wrote
in news:50192b5d$0$6548$9b4e...@newsspool4.arcor-online.net:

Tom Lavedas

unread,
Aug 2, 2012, 10:37:21 AM8/2/12
to
On Thursday, August 2, 2012 5:14:20 AM UTC-4, Davy wrote:
> Ruediger, well if that works then it seems to solve both problems at once! I will need to do a bit of studying to understand the 'with' and then run some tests. Will reply with results thanks Davy "Ruediger Roesler" <worm.co...@nospam.arcornews.de> wrote in news:50192b5d$0$6548$9b4e...@newsspool4.arcor-online.net: > Davy <Da...@me.com> typed: > > [Sorry, in my former message there was an error, therefore I have > cancelled it, but I think it is not possible in this group to cancel > messages.]

Actually, there is a small error in the first function. It should read ...

Function IsRunning(ByVal strXName)
With GetObject("winmgmts:")
IsRunning = CBool( .ExecQuery("Select * from Win32_Process " &_
"where Name = '" & strXName & "'").Count)
End With
End Function

The 'wmi' in the third line does not belong. The With construct removes the name of the object - it is just inferred by the presence of the leading dot.
_____________________
Tom Lavedas

Ruediger Roesler

unread,
Aug 2, 2012, 12:21:12 PM8/2/12
to
Tom Lavedas <tglb...@verizon.net> typed:
Thank you, Tom, for your hint. Therefore I had cancelled my first message
because of this error. In my second message I have removed this not
declared variable. I think, it is not possible cancelling messages in
this group.

This message is invalid:
Message-ID: <news:501929b0$0$6557$9b4e...@newsspool4.arcor-online.net>
It was replaced with this one:
Message-ID: <news:50192b5d$0$6548$9b4e...@newsspool4.arcor-online.net>

--
ЯR


Davy

unread,
Aug 5, 2012, 7:08:42 AM8/5/12
to
Ruediger,
I have tested the script and now my computer goes into
standby each night after performing the backups. So many
thanks for your help.

But a strange this was that in the end I did not need the
script which checks if NTBackup has finished running. My
script is something like:

Call Runbackup("DS") 'computer DS backed up
Call Runbackup("LS") 'computer LS backed up
With CreateObject("WScript.Shell")
.Run "rundll32.exe powrprof.dll,SetSuspendState"

The subroutine Runbackup includes a
WshShell.Run sBackupParams,vbMinimized, TRUE ' SBackupParams
which runs NTBACKUP.EXE

What I dont understand is that line two does not run until
line one has finished and line three does not run until line
two is finished. Yet NTbackup.exe must be running
independantly of the VBScript?

Any thoughts?

Davy

Ruediger Roesler

unread,
Aug 5, 2012, 8:10:11 AM8/5/12
to
Davy <Da...@me.com> typed:
You can give the Run-Method the command to wait for return. That is the
syntax:

intResult = object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

bWaitOnReturn is an optional boolean value indicating whether the script
should wait for the program to finish executing before continuing to the
next statement in your script. If set to *true*, script execution stops
until the program has finished, and Run evaluates any error code returned
by the program. If this parameter is set to *false*, what is the precon-
dition, or if omitted, the Run method returns immediately after starting
the program without any result. But you can get the same effect if you
call this Method in order to obtain a return code, then this method
behaves as bWaitOnReturn is set to true.

This command returns immediately:
wshShell.Run "NTBackup.exe", wshMinimezed

This both commands wait until the end of execution of the called program:
intReturn = wshShell.Run("NTBackup.exe")
wshShell.Run "NTBackup.exe", , True

But I am not sure whether this is the solution for your problem. Post
your code so that I can see that spaghetti.

That is a script I wrote 3 years ago for an automatic backup of a user's
folder at the end of each session:

'########################### Sicherung.vbs ############################
Rem von h.r.roesler
' The script saves a folder hierarchy, it was tested with
' Windows 7 Ultimate edition.
' Syntax:
' CScript.exe [path]Sicherung.vbs <Source Folder> <Target Folder>
' CScript.exe C:\Windows\Sicherung.vbs C:\Users\Public R:\backup
' If the name of a folder contains blank characters, it must be
' enclosed in quotation marks.
Option Explicit

Const SysFolder = 1, SRC = 0, DST = 1, ZIEL = 2
Dim fso, strFldr(2), strArgs, strCmd, str, i

Set fso = CreateObject("Scripting.FileSystemObject")

strCmd = fso.BuildPath(fso.GetSpecialFolder(SysFolder), "RoboCopy.exe")
If Not(fso.FileExists(strCmd)) Then strCmd = "RoboCopy.exe"

If WScript.Arguments.Count > 1 Then
strFldr(SRC) = WScript.Arguments(SRC)
strFldr(DST) = WScript.Arguments(DST)
End If

With CreateObject("WScript.Shell")
If Not(fso.FolderExists(strFldr(SRC))) Then
.PopUp "Source Folder " & strFldr(SRC) & " doesn't exist!", _
30, WScript.ScriptName, vbExclamation Or vbSystemModal
WScript.Quit
End If
Select Case .PopUp("Should the user's folder " & strFldr(SRC) & _
" be saved?", 10, WScript.ScriptName, _
vbQuestion Or vbYesNo Or vbSystemModal)
Case vbNo:
Case Else:
str = .ExpandEnvironmentStrings("%USERNAME%") ' Pfad basteln
strFldr(DST) = fso.BuildPath(strFldr(DST), str & "\" & _
fso.GetBaseName(strFldr(SRC)))

str = fso.BuildPath(fso.GetParentFolderName(strFldr(DST)), _
fso.GetBaseName(WScript.ScriptName) & ".log")
If InStr(str, " ") > 0 Then str = """" & str & """"
strArgs = " /MIR /W:0 /R:0 /REG /FFT /NP /TEE /LOG:" & str

If Not(fso.FolderExists(strFldr(DST))) Then
For Each str In Split(strFldr(DST), "\")
strFldr(ZIEL) = strFldr(ZIEL) & str & "\"
If Not(fso.FolderExists(strFldr(ZIEL))) Then
'WScript.Echo "Erzeuge " & strFldr(ZIEL)
fso.CreateFolder strFldr(ZIEL)
End If
Next
End If

For i = SRC To DST ' Backslash am Ende eines Pfades
Do While Right(strFldr(i), 1) = "\" ' entfernen
strFldr(i) = Left(strFldr(i), Len(strFldr(i)) - 1)
Loop
If InStr(strFldr(i), " ") > 0 Then
strFldr(i) = """" & strFldr(i) & """"
End If
Next

strCmd = strCmd & " " & strFldr(SRC) & " " & strFldr(DST)
'WScript.Echo strCmd & strArgs
With .Exec(strCmd & strArgs)
Do Until .StdOut.AtEndOfStream
WScript.StdOut.WriteLine .StdOut.ReadLine
WScript.Sleep 0
Loop
End With
End Select
End With
'########################### Sicherung.vbs ############################

--
ЯR

Davy

unread,
Aug 6, 2012, 1:17:44 PM8/6/12
to
Ruediger,
thanks for that, yes it is the 'True' parameter that makes
sure that the backups and closedown run sequentially.
Davy

"Ruediger Roesler" <worm.co...@nospam.arcornews.de>
wrote in news:501e62bc$0$6562$9b4e...@newsspool4.arcor-
online.net:
0 new messages