Links:
http://www.activexperts.com/activmonitor/windowsmanagement/scripts/
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/
Simple Scripts
Copy File (having desplay problems:
'Copy
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.CreateTextFile(".\xxxxx.xxx", True)
aFile.WriteLine("xxxx")
Set aFile = fso.GetFile(".\xxxxx.xxx")
aFile.Copy("./xxxxx.xxx")
'Alternate fso.CopyFile "C:\xxxxxx\*.*", "D:\xxxxxx\",TRUE
'Copy Folder fso.CopyFolder "C:\xxxxxx\*", "D:\xxxxxx\xxxxxx\",TRUE
Delete File:
'Delete
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.GetFile(".\xxxxx.xxx")
aFile.Delete
Move/Rename File:
'Move/Rename
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.CreateTextFile(".\xxxxx.xxx", True)
aFile.WriteLine("xxxx")
Set aFile = fso.GetFile(".\xxxxx.xxx")
aFile.Move ".\xxxxx.xxx"
Map Network Drive:
'Map Network Drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "Z:" , "\\Servername\share"
Change Password on remote computers (having display problems):
Const InputFile = "c:\list.txt"
Const PassFile = "c:\pass.txt"
Const LogFile = "c:\passlog.txt"
Const ForAppending = 8
Const ForReading = 1
' Read InputFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile, ForReading)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
' Read PassFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(PassFile, ForReading)
strPassword = objFile.ReadAll
objFile.Close
' Open LogFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.OpenTextFile(LogFile, ForAppending)
On Error Resume Next
For Each strComputer In arrComputers
' Pinging. Inten
Set objShell = CreateObject("Wscript.Shell")
Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & strComputer)
If InStr(objScriptExec.StdOut.ReadAll, "Reply") > 0 Then
' User manipulation, in my case the user is "Test",
' change it to the local Administrator user name
Err.Clear
Set objUser = GetObject("WinNT://" & strComputer & "/ntadmin, user")
If Err.Number Then
WScript.Echo " " & strComputer & " - ERROR: User name not found"
objLog.WriteLine "" &Date &", " &Time & ", " & strComputer & ", ERROR: User name not found"
Err.Clear
Else
objUser.SetPassword strPassword
objUser.SetInfo
WScript.Echo " " & strComputer & " - Password successfully changed"
objLog.WriteLine "" &Date &", " &Time & ", " & strComputer & ", Password Successfully Changed"
End If
Else
WScript.Echo " " & strComputer & " - ERROR: Host not responding"
objLog.WriteLine "" &Date &", " &Time & ", " & strComputer & ", ERROR: Host not responding"
End If
Next
objLog.Close
Call a Batch file (.bat) from VBS (code not showing correctly)
'Run Batch File
sBatFile = "c:\xxxxxx\xxxxx.bat"
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FileExists(sBatFile) Then
MsgBox "Could not find batch file, quitting!", _
vbCritical + vbSystemModal, "Text search"
WScript.Quit
End If
' just in case there is spaces in the path
sBatFileShort = oFSO.GetFile(sBatFile).ShortPath
' Run the batch file hidden, and let the VBScript wait for
' the batch file to finish
oShell.Run sBatFileShort, 0, True