Set WshShell = CreateObject("WScript.Shell")
Set WshShell = CreateObject("WScript.Shell")
Возвращаемое значение: строка, путь к текущему каталогу.CurrentDirectory
Set WshShell = CreateObject("WScript.Shell")
MsgBox WshShell.CurrentDirectory
Возвращаемое значение: объект-коллекция "WshEnvironment", содержащая переменные среды. Необязательный параметр "Type" - строка, задаёт вид переменных. Возможные значения:Environment(<Type>)
Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment
MsgBox WshEnv.Item("WINDIR")
Set WshShell = CreateObject("WScript.Shell")
WScript.Echo "ПЕРЕМЕННЫЕ System:"
For Each Var In WshShell.Environment("System")
WScript.Echo Var
Next
WScript.Echo vbCrLf & "ПЕРЕМЕННЫЕ User:"
For Each Var In WshShell.Environment("User")
WScript.Echo Var
Next
WScript.Echo vbCrLf & "ПЕРЕМЕННЫЕ Volatile:"
For Each Var In WshShell.Environment("Volatile")
WScript.Echo Var
Next
WScript.Echo vbCrLf & "ПЕРЕМЕННЫЕ Process:"
For Each Var In WshShell.Environment("Process")
WScript.Echo Var
Next
Возвращаемое значение: объект-коллекция "SpecialFolders", содержащая пути к специальным папкам Windows. Некоторые специальные папки:SpecialFolders(<WshSpecialFolder>)
Set WshShell = CreateObject("WScript.Shell")
Set SpecialFolders = WshShell.SpecialFolders
MsgBox SpecialFolders.Item("Desktop")
MsgBox WshShell.SpecialFolders("Desktop")
Set WshShell = CreateObject("WScript.Shell")
For Each Folder In WshShell.SpecialFolders
WScript.Echo Folder
Next
Назначение: возвращает значение переменной среды текущего командного окна.ExpandEnvironmentStrings(<String>)
Set WshShell = CreateObject("WScript.Shell")
MsgBox WshShell.ExpandEnvironmentStrings("%WinDir%")
Назначение: выводит на экран модальное окно сообщения.Popup(<Text>,<SecondsToWait>,<Title>,<Type>)
Set WshShell = CreateObject("WScript.Shell")
WshShell.Popup "Текст сообщения",, "Текст заголовка", 4+16
Назначение: посылает одно или несколько нажатий клавиш в активное окно (имитация набора на клавиатуре).SendKeys(<String>)
{+} {^} {%} {~} {(} {)} {[} {]} {{} {}}
Задание неотображаемых символов и специальных клавиш:
<Backspace> - {BACKSPACE} или {BS} или {BKSP}
<Break> - {BREAK}
<Caps Lock> - {CAPSLOCK}
<Delete> - {DELETE} или {DEL}
<End> - {END}
<Enter> - {ENTER} или ~
<Esc> - {ESC}
<Home> - {HOME}
<Insert> - {INSERT} или {INS}
<Num Lock> - {NUMLOCK}
<Page Down> - {PGDN}
<Page Up> - {PGUP}
<Print Screen> - {PRTSC}
<Scroll Lock> - {SCROLLLOCK}
<Tab> - {TAB}
<Up Arrow> - {UP}
<Left Arrow> - {LEFT}
<Down Arrow> - {DOWN}
<Right Arrow> - {RIGHT}
<F1> - {F1}
<F2> - {F2} и т.д.
<Shift> - +
<Ctrl> - ^
<Alt> - %
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^{ESC}"
Назначение: создаёт новый независимый процесс, который запускает заданное приложение.Run(<Command>,<WindowStyle>,<WaitOnReturn>)
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "explorer /e,/root,""C:\Program Files"""
Set WshShell = CreateObject("WScript.Shell")
RetCode = WshShell.Run("notepad", 1, True)
MsgBox "Обработка завершена! Код возврата - " & RetCode
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("nslookup 127.0.0.1")
WScript.Sleep 7000
Set TextStream = WshExec.StdOut
Str = vbNullString
While Not TextStream.AtEndOfStream
Str = Str & Trim(TextStream.ReadLine()) & vbCrLf
Wend
MsgBox Str
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("notepad")
WScript.Sleep 2000
WshShell.AppActivate(WshExec.ProcessID)
WshShell.SendKeys "0123456789"
Назначение: активизирует указанное окно какого-либо приложения. Возвращает True в случае успеха и False в случае неудачи.AppActivate(<Title>)
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("notepad")
WScript.Sleep 2000
Res = WshShell.AppActivate(WshExec.ProcessID)
If Res Then WshShell.SendKeys("0123456789")
Назначение: удаляет из реестра заданный параметр или раздел целиком.RegDelete(<Name>)
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\NewKey\","Value"
WshShell.RegWrite "HKEY_CURRENT_USER\NewKey\Param","Value","REG_SZ"
MsgBox WshShell.RegRead("HKEY_CURRENT_USER\NewKey\Param")
MsgBox WshShell.RegRead("HKEY_CURRENT_USER\NewKey\")
WshShell.RegDelete "HKEY_CURRENT_USER\NewKey\Param"
WshShell.RegDelete "HKEY_CURRENT_USER\NewKey\"
Назначение: читает из реестра заданный параметр или значение по умолчанию для раздела.RegRead(<Name>)
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\NewKey\","Value"
WshShell.RegWrite "HKEY_CURRENT_USER\NewKey\Param","Value","REG_SZ"
MsgBox WshShell.RegRead("HKEY_CURRENT_USER\NewKey\Param")
MsgBox WshShell.RegRead("HKEY_CURRENT_USER\NewKey\")
WshShell.RegDelete "HKEY_CURRENT_USER\NewKey\Param"
WshShell.RegDelete "HKEY_CURRENT_USER\NewKey\"
Назначение: записываает в реестр заданный параметр или раздел.RegWrite(<Name>,<Value>,<Type>)
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\NewKey\","Value"
WshShell.RegWrite "HKEY_CURRENT_USER\NewKey\Param","Value","REG_SZ"
MsgBox WshShell.RegRead("HKEY_CURRENT_USER\NewKey\Param")
MsgBox WshShell.RegRead("HKEY_CURRENT_USER\NewKey\")
WshShell.RegDelete "HKEY_CURRENT_USER\NewKey\Param"
WshShell.RegDelete "HKEY_CURRENT_USER\NewKey\"
Назначение: протоколирует событие в журнале WindowsNT или в файле WSH.log. Возвращает True в случае успеха и False в противном случае.LogEvent(<Type>,<Message>,<Target>)
Set WshShell = CreateObject("WScript.Shell")
WshShell.LogEvent 4, "Test event!"
Назначение: возвращает объект "WshShortcut" или "WshURLShortcut", указывающий на ярлык .lnk или .url.CreateShortcut(<Path>)
Set WshShell = CreateObject("WScript.Shell")
Set WshURLShortcut = WshShell.CreateShortcut("C:\Microsoft.url")
WshURLShortcut.TargetPath = "http://microsoft.com"
WshURLShortcut.Save
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("notepad")
Возвращаемое значение: код выхода, устанавливаемый дочерней задачей при завершении выполнения.ExitCode
Set WshShell = CreateObject("WScript.Shell")
'запуск "xcopy" с заведомо ошибочными параметрами
Set WshExec = WshShell.Exec("xcopy abc123")
'пауза для запуска приложения
WScript.Sleep 2000
'чтение кода выхода
MsgBox WshExec.ExitCode
Возвращаемое значение: идентификатор запущенного процесса (PID).ProcessID
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("notepad")
WScript.Sleep 2000
WshShell.AppActivate WshExec.ProcessID
WshShell.SendKeys "0123456789"
Возвращаемое значение: состояние запущенного процесса. Возможные значения:Status
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("notepad")
WScript.Sleep 2000
MsgBox "status - " & WshExec.Status
WshExec.Terminate
WScript.Sleep 2000
MsgBox "status - " & WshExec.Status
Возвращаемое значение: объект "TextStream", соответствующий стандартному выходному потоку запущенной задачи.StdOut
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("nslookup")
Set InStream = WshExec.StdIn
InStream.WriteLine "help"
InStream.WriteLine "exit"
Set OutStream = WshExec.StdOut
Str = vbNullString
While Not OutStream.AtEndOfStream
Str = Str & Trim(OutStream.ReadLine()) & vbCrLf
Wend
MsgBox Str
Возвращаемое значение: объект "TextStream", соответствующий стандартному входному потоку запущенной задачи.StdIn
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("nslookup")
Set InStream = WshExec.StdIn
InStream.WriteLine "help"
InStream.WriteLine "exit"
Set OutStream = WshExec.StdOut
Str = vbNullString
While Not OutStream.AtEndOfStream
Str = Str & Trim(OutStream.ReadLine()) & vbCrLf
Wend
MsgBox Str
Возвращаемое значение: объект "TextStream", соответствующий стандартному потоку ошибок запущенной задачи.StdErr
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("nslookup")
Set InStream = WshExec.StdIn
InStream.WriteLine "abc123"
InStream.WriteLine "exit"
Set OutStream = WshExec.StdErr
Str = vbNullString
While Not OutStream.AtEndOfStream
Str = Str & Trim(OutStream.ReadLine()) & vbCrLf
Wend
MsgBox Str
Назначение: пытается закрыть приложение, посылая ему сообщение WM_CLOSE. Если это не срабатывает, задача завершается принудительно.Terminate
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("notepad")
WScript.Sleep 2000
MsgBox "status - " & WshExec.Status
WshExec.Terminate
WScript.Sleep 2000
MsgBox "status - " & WshExec.Status
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
Arguments
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Возвращаемое значение: строка, описание в поле "Комментарий" ("Comment") в свойствах ярлыка.Description
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Возвращаемое значение: строка, полный путь к файлу ярлыка.FullName
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Возвращаемое значение: строка, содержащая названия горячих клавиш, разделённые знаком "+".Hotkey
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Возвращаемое значение: строка, содержащая расположение иконки для ярлыка в формате "путь к файлу, индекс иконки". Индексы иконок начинаются с нуля.IconLocation
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Возвращаемое значение: строка, содержащая путь к исполняемому файлу.TargetPath
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Возвращаемое значение: число, определяющее вид окна запускаемого приложения. Возможные значения:WindowStyle
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Возвращаемое значение: строка, путь к рабочему каталогу ярлыка.WorkingDirectory
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Назначение: сохраняет ярлык.
Set WshShell = CreateObject("WScript.Shell")
Set WshShortcut = WshShell.CreateShortcut("C:\Notepad.lnk")
WshShortcut.Arguments = "C:\autoexec.bat"
WshShortcut.Description = "Пробный ярлык"
WshShortcut.HotKey = "CTRL+ALT+F"
WshShortcut.IconLocation = "shell32.dll, 5"
WshShortcut.TargetPath = "notepad.exe"
WshShortcut.WindowStyle = 1
WshShortcut.WorkingDirectory = "C:\"
MsgBox WshShortcut.FullName
WshShortcut.Save
Set WshShell = CreateObject("WScript.Shell")
Set WshUrlShortcut = WshShell.CreateShortcut("C:\Microsoft.url")
Возвращаемое значение: строка, полный путь к файлу ярлыка.FullName
Set WshShell = CreateObject("WScript.Shell")
Set WshUrlShortcut = WshShell.CreateShortcut("C:\Microsoft.url")
WshUrlShortcut.TargetPath = "http://microsoft.com"
MsgBox WshUrlShortcut.FullName
WshUrlShortcut.Save
Возвращаемое значение: строка, содержащая путь к документу Интернет.TargetPath
Set WshShell = CreateObject("WScript.Shell")
Set WshUrlShortcut = WshShell.CreateShortcut("C:\Microsoft.url")
WshUrlShortcut.TargetPath = "http://microsoft.com"
MsgBox WshUrlShortcut.FullName
WshUrlShortcut.Save
Назначение: сохраняет ярлык.
Set WshShell = CreateObject("WScript.Shell")
Set WshUrlShortcut = WshShell.CreateShortcut("C:\Microsoft.url")
WshUrlShortcut.TargetPath = "http://microsoft.com"
MsgBox WshUrlShortcut.FullName
WshUrlShortcut.Save
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?