Hello, I’m trying to edit a vbs script that I found online to help me remotely connect to a few servers (using a servers.txt file) and make a copy of a specific file called test.txt (it’s the same file name and path on all servers but with different configuration for each server) and add the date to the file name (test_todays data.txt) but not overwrite the previous days file. I’m also trying to copy that test_date.txt file to a staging folder on the same directory to make some changes to it. Thank you, David
Dim oFSO, sCList, sComputer, sWinDir, colOperatingSystems, oOperatingSystem Dim oWMIService, Error, sWinDirRaw, fso, drv, str Const ForReading = 1 Const OverwriteExisting = True ‘Get computers ——————————————– Set oFSO = CreateObject(“Scripting.FileSystemObject”) Set sCList = oFSO.OpenTextFile(“c:scriptsservers.txt”) Do Until sCList.AtEndOfStream sComputer = sCList.ReadLine ‘Get WinDir name ———————————————————— Set oWMIService = GetObject(“winmgmts:\\” & sComputer) Set colOperatingSystems = oWMIService.InstancesOf(“Win32_OperatingSystem”) For Each oOperatingSystem In colOperatingSystems sWinDirRaw = oOperatingSystem.WindowsDirectory sWinDir = StripDriveInfo(sWinDirRaw) Next ‘If test.txt exists, make a backup copy named test_todaysdate.txt —————————————– If oFSO.FileExists(“\\” & sComputer & “d$” & sWinDir & “ABCMy SystemTestConftest.txt”) Then oFSO.CopyFile “\\” & sComputer & _ “d$” & sWinDir & “ABCMy SystemTestConftest.txt”, “\\” & sComputer & _ “d$” & sWinDir & “ABCMy SystemTestConftest_20110907.txt” End If ‘Copy tests file ————————————————————— oFSO.CopyFile “d$ABCMy SystemTestConftest_20110907.txt”, “\\” & sComputer &_ “d$” & sWinDir & “ABCMy SystemTestConfstagingtest_20110907.txt”, OverwriteExisting If Error <> 0 Then WScript.Echo “Error copying file to ” & sComputer Else WScript.Echo “Finished script On ” & sComputer WScript.Echo “———————————-” End If Loop sCList.Close WScript.Echo “Finished Updates on all computers” MsgBox (“Exit?”) Function StripDriveInfo(path) ‘Set fso = CreateObject(“Scripting.FileSystemObject”) drv = oFSO.GetDriveName(path) If Len(drv) >0 Then str = Mid(path, Len(drv) + 2) Else str = path End If StripDriveInfo = str End Function
VBS to Remotely Make a copy of a File on Multiple Systems
Verify NTP
VBScript to verify a NTP Time source
VBS output to text
How do I change this code to: instead of poping up a window, to output the results to a text file?
”create a connection object set connObj = CreateObject(“ADODB.Connection”)
”create a command object set cmdObj = CreateObject(“ADODB.Command”)
”set the properties connObj.Provider = “ADsDSOObject” connObj.Open “Active Directory Provider” set cmdObj.ActiveConnection = connObj cmdObj.Properties(“Page Size”) = 25
”create the LDAP query for your domain – userAccountCountrol with a value of 2 = disabled cmdObj.CommandText = “<LDAP://dc=abc,dc=main>;(&(objectCategory=User)(userAccountControl:1.2.840.113556.1.4.803:=2));Name;Subtree” ”execute the query set rsObj = cmdObj.Execute
”place the cursor at the first record and loop over the records until we hit the end of file marker rsObj.MoveFirst do until rsObj.EOF Wscript.Echo rsObj.Fields(“Name”).Value rsObj.MoveNext loop
Autoprint to PDF Printer
Does anyone know if there is a script (VBS, BAT or otherwise) that will send a requested file (xls, doc, txt) to a local installed PDF printer and render it without user intervention?
Set Page orientation
Can anyone help identify how to set the Page Layout Orientation of an XLSX file in VBS? I am using the below script example for reference.
Set obj = CreateObject("Excel.Application") Set objWorkbook = obj.Workbooks.Open("C:pathtest.xlsx") obj.ActiveSheet.PageSetup.Orientation = xlLandscape obj.ActiveWorkbook.Saveas "C:pathtest.xlsx" obj.ActiveWorkbook.Close
Thank you.
Extract Data from SAP using VBScript
Hi,
I am trying to extract data out of SAP using VBScript. I remember this worked earlier, but ever since we upgraded to VB7, I am getting an error. Can you please look into this?
code:
Dim R3, MyFunc, App, objFileSystemObject, filOutput, objmessage As Object
Dim nTotalRecords As Long
‘ Define the objects to hold IMPORT parameters
Dim QUERY_TABLE As Object
Dim DELIMITER As Object
Dim NO_DATA As Object
Dim ROWSKIPS As Object
Dim ROWCOUNT As Object
‘ Define the objects to hold the EXPORT parameters
‘ None for RFC_TABLE_READ
‘ Define the objects to hold the TABLES parameters
‘ Where clause
Dim OPTIONS As Object
‘ Fill with fields to return. After function call will hold
‘ detailed information about the columns of data (start position
‘ of each field, length, etc.
Dim FIELDS As Object
‘ Holds the data returned by the function
Dim tDATA As Object
‘ Use to write out results
Dim ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow, iField, iLength As Integer
Dim var_return As String
Public Function RFC_READ_TABLE_MARA() ‘********************************************** ‘Create Server object and Setup the connection ‘********************************************** Set objFileSystemObject = CreateObject(“Scripting.FileSystemObject” attachpath1 = “C:ExtractsMARA.rtf” Set R3 = CreateObject(“SAP.Functions”) R3.Connection.system = “xxx” R3.Connection.SystemNumber = “xxx” R3.Connection.client = “xxx” R3.Connection.User = “xxx” R3.Connection.Password = “XXX” R3.Connection.language = “EN” R3.Connection.applicationserver = “XXX” If R3.Connection.logon(0, True) <> True Then MsgBox “No connection to R3!” var_return = ” has Failed” sendmessage (var_return) Exit Function End If ‘***************************************************** ‘Call RFC function RFC_READ_TABLE ‘***************************************************** Set MyFunc = R3.Add(“RFC_READ_TABLE”) ERROR RECEIVED IS: Run-time error ‘-2147352568′ Bad variant type Thank you
Instring function using vbscript
how to extract the comma till the last and display only the last value suppose if i insert 100000 rows it should show 100000 not like from 1,2,3, till 100000 it should extract till last comma please help me
Select Statement & Where Clause ….
VBscript to send email on service failure
Reading a value from HKLM registry and writing it HKLM registry
Remove character from number VBscript
how do i remove from 1.5.600 the .600 part? i just need 1.5
I tried left but it seems only works with strings
Can I find an Excel merged cell size in VBScript?
I have a set of Excel spreadsheets which all have similar properties and I’m trying to automate a set of processes on them.
I’m a compelte VB beginner, but it’s going ok – I’ve just hit a stumbling block with the internet isn’t being very helpful with.
Once I have found a certain cell, is it possible to determine how many columns it is merged across?
Many thanks for any help!
Rename Printers in logon for Windows Server 2003, with VBScript
Hi peeps!
Another question! This has been buggin me for a while.
Right, I have a Windows Server 2003 SP2 domain (Not R2) and i have about 90 Windows XP professional SP3 clients. Now I have at least 3 printers that are being shared. The printer share names are:
printer2
printer3
printer4
when staff and student log in they dont get “printer2″ “printer3″ and “printer4″ in printers and faxes window,
it comes up with
“Brother HL-4040cn on server”
“NRG MP C2500 on server”
etc…
Here’s my script
————————————————
// Declare All variables Option Explicit '// Comment this out for debugging! On Error Resume Next '// Variables Dim network, filesys, shell Dim printer2, printer3, printer4, serverpath, servername '// Create Windows Scripting Object Set network = CreateObject("WScript.Network") Set filesys = CreateObject("Scripting.FileSystemObject") Set shell = CreateObject("WScript.Shell") '// Define UNC Paths servername = "pvserver" serverpath = "\" & servername & "" printer2 = serverpath & "Printer2" printer3 = serverpath & "Printer3" printer4 = serverpath & "Printer4" '// Dont run on the server! If LCase(network.ComputerName) = servername Then err.Raise1, "Can not run on the server!" End If '// Map Printers network.AddWindowsPrinterConnection printer2 network.AddWindowsPrinterConnection printer3 network.AddWindowsPrinterConnection printer4 '// Set default printer network.SetDefaultPrinter printer2 '// map network drives network.MapNetworkDrive "s:", serverpath & "software" network.MapNetworkDrive "o:", serverpath & "Pupil Resources" network.MapNetworkDrive "z:", serverpath & "Media" network.MapNetworkDrive "G:", serverpath & "Sherston"
———————————–
Can anyone rewrite this so you can make it say “printer2″ “printer3″ ”printer4″ in printers and faxes in peoples logins?
I’m ripping my hair out
many thanks
Phil
Is it possible to have Regular Expressions in Excel without VBScript?
How to install Windows updates without Open File Security popup
Scripting MMC
Uploading attachments to QC using VBScript
VB Script to Create a Scheduled Task on a Remote Machine Using Alternate Credentials
How to connect to quick 3270 secure screen through VBA macro?
Hi, I use the following code to connect to quick 3270 macro and it also connect to the screen. But when I run the macro for the first time it works, but does not work when I run the same macro for second time. If I restart the mainframe then the macro runs. Below is the code.
Sub getdata() Set objQuick3270 = CreateObject("Quick3270.Application") objQuick3270.Visibility = True Set objSession = objQuick3270.ActiveSession Set objScreen = objSession.Screen HostSettleTime = 3000 ' milliseconds objSession.Server_Name = "Server Name" 'Server that u are using objSession.Model_Name = "IBM-7248-2-A" objSession.Connect
Please help me in this regard.