Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Trick one

Reply
 
Old 07-09-2009   #1 (permalink)
John


 
 

Trick one

Hi,
I now have a small script which will backup on logoff.
Can the following be implemented?

The script is as follows:

Set Command = WScript.CreateObject("WScript.Shell")
Command.Run """c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe"" -r"

Is it possible to create a progress bar in a windows which will close at
100% and continue to logoff?

Regards

John


My System SpecsSystem Spec
Old 07-09-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Trick one


"John" <noreply@xxxxxx> wrote in message
news:B3B3E395-D963-4414-AEF3-3B1E69EE7448@xxxxxx
Quote:

> Hi,
> I now have a small script which will backup on logoff.
> Can the following be implemented?
>
> The script is as follows:
>
> Set Command = WScript.CreateObject("WScript.Shell")
> Command.Run """c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe"" -r"
>
> Is it possible to create a progress bar in a windows which will close at
> 100% and continue to logoff?
>
> Regards
>
> John
>
VBScript programs don't have objects that support progress bars, although I
believe it can be done using third party objects, perhaps including IE.
However, in this case there is no way for a script to monitor the progress
of an exe. The progress bar would need to be implemented by the exe.
(SynctoyCmd.exe in this case).

Other than that, I would recommend code similar to:
=========
Option Explicit
Dim objShell, strCmd, intReturn

Set objShell = CreateObject("Wscript.Shell")
strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
2.0\SynctoyCmd.exe"" -r"
intReturn = objShell.Run(strCmd, 2, True)
If (intReturn <> 0) Then
Call MsgBox("Backup failed. Return code: " & CStr(intReturn))
End If
=======
I use "Option Explicit" and declare the variables to make troubleshooting
easier. I like to use %comspec% /c to run programs. Also, the "True"
parameter forces the script to wait for the program to finish. In most
cases, the variable intReturn will have the return code from the program,
unless the exe spawns another process that actually does the work. If you
are lucky, the script will wait for SynctoyCmd to complete and intReturn
will only be 0 if it succeeds. If the program raises an error, the return
code may help troubleshoot. However, I don't know if the logoff operation
will wait for this to finish. You will need to experiment.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 07-09-2009   #3 (permalink)
John


 
 

Re: Trick one

Ricahrd
Thanks for the reply

My script below now throws an error 800A0401 expected end of statement.

Sorry this is my first attempt at script and I'm at a loss here.
Could you help out please


Regards

John


Option Explicit
Dim objShell, strCmd, intReturn

Set objShell = CreateObject("Wscript.Shell")
strCmd = "%comspec% /c """c:\Program Files (x86)\SyncToy
2.0\SynctoyCmd.exe"" -r"
intReturn = objShell.Run(strCmd, 2, True)
If (intReturn <> 0) Then
Call MsgBox("Backup failed. Return code: " & CStr(intReturn))
End If





"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:uOBLWBNAKHA.3432@xxxxxx
Quote:

>
> "John" <noreply@xxxxxx> wrote in message
> news:B3B3E395-D963-4414-AEF3-3B1E69EE7448@xxxxxx
Quote:

