Run vbs file. Running a process on a remote computer – VBS Remote Scripting


Instructions

Run the file with *.vbs extension double click mouse or call it by name in the console. To do this, go to the start/run menu and type the path to required file in the window that opens. This is the most common Text Document, which can be easily edited in . This method the most understandable and simple, but sometimes due to certain circumstances it does not work (the system does not support the format, the encoding has failed, etc.).

If the file has a *.vbs extension, check for VBS language interpreters. There should be two of them in the system: console CScript and window WScript (together they are Windows Script Host or WSH). In theory, they should be installed immediately with the system, but sometimes it turns out that they are either damaged or not installed at all (maybe on older versions of systems). If interpreters are not available, install them on your computer and run the script double click mice.

Create a regular text file with a txt extension. Copy this text there:Sub Run(ByVal sFile)Dim shellSet shell = CreateObject("WScript.Shell")shell.Run Chr(34) & sFile & Chr(34), 1, falseSet shell = NothingEnd SubRun "C:/Program Files/FileZilla FTP Client/filezilla.exe"Naturally, replace the path with yours executable file. Then rename the txt file you created earlier to vbs extension. To check, double-click on it with the mouse and specified path the program will start.

In order to contact Windows method Script Host, specify the object and method with the required parameters (using a dot). You also specify WSH properties, but they can be assigned and read into variables and other properties. Always consider the data type of properties and variables, otherwise the script will throw a data type incompatibility error.

Write or select a useful website script- this is half the battle, we still need to find a way to accomplish it. Let's take a closer look at what is needed to execute the most common types script ov.

Instructions

Required condition execution of any script and (that is, the script), naturally, is the presence of the performer himself. In relation to programming languages, such an executor will be the interpreter script new language. Depending on where the script is to be executed, the language interpreter can be either part of the server software, or part program code browser. Therefore, to perform any server script(for example php- or perl- script) must have running server. You can select a server on the network or at home. It is very popular, for example, among Russian-speaking programmers because of its relative simplicity and free server software called “Denver”. Or you can not bother with the installation at home, but use the services of a hosting provider. The provider will give you access to, and all the worries about its maintenance and service will not concern you. Usually these are paid, but not expensive.

The situation is the same with “client” script ami. These are scripts that should be executed directly in . To do this script, written, for example, in JavaScript except for the browser and simple text editor(will do standard notepad) nothing more is required. Here, for example, is the simplest script: var now = new Date();
document.write("This script executed in " + now.getHours() + " hours " + now.getMinutes() + " minutes"); To execute it, just save this code in a file with an html extension (for example, test.html) and then double-click it mice. HTML extension(HyperText Markup Language - “hypertext markup language”) in operating system reserved for files containing web pages. Therefore, the OS will launch your browser and give it the address of this file, and the browser will recognize script, will read and execute his script. As a result we will see

Yes, oddly enough, VBScript (more precisely, Windows Scripting Host) also has the ability to run scripts on remote computers. True, this function has not gained much popularity, most likely due to the fact that it requires a lot of preparatory measures that are extremely poorly documented.

So, to run the script on another computer using VBS, we need:

  1. Administrator rights to remote computer. Well, this goes without saying, and is required in almost all launch methods that I listed on the blog.
  2. Allow WSH Remote Scripting by setting the Remote string parameter equal to “1” in the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Script Host\Settings
  3. Due to a bug, on systems with Windows XP you need to run the wscript –regserver command. In SP3 the error seems to have been fixed.
  4. You must disable the Firewall (or allow DCOM calls in exceptions) on both computers. Yes, yes, and on the one from which you launch the script, too (thanks to Kostya Leontev, I would not have guessed :)
  5. On XP SP2 and higher systems, you will need to change the security settings (this can be done using group policy). In the Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options\ node, change the permissions as follows:
    1. DCOM: Machine Access Restrictions in Security Descriptor Definition Language (SDDL) syntax
      Issue Anonymous groups Logon and Everyone permissions Allow Local and Allow Remote Access
    2. DCOM: Machine Launch Restrictions in Security Descriptor Definition Language (SDDL) syntax
      The Administrators group permissions Allow Local Launch, Allow Remote Launch, Allow Local Activation, Allow Remote Activation
      Everyone group – Allow Local Launch, Allow Local Activation.

All! 🙂 Now you can use it :)

For example, let's create a script c:\test.vbs (it will be launched on a remote computer):

Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTSOut = objFSO.CreateTextFile("C:\log.txt", True) objTSOut.WriteLine "Script executed" objTSOut.Close

Well, and most importantly, a script that will directly launch a file on a remote computer, RunRemoteScript.vbs:

