How do I run a script?

Posted on 2005-02-25
Medium Priority
Last Modified: 2008-01-09
From here, I was referred to a script.

I've got the script as a text file.  What do I do with it?

LISTING 4: Code to Create a Restore Point

if (boolCreateRestorePoint == true)
  objWMIClass = objWMIServices.Get ("SystemRestore")
  intRC = objWMIClass.CreateRestorePoint (strDescription,
  if (intRC)
    WScript.Echo ("Failed to create a new system restore point
      (" + intRC + ")")
    WScript.Echo ("System restore point successfully created.")

Question by:raymm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 27

Expert Comment

ID: 13407640
LVL 27

Expert Comment

ID: 13407667
Hmm not working ok

 The script of restoring of system of Windows XP
Alain Lisso


The important changes - for example, installation of the new program or editing of the register - on client computers of Windows XP Professional Edition always conjugate with risk. Fortunately, in XP Pro there is function System Restore with which help it is possible to return system in a former state (named by a point of restoring - restore point, or a system breakpoint - system checkpoint). Besides System Restore allows to take into account changes or personal files which have been created later; any operation of restoring fulfilled with usage System Restore, is completely converted.

XP Pro automatically creates a point of restoring each 24 hours; many procedures of installation demand creation of a point of restoring directly before installation of the application. The point of restoring can be created at any moment with the help of wizard System Restore or the script of Windows Management Instrumentation (WMI). In given clause function WMI which supports System Restore and the script for preparation and handles of points of restoring from the command line is considered.
Urgent help System Restore

At creation of a point of restoring System Restore does complete " an instant picture " register and some dynamic system files, saving the current state of a base set of system and applied files. System Restore compresses the register and creates copies of necessary files when finds out, that computer XP is not used. The list of files which are watched and eliminated System Restore, is stored in the hidden XML-file filelist.xml (in a folder %windir %\system32\restore).

Correct operation System Restore needs at least 200 Mb of the free space on a system disk. If size of the free space on any disk becomes less than 50 Mb System Restore switches in a waiting mode and stops creation of points of restoring. At release, at least, 200 Mb of a disk space operation System Restore is restored. More detailed information on foundation architecture System Restore is resulted in clause of Microsoft " Windows System Restore ".
WMI-provider System Restore

To create breakpoints of restoring of system on the local computer it is possible with the help of wizard System Restore which is in menu Start, All Programs, Accessories, System Tools. For same purpose it is possible to make the script, using possibilities of WMI-provider System Restore. This provider is in repozitarii Common Information Model (CIM) in space of names root\default and supports two classes WMI: class SystemRestore and class SystemRestoreConfig. Class SystemRestore allocates five methods which realize typical operations System Restore (creation of points of restoring, blocking and activation System Restore, reading of the status of the last operation of restoring and restoring of system). Properties of class SystemRestoreConfig allow to control frequency of creation of points of restoring and a disk space selected for System Restore on each disk. More detailed information on classes both their properties and methods is resulted in clause " System Restore WMI Classes ".
The script for System Restore

To illustrate operation of classes SystemRestore and SystemRestoreConfig, we shall consider the script in which the majority of the functions given by WMI-provider System Restore is used. The script composed in language JScript and is named WMISystemRestore.wsf. It gives a set of parameters of the command line which corresponds to methods and properties of classes of the provider. At start of the script from the command line it is necessary to apply a key/Action in a combination to the mandatory keyword defining operation which should be fulfilled to the script. Valid keywords - List, Disable, Enable, CreateRestorePoint, LastRestoreStatus and Update. Before to start the detailed analysis of the source text, I shall tell about various parameters of the command line which are used at execution of the script.

The most simple operation - review of existing points of restoring with the help of List keyword:


On the Screen 1 the result of execution of this command is resulted. Three points of restoring and five properties for each of them are shown.

First two properties, CreationTime (time of creation) and Description (description), in additional explanations do not require. Property EventType saved as an integer, defines type of the event which have served by a reason of creation of a point of restoring, and helps to place, for example, whether there corresponds the given point of restoring to a state of system up to or after change. In Table 1 possible values of this property are listed. Property SequenceNumber represented by an integer which defines a serial number of a point of restoring in the list of all existing points.

Disable keywords and Enable are used for disconnecting and activation System Restore. To fulfil these operations on concrete volume, it is necessary to specify the character of a disk. For example, to disable System Restore on volume D, it is necessary to enter the command



To disable or make active System Restore on all disks, it is necessary to replace the character of a disk with the character of group operation (*).

For creation of a point of restoring CreateRestorePoint keyword which the key/Description in a combination to a descriptive name for a point of restoring (so-called) follows is used:



 " My System Restore " 

The name entered by the user is displayed in property Description of a point of restoring.

To clarify the status of the last operation of restoring it is possible with the help of LastRestoreStatus keyword. In the script it is not required to supplement the keyword in any parameters:



For restoring a system breakpoint the key/RestoreSequence and a serial number of a restored breakpoint is used. The serial number of a point can be learned, having made the list of all points of restoring with the help of List keyword, and then having analyzed property SequenceNumber of each point. For example, to restore a breakpoint 28, it is necessary to enter the command



To change property System Restore defining percent of a disk space which is selected for information System Restore, it is necessary to use Update keyword with the subsequent key/DiskPercentage and the value specifying percent of a disk space. For example, to select 12 % of all disk space, it is enough to enter the command



Update keyword is used for change a graphics of creation of points. Behind a word there is a sequence of keys -/GlobalInterval,/LifeInterval and/SessionInterval - each of which is supplemented with the value specifying a time interval. The key/GlobalInterval corresponds to property RPGlobalInterval of class SystemRestoreConfig and defines an absolute time interval (in seconds) through which System Restore creates system breakpoints. A default - 86 400 seconds (24 hours). The key/LifeInterval corresponds to property RPLifeInterval of class SystemRestoreConfig and defines a period (in seconds) during which System Restore stores breakpoints. If the age of a point exceeds the indicated interval, System Restore deletes her. Value 7 776 000 (90 days) by default is accepted. The key/SessionInterval corresponds to property RPSessionInterval of class SystemRestoreConfig and defines a period (in seconds) during which System Restore creates scheduled breakpoints during an interactive session. A default - 0 (during an interactive session of a point of restoring do not form). The given property of class SystemRestoreConfig represented in seconds, but in the script temporary parameters are specified in hours, apparently from the following command:





Having got acquainted with various parameters of the command line and methods appropriate to them or properties, it is possible to consider the script. To load complete version WMISystemRestore.wsf and his minorant functions, it is necessary to address to Insertion 1. Administrative powers are necessary for start of the script. To make presentation by more clear, I have selected fragments of the source text in which main functions of the script are realized.
Usage System Restore

The script starts with definition of parameters of the command line, and then preparation for usage System Restore is fulfilled. The last process is shown in Listing 1.

First, the fragment of the source text with label A in Listing 1 contains some calls of external auxiliary functions. In DecodeSystemRestoreFunction.vbs two functions - DecodeRestorePointType () and DecodeEventType () - for the analysis of properties RestorePointType and EventType, accordingly enter. DisplayFormattedPropertyFunction.vbs contains function DisplayFormattedProperty () which provides mapping properties of classes and their values. Function ErrorHandler () enters in TinyErrorHandler.vbs and is used for error handling at execution of the script.

The fragment of the source text with label B in Listing 1 creates two objects: SWbemLocator, which is used for connection WMI, and SWbemDateTime, which is used by function DisplayFormattedProperty () for a manipulation properties of date and time WMI. The fragment of the source text with label C defines two constants: cComputerName sets the computer name with which connection is installed, and cWMINameSpace defines space of names repozitarija WMI CIM (root\default) with which connection is installed. Then parse of the command line with usage of XML-function of Windows Script Host (WSH) 5.6 is fulfilled. The source text with label D installs connection WMI.
Review of points of restoring

The source text in Listing 2 displays existing points of restoring. The fragment with label A extracts all copies of class SystemRestore, then the program code with label B enumerates all received copies SystemRestore and their properties. The script calls function DecodeRestorePointType () or DecodeEventType () for decryption of values of properties EventType and RestorePointType and with the help before created SWbemDateTime object will transform string of date and time Distributed Management Task Force (DMTF) properties CreationTime to easily readable property.
Activation and disconnecting of monitoring of a disk

In the script the simple way of activation and disconnecting of function of disk monitoring System Restore is used. In Listing 3 it is shown, as method Enable is applied to activation of monitoring; method Disable is in the same way used for disconnecting monitoring. First the program code with label A extracts a copy of class SystemRestore. Methods Enable and Disable are not connected to the defined copy of a point of restoring, but operate globally in subsystem System Restore. Therefore the script extracts not a copy of a concrete point of restoring, and a copy of class Restore.

As it was marked earlier, method Enable or Disable can effect on the defined disk or all disks. If the script calls methods for all disks the program code with label B in Listing 3 transfers a null string in method Enable. Method Enable accepts also the second parameter as binary number which defines, whether it is necessary to postpone execution of a method until mode System Restore will not be completely activated for a concrete disk or disks before to return to execution of the script. In the exemplary script to the given parameter value true. Is assigned
Creation of a point of restoring

The program code in Listing 4 calls method CreateRestorePoint to create a point of restoring just as method Enable has been called. First the copy of class SystemRestore is extracted. Then in a fragment with label A method CreateRestorePoint for which three parameters are required is called. The first parameter represents the description of a point of restoring which the script reads out from a key/Description as it has been shown earlier. The second parameter corresponds to property RestorePointType and should have one of the values listed in Table 2. The third parameter corresponds to property EventType and should have one of the values resulted in table 1.

To simplify and reduce the source text of the script, I have rigidly set value APPLICATION_INSTALL of property RestorePointType and value BEGIN_SYSTEM_CHANGE of property EventType; in result the script creates a point of restoring in the beginning of installation process of the new application. Usually installation programs, such as Windows Installer or InstallShield companies InstallShield Software, automatically create points of restoring before installation. In this case it is not necessary to create an own point of restoring before installation of the application.

At start of scripts which make changes to system or the register, it is possible to involve WMISystemRestore.wsf with a key/Action:CreateRestorePoint manually to create doinstalljatsionnuju a point of restoring. After installation it is necessary to edit value END_SYSTEM_CHANGE for property EventType which will create posleinstalljatsionnuju a point of restoring. If it is necessary to cancel changes in system or to delete a point of restoring, it is necessary to edit the script, having assigned values CANCELLED_OPERATION and END_SYSTEM_CHANGE for properties RestorePointType and EventType, accordingly. Labels RestorePointType and EventType are defined as a constant in file DecodeSystemRestoreFunction.vbs.
Reading the status of operation of restoring

To receive the status of the last operation of restoring it is simple. In the source text in Listing 5 method GetLastRestoreStatus from a copy of class SystemRestore (similarly to execution of methods Enable and CreateRestorePoint) is fulfilled global for subsystem System Restore. The method returns value 0, 1 or 2. Value 0 specifies, that the last operation of restoring was completed unsuccessfully, 1 means, that restoring has passed successfully, and 2 testifies, that restoring has been interrupted.
Restoring a system breakpoint

In Listing 6 the program code for restoring a system breakpoint is shown. To make it it is not more complex, than to read through the status of restoring. Method Restore should be fulfilled from a copy of class SystemRestore, and a unique mandatory data-in - a serial number of a point of restoring which can be learned, having started WMISystemRestore.wsf with parameter of/Action:List. command line
Upgrade of parameters

The program code of Listing 7 is intended for handle of properties which define frequency of creation of points of restoring on a graphics and the value of the disk space borrowed System Restore on each disk. For this purpose the fragment with label A should extract a copy of class SystemRestoreConfig. There is only one copy - SR. In a fragment with label B this copy reads out the percent of a disk space stored in property DiskPercent and three metrics of frequency from properties RPGlobalInterval, RPLifeInterval and RPSessionInterval. As it was marked above, temporary parameters in the script are specified in hours. As class SystemRestoreConfig calculates appropriate properties in seconds, the script multiplies temporary metrics on 3600. From the command line it is possible to change one or several properties, therefore the script checks, what property has the assigned value. If the value differs from-1 (by default specifies, that from the command line has not been set new values) the script updates the given property. The program code with label C saves the refreshed property or properties in repozitarii CIM, calling method Put_ of SWbemObject object which represents a copy of class SystemRestoreConfig.
Restoring without problems

Many installation programs automatically create points of restoring before the beginning of installation, but from time to time there is a necessity for creation of points of restoring manually, for example, at stsenarnyh changes in several computers XP Pro simultaneously. In such cases process can be sped up with the help of specialized scripts, but dangerously to make large-scale changes, not having received it is preliminary a backup copy of system parameters of each computer. As much as possible to lower risk, it is possible to start the script of preparation of points of restoring in the beginning of the specialized script. It will provide restoring systems XP Pro in a case of failure and will help to save working capacity of computers.

Alain Lisso - With it it is possible to communicate to the address: alain.lissoir@compaq.com.

LVL 27

Expert Comment

ID: 13407693
Addon: save your script as textfile name it "WMISystemRestore.wsf" Follow those given examples.

Here is the original source: http://www.osp.ru/win2000/programme/410_28.htm#incuts

and here your script: http://www.osp.ru/win2000/programme/410_28_6.htm


Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 13407745

That is huge.  And thank you.

But I'm looking for something like copy to a *.bat file and make a shortcut.

Looking for guidance at that level.
LVL 27

Expert Comment

ID: 13408037
Ok let's start here:

Download: http://www.winnetmag.com/Files/07/42738/42738.zip

unpack it all (includes another archive) to c:\temp

now start "cmd" and go to c:\temp\Scripts

now simply start that file: C:\temp\Scripts>WMISystemRestore.wsf <Enter>

you should get a big helpscreen.

Well basically that is all you need.

Now open explorer and go to c:\windows\tasks

Click on "Create new task"
When the assistent asks you to choose a program open "Search" and select  WMISystemRestore.wsf in folder c:\temp\Scripts

now choose the time you want to start system restore e.g. "at logon"

Now you are being asked for an admin account, enter accountname and password

Press forward 2 times. Now open that new task with a doubleclick

in the line "run: C:\temp\Scripts\WMISystemRestore.wsf"

change to : C:\temp\Scripts\WMISystemRestore.wsf /action:createrestorepoint /description "my automatic system restorepoint"

Close with ok.

Open with right mouse button and click "run" Your restorepoint should be automatically created.

Now reboot and check if it works too.

If you get some error message: failed to create a new system restore point" you should check your account settings in the task.

That's all.


LVL 27

Expert Comment

ID: 13408053
if you want some batchfile, keep those locations after unpacking and create a batchfile with this content:

C:\temp\Scripts\WMISystemRestore.wsf /action:createrestorepoint /description "my automatic system restorepoint"

That should be ok.

Of cause you can move the directory "Scripts" to any location, just make sure you change the path "c:\temp\scripts" accordingly.

LVL 15

Expert Comment

ID: 13408896
save it to a txt file and change the extension to .vbs.  then when you run it, it should either error out or complete.
LVL 10

Expert Comment

ID: 13409004
FYI - after you follow the instructions, and rename the file to a .wsf extension..

I believe all you will need to do from the command prompt (@ c:\dirofthescript) is type:

cscript c:\dirofthescript\scriptname.wsf

that will then run correctly or error out.

If you just doubleclick the file, it may error out and you will never know it...


Author Comment

ID: 13421080
I think problem arises from lack of password in Scheduled Tasks.
I don't have a password to log on.
When I set up Scheduled Task, it says "Access is denied.  You do not have permission to run the requested operation."
But I have admin powers.
Tried making a task to be run as Administrator, no password, same message.
Do I have to setup a password?  I'm the only user on this computer.
LVL 27

Expert Comment

ID: 13421699
Yep, as it seems empty passwords are not allowed.

You could create another adminaccount with a password or give your account a password.


Author Comment

ID: 13422104
Some progress being made.
Scheduled Tasks report task is running, but I doesn't end.
Got error: Cannot retrieve referenced URL:      <script language="VBScript" src=".\Functions\DecodeSystemRestoreFunction.vbs" />

What to do?

Author Comment

ID: 13422893
Here is what I'm going to try:

Using the Registry Editor to Configure System Restore

You can use the registry editor, Regedit.exe, to change entries in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\SystemRestore subkey that are not configurable by using Control Panel. Table D.4 lists some of these settings.

Table D.4   Selected System Restore Registry Settings
Registry ValueDescription
RPSessionInterval  Specifies the intervals, in seconds, between scheduled restore-point creation during an active user session. The default value is 0 seconds (disabled).  
RPGlobalInterval  Specifies the time interval, in seconds, at which scheduled restore points are created (regardless of whether or not there is an active user session). The default value is 86,400 seconds (24 hours).  
RPLifeInterval  Specifies the time interval, in seconds, for which restore points are kept. System Restore deletes restore points older than the specified value. The default value is 7,776,000 seconds (90 days).  
DiskPercent  Specifies the maximum amount of disk space on each drive that System Restore can use. This value is specified as a percentage of the total drive space. The default value is 12 percent

Author Comment

ID: 13422898
I'm going to set RPSessionInterval  to 3600 (60 minutes).
LVL 27

Accepted Solution

Tolomir earned 2000 total points
ID: 13423014
As I have tolad you, don't use just that single script but unzip the entire archive named

http://www.winnetmag.com/Files/07/42738/42738.zip to any folder

now unzip Scripting the Windows XP System Restore (ScriptKit).zip to a folder e.g. c:\temp

Before extracting make sure that you have selected: "use folder names"

now you should have a folder called C:\temp\Scripts within

a file: WMISystemRestore.wsf
and 2 folders: Certificates, Functions

btw.: in Functions you will find the missing ".\Functions\DecodeSystemRestoreFunction.vbs"


now create a new textfile and fill it with this content:

C:\temp\Scripts\WMISystemRestore.wsf /action:createrestorepoint /description "my automatic system restorepoint"

name it savesystem.bat

doubleclick on it. If you have admin rights, you should create a restorepoint.

That is all, nothing more to do ;-)


Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question