Documentación VBS
Estructuras de control
Bucle FOR
I = 1
For I = 1 to 22
"Accion"
Next
Bucle FOR para arrays
For Each strSubkey In arrSubkeys
"Accion"
Next
Manejo de ficheros
Codigo común para ficheros
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objfso
Dim objficherolog
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objFicheroLog = objfso.OpenTextFile( "ruta completa y nombre del log", ForAppending , True )
Borrar Carpeta
objfso.DeleteFolder "Ruta completa de la carpeta a borrar"
Copiar fichero
objfso.CopyFile "c:\hola.txt","c:\prueba\"
Comprobarr si existe un fichero
if not objfso.FileExists(strDirectorioProgramas & "\Novadigm\Radskman.exe") then
Leer un Fichero , una linea una posicion del Array
Dim vector()
Do Until miFichero.AtEndOfStream
reDim Preserve vector(i)
vector(i) = mifichero.ReadLine
i = i + 1
Loop
Buscar en un Array
Dim cont
For cont = Lbound(del_mad) to UBound(del_mad)
If del_mad(cont) = Subred then
WScript.Echo "Encontrado"
Listar Software Instaldo en maquina local
Dim objfso
Dim objficherolog
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objFicheroLog = objfso.OpenTextFile( "c:\listado.log", 8, True )
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"
Set objReg = GetObject("winmgmts://" & strComputer & _
"/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
WScript.Echo "Installed Applications" & VbCrLf
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, _
strEntry1b, strValue1
End If
If strValue1 <> "" Then
objFicheroLog.WriteLine VbCrLf & "Display Name: " & strValue1
End If
Next
Desinstalar Software
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Cadena localizada en listar software'")
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
Instalar Software
Dim objWSHShell, objExec
Set objWSHShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
Set objExec = objWSHShell.Exec("Ruat completa del EXE y parametros")
' Espera a la correcta finalizacion del EXE
Do While objExec.Status = 0
WScript.Sleep 500
Loop
set WshShell = Nothing
Montar Unidades de Red
on error resume next
WshNetwork.RemoveNetworkDrive CONST_UNIDAD_DESCRIPTOR
WshNetwork.MapNetworkDrive NUEVA_UNIDAD, RECURSO_COMPARTIDO , false , USUARIO , PASSWORD
Trabajo con el registro
Dim RegShell
Set RegShell = WScript.CreateObject("WScript.Shell")
"Entrada de registro , se mantienen las comillas"
Dim strRuta
strRuta = "1"
Dim valor
valor = "1"
RegShell.RegWrite strRuta, valor ,"REG_DWORD"
Set RegShell = Nothing