Set objController = CreateObject("WshController") Set objRemoteScript = objController.CreateScript("C:\test.vbs", "computer1") WScript.ConnectObject objRemoteScript, "remote_" objRemoteScript.Execute Do While objRemoteScript.Status<>1 WScript.Sleep 1000 Loop MsgBox "Script complete" Sub remote_Error Dim objError Set objError = objRemoteScript.Error WScript.Echo "Error - Line: " & objError.Line & _ ", Char: " & objError.Character & vbCrLf & _ " Description: " & objError.Description WScript.Quit -1 End Sub

The second line specifies the name of the script to be launched and the computer name.

PS: I spent a lot of time to get this script to work, especially until I found point 5 😉 And then, as a result, I was able to execute the script only on a machine with Windows XP (SP3). Nothing worked on a computer with Vista - perhaps you need some additional items to bypass new security improvements 🙂 So if you suddenly have any problems with this thing, google is in your hands and good luck 😉

I'm breaking this down into several individual parts, since each part can be made individually. (I see a similar answer, but I'll give a more detailed explanation here.)

First part to avoid typing "CScript" (or "WScript"), you need to tell Windows how to run the *.vbs script file. On my Windows 8 (I can't be sure all these commands work exactly as shown here in old Windows, but the process is the same even if you need to change the commands slightly), launch a console window (eg "command prompt", or aka [incorrectly] "dos prompt") and enter "assoc.vbs". This should result in a response like:

C:\Windows\System32>assoc .vbs .vbs=VBSFile

Using this you then type "ftype VBSFile" which should produce the response:

C:\Windows\System32>ftype VBSFile vbsfile="%SystemRoot%\System32\WScript.exe" "%1" %*

C:\Windows\System32>ftype VBSFile vbsfile="%SystemRoot%\System32\CScript.exe" "%1" %*

If these two are already defined as above, your Windows is already configured to know how to run the *.vbs file. (BTW, WScript and CScript are the same program using different names. WScript runs the script as if it were a GUI program, and CScript runs it as if it were a program command line. See other sites and/or documentation for these details and caveats.)

If any of the commands did not respond as above (or similar responses if the file type reported by the association and/or the command executed with the ftype message has different names or locations), you can enter them yourself:

C:\Windows\System32>assoc .vbs=VBSFile

C:\Windows\System32>ftype vbsfile="%SystemRoot%\System32\WScript.exe" "%1" %*

You can also type "help assoc" or "help ftype" to get additional information about these commands, which are often handy when you want to automatically run certain programs by simply typing the file name with a specific extension. (Be careful as some file extensions are specially configured by Windows or programs you may have installed to work correctly. Always check the current assigned values ​​reported by assoc/ftype and save them to text file somewhere if you need to restore them.)

Second part without entering a file extension when entering a command from a console window. Understanding how Windows (and the CMD.EXE program) finds the commands you enter is useful for this (and the next) part. When you enter a command, let's use "querty" as an example, the system will first try to find the internal command list command in it (via settings in Windows registry for the system itself or programmed in the case of CMD.EXE). Since there is no such command, it will try to find the command in the current %PATH% environment variable. In older versions of DOS/Windows, CMD.EXE (and/or COMMAND.COM) will automatically add the file extensions ".bat", ".exe", ".com" and possibly ".cmd" to the command name you type unless you explicitly typed the extension (e.g. "querty.bat" to avoid "querty.exe" by mistake). In more modern Windows it will try the extensions listed in the %PATHEXT% environment variable. So all you have to do is add .vbs to %PATHEXT%. For example, here's my %PATHEXT%:

C:\Windows\System32>set pathext PATHEXT=.PLX;.PLW;.PL;.BAT;.CMD;.VBS;.COM;.EXE;.VBE;.JS;.JSE;.WSF;.WSH; .MSC;.PY

Please note that extensions MUST include ".", separated by ";" and that .VBS is shown in the "AFTER.CMD" field, but BEFORE.COM. This means that if the command processor (CMD.EXE) finds more than one match, it will use the first one listed. That is, if I have query.cmd, querty.vbs and querty.com, it will use querty.cmd.

Now if you want to do this all the time without having to set %PATHEXT% you will have to change system environment. Typing it in the console window only changes it for the console window session. I'll leave this process as an exercise for the reader. :-P

The third part to run the script without typing the full path. This part, related to the second part, has been around since DOS. Just make sure the file is in one of the directories (folders, for you Windows people!) listed in the %PATH% environment variable. My suggestion is to make your own storage directory various files and programs that you create or frequently use from the console/command line window(i.e. don't worry about this for programs you run from start menu or any other method.. only the console window. Don't mess with programs that are installed by Windows or an automatic installer unless you know what you're doing).

Personally, I always create a "C:\sys\bat" directory for batch files, a "C:\sys\bin" directory for *.exe and *.com files (for example, if you download something like "md5sum", the utility checksum MD5), the "C:\sys\wsh" directory for VBScripts (and JScripts named "wsh" since both are executed using the "Windows Scripting Host" or "wsh"), and soon. Then I add them to my %PATH% variable (Control Panel -> Advanced System Settings -> Advanced Tab -> " Environment Variables"), so Windows can always find them when you type them.

Combining all three parts will lead to setting your Windows systems so that wherever you can type a command line command, you can run your VBScript by simply typing its name base file. You can do the same for any file type/extension; As you probably saw in my %PATHEXT%, my system is configured to run Perl (.PLX;.PLW;.PL) and Python (.PY) scripts. (I also put "C:\sys\bat; C:\sys\scripts; C:\sys\wsh; C:\sys\bin" at the beginning of my %PATH% and put various batch files, script files, etc. in these directories so Windows can always find them. This is also useful if you want to "override" some commands: put the *.bat files in the path first so that the system finds them before the *. exe, for example, and then the *.bat file can run real program by providing the full path to the actual *.exe file. Learn about various sites in "batch file programming" to get detailed information and other examples of the power of the command line.. It's not dead yet!)

Last note:. Check some of the other sites for various warnings and cautions. This question was posed by a script called "converter.vbs" which is dangerously close to the command "convert.exe" which is Windows program to transform your hard drive from file FAT systems V file system NTFS. which can squeeze your HDD, if you made a text entry error.

On the other hand, using above mentioned methods, you can also insulate yourself from such errors. You can use CONVERT.EXE as an example. Rename it to something like "REAL_CONVERT.EXE", then create a file like "C:\sys\bat\convert.bat" which contains:

@ECHO OFF ECHO !DANGER! !DANGER! !DANGER! !DANGER, WILL ROBINSON! ECHO This command will convert your hard drive to NTFS! DO YOU REALLY WANT TO DO THIS?! ECHO PRESS CONTROL-C TO ABORT, otherwise.. REM "PAUSE" will pause the batch file with the message "Press any key to continue...", REM and also allow the user to press CONTROL-C which will prompt the user to abort or REM continue running the batch file. PAUSE ECHO Okay, if you"re really determined to do this, type this command: ECHO. %SystemRoot%\SYSTEM32\REAL_CONVERT.EXE ECHO to run the real CONVERT.EXE program. Have a nice day!

You can also use CHOICE.EXE on modern Windows to have the user enter "y" or "n" if they really want to continue, etc. Again, the power of batch (and script) files!

Most of these sites are aimed at batch files, but most of the information in them applies to running any type of file (*.bat), command file (*.cmd) and scripts (*.vbs, *.js, *.pl, *.py, etc.) .

Created an extensive batch script program to handle some automated file management and printing, and I need to call a vbs file for its sendkeys operation. Is there a way to do this without freezing the program?

I tried START / WAIT my.vbs and the script freezes when it enters .vbs

Does anyone have any other methods or switches you would recommend?

I'd like it to run silently if at all possible, and I need the /WAIT switch because I need the sendkeys operation to complete before the next step in the batch file.

timeout 5 timeout /?

TIMEOUT

Description: This utility accepts a timeout parameter to wait a specified period of time (in seconds) or until any key is pressed. It also accepts an option to ignore keypress.

List of parameters: /T timeout Specifies the number of seconds to wait. Valid range: -1 to 99999 seconds.

/NOBREAK Ignore key presses and wait specified time. /? Displays this help message.

NOTE. A timeout value of -1 means waiting indefinitely for a key press.

TIMEOUT /? TIMEOUT / T 10 TIMEOUT / T 300 / NOBREAK TIMEOUT / T - 1

Just call Correct vbs file path

BAT File Edit it...!!!

wscript " file-path "

Example:

wscript " D:\KmaniZoro\PGM\N++\VBS\inputbox.vbs "

This is a very old question, but the existing answers are outrageously vague and/or fail to identify the most important things when they are not just wrong. I'm not going to repeat what there are already other answers, but from other answers the following differences are missing:

Areas of use

VBScript code is not needs to procedural areas: he Maybe be written as script, which just does a bunch of procedural operations from top to bottom.

In VB6/VBA executable operations can only exist internal procedural areas.

Types

In VBScript, everything (variables, function return values, etc.) is a Variant (i.e. almost duck, as in JavaScript). When declaring a variable, it is prohibited to declare an explicit type. Keyword As prohibited!

In VB6 / VBA everything is default used by implicit Variant , but good VB6/VBA code uses explicit types where applicable.







2024 gtavrl.ru.