Here is a memento of several useful commands in VBScript (common declarations, check files, folders and registry, create or delete files and folders, copy files and folders).
TechNet: https://technet.microsoft.com/en-us/library/ee198844.aspx
W3Schools: http://www.w3schools.com/asp/vbscript_ref_functions.asp
Date/Time, Conversion, Format, Math, Array, String…
This article will be updated progressively.
1. Common Declarations
Set fso = CreateObject("scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
Set WshUsrEnv = WshShell.Environment("Process")
Set objNetwork = CreateObject("Wscript.Network")
CurrentPath = fso.GetAbsolutePathName(".")
2. Line Break
VbCrLF
3. Registry
' Create Key
Set WshShell = CreateObject("Wscript.Shell")
WshShell.RegWrite "HKLM\SOFTWARE\MyKey\MySubKey\", ""
' Create Value
Set WshShell = CreateObject("Wscript.Shell")
WshShell.RegWrite "HKLM\SOFTWARE\MyKey\MySubKey\MyValue", "1", "REG_SZ"
' Delete Key
Set WshShell = CreateObject("Wscript.Shell")
WshShell.RegDelete "HKLM\SOFTWARE\MyKey\MySubKey"
4. Check / Create Files and Folders
' Check Folder
Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FolderExists("C:\Wordir")) Then
fso.CreateFolder("C:\Workdir")
End If
' Check File
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists("C:\Wordir\MyFile.txt")) Then
MsgBox("The file exists")
End If
5. File Copy
' Copy File
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "C:\Workdir\Source\MyFile.txt", "C:\Workdir\Destination\MyFile.txt"