Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
WScript.Shell é um objeto do Windows Script Host (WSH) que permite a automação de várias tarefas no ambiente Windows. Ele é especialmente útil para administradores de sistemas e desenvolvedores que precisam executar comandos, manipular arquivos e interagir com o sistema operacional de forma programática. Este artigo explora como utilizar WScript.Shell para automatizar tarefas comuns no Windows, fornecendo exemplos práticos e detalhados.
Exemplos:
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run "cmd.exe /c echo Hello, World!"
Set shell = Nothing
Neste exemplo, o script cria um objeto WScript.Shell e usa o método Run
para executar um comando CMD que imprime "Hello, World!" na tela.
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run "notepad.exe"
Set shell = Nothing
Este script abre o Bloco de Notas (Notepad) no Windows.
Dim shell, shortcut, desktopPath
Set shell = CreateObject("WScript.Shell")
desktopPath = shell.SpecialFolders("Desktop")
Set shortcut = shell.CreateShortcut(desktopPath & "\MyShortcut.lnk")
shortcut.TargetPath = "C:\Path\To\Your\Application.exe"
shortcut.Save
Set shell = Nothing
Set shortcut = Nothing
Aqui, o script cria um atalho na área de trabalho para uma aplicação especificada.
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Environment("SYSTEM")("Path") = shell.Environment("SYSTEM")("Path") & ";C:\NewPath"
Set shell = Nothing
Este script adiciona um novo caminho ao PATH do sistema.