>> Hi,
>> I now have a small script which will backup on logoff.
>> Can the following be implemented?
>>
>> The script is as follows:
>>
>> Set Command = WScript.CreateObject("WScript.Shell")
>> Command.Run """c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe"" -r"
>>
>> Is it possible to create a progress bar in a windows which will close at
>> 100% and continue to logoff?
>>
>> Regards
>>
>> John
>>
>
> VBScript programs don't have objects that support progress bars, although
> I believe it can be done using third party objects, perhaps including IE.
> However, in this case there is no way for a script to monitor the progress
> of an exe. The progress bar would need to be implemented by the exe.
> (SynctoyCmd.exe in this case).
>
> Other than that, I would recommend code similar to:
> =========
> Option Explicit
> Dim objShell, strCmd, intReturn
>
> Set objShell = CreateObject("Wscript.Shell")
> strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
> 2.0\SynctoyCmd.exe"" -r"
> intReturn = objShell.Run(strCmd, 2, True)
> If (intReturn <> 0) Then
> Call MsgBox("Backup failed. Return code: " & CStr(intReturn))
> End If
> =======
> I use "Option Explicit" and declare the variables to make troubleshooting
> easier. I like to use %comspec% /c to run programs. Also, the "True"
> parameter forces the script to wait for the program to finish. In most
> cases, the variable intReturn will have the return code from the program,
> unless the exe spawns another process that actually does the work. If you
> are lucky, the script will wait for SynctoyCmd to complete and intReturn
> will only be 0 if it succeeds. If the program raises an error, the return
> code may help troubleshoot. However, I don't know if the logoff operation
> will wait for this to finish. You will need to experiment.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
My System SpecsSystem Spec
Old 07-09-2009   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: Trick one

The """ should be "". The statement should be as follows (watch line
wrapping, this is one line:

strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
2.0\SynctoyCmd.exe"" -r"

In VBScript strings are enclosed with quotes. If there are any quotes
embedded in the string, they must be doubled. You can echo the value of
strCmd to the command prompt (a common way to troubleshoot these things), as
follows:

strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
2.0\SynctoyCmd.exe"" -r"
Wscript.Echo strCmd

The result (at a command prompt) should be:

%comspec% /c "c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe" -r

Other examples:

strCmd = """c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe"" -r"
Wscript.Echo strCmd

results in:

"c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe" -r

and finally, this example:

strProgram = "SynctoyCmd.ext"
strCmd = """c:\Program Files (x86)\SyncToy 2.0\" & strProgram & """"
Wscript.Echo strCmd

results in:

"c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.ext"

In the last example the value assigned to the variable strCmd is the
concatenation of three strings. The "&" operator concatenates strings. The
string """" resolves to a single quoted quote character. After awhile to get
used to it, but I admit it is not easy to read at first.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"John" <noreply@xxxxxx> wrote in message
news:O2u1gHNAKHA.2604@xxxxxx
Quote:

> Ricahrd
> Thanks for the reply
>
> My script below now throws an error 800A0401 expected end of statement.
>
> Sorry this is my first attempt at script and I'm at a loss here.
> Could you help out please
>
>
> Regards
>
> John
>
>
> Option Explicit
> Dim objShell, strCmd, intReturn
>
> Set objShell = CreateObject("Wscript.Shell")
> strCmd = "%comspec% /c """c:\Program Files (x86)\SyncToy
> 2.0\SynctoyCmd.exe"" -r"
> intReturn = objShell.Run(strCmd, 2, True)
> If (intReturn <> 0) Then
> Call MsgBox("Backup failed. Return code: " & CStr(intReturn))
> End If
>
>
>
>
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:uOBLWBNAKHA.3432@xxxxxx
Quote:

>>
>> "John" <noreply@xxxxxx> wrote in message
>> news:B3B3E395-D963-4414-AEF3-3B1E69EE7448@xxxxxx
Quote:

>>> Hi,
>>> I now have a small script which will backup on logoff.
>>> Can the following be implemented?
>>>
>>> The script is as follows:
>>>
>>> Set Command = WScript.CreateObject("WScript.Shell")
>>> Command.Run """c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe"" -r"
>>>
>>> Is it possible to create a progress bar in a windows which will close at
>>> 100% and continue to logoff?
>>>
>>> Regards
>>>
>>> John
>>>
>>
>> VBScript programs don't have objects that support progress bars, although
>> I believe it can be done using third party objects, perhaps including IE.
>> However, in this case there is no way for a script to monitor the
>> progress of an exe. The progress bar would need to be implemented by the
>> exe. (SynctoyCmd.exe in this case).
>>
>> Other than that, I would recommend code similar to:
>> =========
>> Option Explicit
>> Dim objShell, strCmd, intReturn
>>
>> Set objShell = CreateObject("Wscript.Shell")
>> strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
>> 2.0\SynctoyCmd.exe"" -r"
>> intReturn = objShell.Run(strCmd, 2, True)
>> If (intReturn <> 0) Then
>> Call MsgBox("Backup failed. Return code: " & CStr(intReturn))
>> End If
>> =======
>> I use "Option Explicit" and declare the variables to make troubleshooting
>> easier. I like to use %comspec% /c to run programs. Also, the "True"
>> parameter forces the script to wait for the program to finish. In most
>> cases, the variable intReturn will have the return code from the program,
>> unless the exe spawns another process that actually does the work. If you
>> are lucky, the script will wait for SynctoyCmd to complete and intReturn
>> will only be 0 if it succeeds. If the program raises an error, the return
>> code may help troubleshoot. However, I don't know if the logoff operation
>> will wait for this to finish. You will need to experiment.
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>

My System SpecsSystem Spec
Old 07-09-2009   #5 (permalink)
John


 
 

Re: Trick one

Perect thanks

However it would be nice to have some sort of visual representation of the
progress or if the backup succeeds or fails.

i.e. a windows with text " Please wait while files are synchronized", "Files
Successfully synchronized or Not" " Pause 5 secs window closes" or something
like this.

Regard

John



Regards

John

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:OUii$nNAKHA.5068@xxxxxx
Quote:

> The """ should be "". The statement should be as follows (watch line
> wrapping, this is one line:
>
> strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
> 2.0\SynctoyCmd.exe"" -r"
>
> In VBScript strings are enclosed with quotes. If there are any quotes
> embedded in the string, they must be doubled. You can echo the value of
> strCmd to the command prompt (a common way to troubleshoot these things),
> as follows:
>
> strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
> 2.0\SynctoyCmd.exe"" -r"
> Wscript.Echo strCmd
>
> The result (at a command prompt) should be:
>
> %comspec% /c "c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe" -r
>
> Other examples:
>
> strCmd = """c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe"" -r"
> Wscript.Echo strCmd
>
> results in:
>
> "c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe" -r
>
> and finally, this example:
>
> strProgram = "SynctoyCmd.ext"
> strCmd = """c:\Program Files (x86)\SyncToy 2.0\" & strProgram & """"
> Wscript.Echo strCmd
>
> results in:
>
> "c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.ext"
>
> In the last example the value assigned to the variable strCmd is the
> concatenation of three strings. The "&" operator concatenates strings. The
> string """" resolves to a single quoted quote character. After awhile to
> get used to it, but I admit it is not easy to read at first.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "John" <noreply@xxxxxx> wrote in message
> news:O2u1gHNAKHA.2604@xxxxxx
Quote:

>> Ricahrd
>> Thanks for the reply
>>
>> My script below now throws an error 800A0401 expected end of statement.
>>
>> Sorry this is my first attempt at script and I'm at a loss here.
>> Could you help out please
>>
>>
>> Regards
>>
>> John
>>
>>
>> Option Explicit
>> Dim objShell, strCmd, intReturn
>>
>> Set objShell = CreateObject("Wscript.Shell")
>> strCmd = "%comspec% /c """c:\Program Files (x86)\SyncToy
>> 2.0\SynctoyCmd.exe"" -r"
>> intReturn = objShell.Run(strCmd, 2, True)
>> If (intReturn <> 0) Then
>> Call MsgBox("Backup failed. Return code: " & CStr(intReturn))
>> End If
>>
>>
>>
>>
>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
>> message news:uOBLWBNAKHA.3432@xxxxxx
Quote:

>>>
>>> "John" <noreply@xxxxxx> wrote in message
>>> news:B3B3E395-D963-4414-AEF3-3B1E69EE7448@xxxxxx
>>>> Hi,
>>>> I now have a small script which will backup on logoff.
>>>> Can the following be implemented?
>>>>
>>>> The script is as follows:
>>>>
>>>> Set Command = WScript.CreateObject("WScript.Shell")
>>>> Command.Run """c:\Program Files (x86)\SyncToy 2.0\SynctoyCmd.exe"" -r"
>>>>
>>>> Is it possible to create a progress bar in a windows which will close
>>>> at 100% and continue to logoff?
>>>>
>>>> Regards
>>>>
>>>> John
>>>>
>>>
>>> VBScript programs don't have objects that support progress bars,
>>> although I believe it can be done using third party objects, perhaps
>>> including IE. However, in this case there is no way for a script to
>>> monitor the progress of an exe. The progress bar would need to be
>>> implemented by the exe. (SynctoyCmd.exe in this case).
>>>
>>> Other than that, I would recommend code similar to:
>>> =========
>>> Option Explicit
>>> Dim objShell, strCmd, intReturn
>>>
>>> Set objShell = CreateObject("Wscript.Shell")
>>> strCmd = "%comspec% /c ""c:\Program Files (x86)\SyncToy
>>> 2.0\SynctoyCmd.exe"" -r"
>>> intReturn = objShell.Run(strCmd, 2, True)
>>> If (intReturn <> 0) Then
>>> Call MsgBox("Backup failed. Return code: " & CStr(intReturn))
>>> End If
>>> =======
>>> I use "Option Explicit" and declare the variables to make
>>> troubleshooting easier. I like to use %comspec% /c to run programs.
>>> Also, the "True" parameter forces the script to wait for the program to
>>> finish. In most cases, the variable intReturn will have the return code
>>> from the program, unless the exe spawns another process that actually
>>> does the work. If you are lucky, the script will wait for SynctoyCmd to
>>> complete and intReturn will only be 0 if it succeeds. If the program
>>> raises an error, the return code may help troubleshoot. However, I don't
>>> know if the logoff operation will wait for this to finish. You will need
>>> to experiment.
>>>
>>> --
>>> Richard Mueller
>>> MVP Directory Services
>>> Hilltop Lab - http://www.rlmueller.net
>>> --
>>>
>>>
>>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Glenna's devious trick ? Vista mail
What is the trick to install PCI modem? Virtual PC
Trick VPC Virtual PC
Windows Defender Trick System Security
the lakeport trick doesn't work!!!! (at least not on my com) Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46