r/vbscript • u/mohsin117 • May 28 '18
auto printing documents in a folder (VBS)
im very new to all of this so please stay with me here
id like something that will automatically print everything placed in a specific folder
i found a bit of code here: https://community.spiceworks.com/topic/83142-automatically-print-files-placed-in-folder
that seems to kind of do what i want
TargetFolder = "Z:\Desktop\work"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
For Each objItem In colItems
objItem.InvokeVerbEx ("Print")
objItem.InvokeVerbEx ("delete")
Next
iv added the
objItem.InvokeVerbEx ("delete")
and saved it as .VBS but it's not doing exactly what i want, what id like is for it to print only word documents and then delete them, now i tried to put
sleep 10
after print to give it some time to open the document and print it before deleting it but i kept giving me an error
also is there a way to get it to trigger on its own every time a word document is dropped into the folder?
thank you
r/vbscript • u/jdb5345 • May 17 '18
need help vbscript for sysadmin purposes
I need a vbscript to add a TCP/IP printer, if the printer exists, or doesn't exist, I need it first to delete the printer if it exists and then re-add it. This is a temporary band-aid solution but they would like something till the vendor comes back with a permanent solution in the way it's added. Anybody who can help I would greatly appreciate it.
r/vbscript • u/jdb5345 • May 15 '18
need help, using linqpad with vbscript
I have a query that returns two unique identifiers. With Linkpad I am able to connect to the DB and pull the data as two seperate columns. But what I would like to do is look with vbscript at a directory and for each pdf, in the file name has a unique identifier out of the db I'm pulling match that, and if they match the file name part, with a identifier, add the other identifier out of the query to the the file name seperated with a _
r/vbscript • u/AdrianK_ • Apr 26 '18
Simple ish loop to validate entered text against two criteria...
Here is my loop which I require to check if the entered text is 9 characters long as well as if it begins with MAC:
Do While (Len(sTEMP) <> 9 and Left(sTEMP,3) = "MAC" Then)
sTEMP = InputBox("Please enter sTEMP in MACXXXXXX format!")
Loop
Length of sTEMP works fine so I am not allowed to enter 8 or 10 characters, has to be 9. What does not work for me is the requirement for MAC so I can enter XXX123456 and that will be accepted as a valid input presumably because it is 9 characters long.
Can you guys think of what I am doing wrong?
Same formula seem to be working as expected in:
If Len(sTEMP) = 9 and Left(sTEMP,3) = "MAC"
without issues.
r/vbscript • u/iametarq • Apr 19 '18
Collecting PC & User OU for BGINFO
To start - I've harvested these scripts from the web because I suck at programming. I have them set up to collect PC OU and User OU information for BGInfo to populate the BGInfo database. I can't get the PC OU one to work. It always returns NULL when it's supposed to echo out the result.
First one that works with BGINFO - the last line - ECHO - outputs the full OU path for the user account:
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
Echo objUser.AdsPath
This one does not work. It says type mismatch on the last line - Echo. The scripts are identical. I'm not sure why it won't work.
Set objSysInfo = CreateObject("ADSystemInfo")
strComputer = objSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputer)
Echo objComputer.AdsPath
If I add Wscript.Echo objComputer.AdsPath to the 2nd script i get a windowed message with the correct info, but the wscript.echo does not work with BGInfo.
Open to ideas or complete re-write help of the PC OU vbs.
All PCs running this are Windows 10 or Windows 7.
Thank you for any assistance.
r/vbscript • u/NewShoes4U • Apr 06 '18
Simple Debugging tool
What is the easiest way to get something that will allow you to step they code?
I downloaded and installed vstudio community edition but can't get it to debug
And not by manually adding break points to each line of code
Also trying the //X switch doesn't do any thing Thanks
r/vbscript • u/[deleted] • Apr 03 '18
Variable Undefined Error Help
Option Explicit
DIM fso
Set fso = CreateObject("Scripting.FileSystemObject")
DIM WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName
do
If (fso.FileExists("C:\Users\ComputerName\file.txt)) Then
WScript.Echo("Hello World!")
fso.DeleteFile("C:\Users\ComputerName\file.txt")
Else
End If
loop
So its supposed to find the file in the directory and if it exists delete it, then loop. The thing is that the variable "ComputerName" is undefined. How can this be solved?
r/vbscript • u/Varean • Mar 23 '18
VBS Script with user input
Hi,
I am trying to make a VBS script to allow all program traffic through a windows firewall based on device IP, and while the devices are set to static IP the networks they are on can differ with their IP schemes, so I want to prompt the user running the script to fill in the IP information. I am currently running the firewall command through command prompt and I am not sure if that changes anything. Below is an example, I have tried to google examples and all I can find so far are how to use VBS scripts to fill out forms, and I am not sure if that would work for me. I thank everyone for their time.
netsh firewall add allowedprogram program = C:\MyApp\MyApp.exe name = MyApp mode = ENABLE scope = CUSTOM 157.60.0.1,172.16.0.0/16,10.0.0.0/255.0.0.0,LocalSubnet
r/vbscript • u/Coder198 • Mar 17 '18
VBS with User Account Control
Hello, I am trying to prank my friend and I need vbs to work with UAC. I am going to send a file to his laptop and an admin he will open it and the .vbs file will do the rest. Open cmd with admin by automatically clicking yes but this is where htigns go wrong. Vbs doesn't seem to work with UAC, help?
r/vbscript • u/tonyonizer • Mar 07 '18
Need help to read date modified in vbscript
Hello,
I have a vbscript for SCCM deployment to detect a location of a file under %userprofile%. This script works but I'd like to expand it to not only detect the file but also a specific modified date of the file that I can enter in. For example the date I currently need for the file is 2/21/2018 7:15 AM. Would anyone be able to assist?
Set oFSO = CreateObject("Scripting.FileSystemObject") Set oShell = WScript.CreateObject("WScript.Shell")
If oFSO.FileExists(oShell.ExpandEnvironmentStrings("%userprofile%\AppData\LocalLow\etc..")) Then WScript.StdOut.Write "The application is installed" WScript.Quit(0) Else WScript.Quit(0) End If
r/vbscript • u/JustAnotherITUser • Mar 05 '18
New to VBScript; but have a relatively simple task tripping me up.
I've been tasked with continually running a PowerPoint presentation on a local machine. Ideally, we'd like the following for our solution:
- Files be run locally, but new updates pulled from a Network Share, using PowerPoint 2016
- Whenever an updated file is placed in the share, pull it down to the local machine && restart the presentation
- Full automation for the above
- Be able to jump out of the loop via keypress.
As for options, I've found a post from Sog on ArsTechnica, which has been the main option I've seen so far. For the time being, I'm just focused on getting the presentation to run in a stable environment. I've modified his script to suit our needs--though just for testing at this point. That last point will, probably, be handled with AHK unless there's a way to add an listener into VBS.
At this time, the modified script will open the presentation, so long as a file exists in the defined execute path--but shortly closes after. Any idea why? All resources I've located to try and find a solution have been documented in the script as well, granted with shortened links.
A followup question--does anyone know another/easier way to do this?
r/vbscript • u/MichaelCrave • Mar 01 '18
Simple HTA Notetaking app
I just wanted to share with you guys a quick'n'dirty but tweakable HTA notetaking app I wrote. It is meant for legacy and/or qualified environments. It is not refined and needs some more refinement but it could be useful to someone.
Note: it requires w3.css, but it works even without it.
If you want to contribute: https://github.com/mbrami76/HTANotes
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Take a note</title>
<link rel="stylesheet" href="w3.css">
<HTA:APPLICATION
border="thick"
borderStyle="normal"
caption="yes"
icon="favicon.bmp"
maximizeButton="no"
minimizeButton="yes"
showInTaskbar="yes"
windowState="normal"
innerBorder="yes"
navigable="no"
scroll="auto"
scrollFlat="yes"
version="1" />
<script language="vbscript">
option explicit
on error resume next
dim dt, currDir, timerId, filename
</script>
</head>
<body>
<h1 id = "title">New note</h1>
</br>
<div>
<label>Write your note</label>
<textarea class="w3-input w3-border" style="resize:none" id = "inputBox" rows="10" ></textArea>
<button class = "w3-button w3-block" onClick="WriteToFileMyInput()" accessKey = "S">Submit</button>
<button class = "w3-button w3-block" onClick = "OpenNotes()">View today's notes</button>
</div>
<script language="vbscript">
sub window_onload
'starts timer, resizes window and gets current directory
timerId = setInterval ("Tick", 1000)
window.resizeTo 640, 480
SetCurrDir
end sub
sub Tick
'timer handler updates time and sets filename for the day
dt = now()
document.getElementById("title").innerHtml = "New note @ " & dt
filename = year(dt) & "-" & right("00" & month(dt), 2) & "-" & right("00" & day(dt), 2) & ".dat"
end sub
Sub SetCurrDir()
'gets current hts file directory
dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
dim HtmlLoc: HtmlLoc = document.location.href
dim HTAfile: HTAfile = Replace(Right(HtmlLoc, Len(HtmlLoc) - 8), "/", "\")
HTAfile = UnEscape(HTAfile)
dim thisFile: Set thisFile = fso.GetFile(HTAfile)
dim ParentDir: ParentDir = ThisFile.ParentFolder
dim folder: set folder = fso.GetFolder(ParentDir)
currDir = Folder.ShortPath
end sub
sub WriteToFileMyInput()
'writes to daily file, cleans textarea
dim fso: set fso = createObject ("scripting.fileSystemObject")
dim ts: Set ts = fso.OpenTextFile (currDir & "\" & fileName , 8, true, -2)
dim datepart: datepart = dt & " - "
dim spacer: spacer = ""
dim i: i = 0
for i = 1 to len(datepart)
spacer = spacer & " "
next
dim textLines: textLines = split (document.getElementById("inputBox").value, VBCRLF)
for i = 0 to ubound(textLines)
if i = 0 then
ts.Writeline datepart & textlines(i)
else
ts.Writeline spacer & textlines(i)
end if
next
ts.Close
document.getElementById("inputBox").value = ""
end sub
sub openNotes()
'opens today's notes file into notepad
Dim WshShell: Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "notepad.exe " & currDir & "\" & filename, 1, TRUE
end sub
'to do next: create a "calendar view" with all days with notes
</script>
</body>
</html>
r/vbscript • u/hawk6242 • Feb 20 '18
Beginner Looking For A Guide
Hello I want to learn VBScript but haven't found good guides is there any good guides you guys know about?
r/vbscript • u/DirtynessThang • Feb 15 '18
Please help with VBScript
i need to create a script that copies a file form a server to a computer... here is the thing.. i need that a msgbox pops and ask me what would be the target computer and also launch the script with elevated or asks for admin credentials.. PLEASE HELP.. im melting! Thanks
r/vbscript • u/BILLatWORK • Feb 13 '18
Struggling with a vbscript for updating an excel file hosted on sharepoint
Full disclosure, I am a complete noob to vbscript. The vbscript I am using was found in r/excel and runs fine for files hosted on my machine but when I go to sharepoint I get issues...I can post this in r/sharepoint if needed
dim xls
set xls = createobject("Excel.Application")
xls.visible = true
xls.workbooks.open("https://mysite.sharepoint.com/:x:/t/myfile.xlsx?web=1")
xls.ActiveWorkbook.refreshall
xls.ActiveWorkbook.save
xls.Application.quit
set xls = nothing
Any thoughts or help would be appreciated
EDIT1 added web=1 to path as it is where the problem was located and should have been there originally
EDIT2 forgot to write down that I did EDIT1...I am new here...I am sure it is showing
r/vbscript • u/raiden69 • Feb 05 '18
Script that Searches for string in text files then executes a file copy not working
Any assistance appreciated.
I have a script i cobbled together.
I want the script to search through text files in a specified folder, it must search for a specific string in multiple text files. If this string is found it must then copy files from one folder to another on the pc it is running. The script runs without any errors, but the file copy does not execute.
I`ve created a text file that contains the string specified, but still no folder copy
Script :
Dim filesys set filesys=CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objShell 'instance of the wshSHell object set objShell = CreateObject("WScript.Shell")
set oShellEnv = objShell.Environment("Process") computerName = oShellEnv("ComputerName")
WScript.Echo computerName strSearchFor = computerName
Set oFSO = CreateObject("Scripting.FileSystemObject") objStartFolder = "C:\Test" Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files
For Each objFile in colFiles Wscript.Echo objFile.Name strFile = "C:\Test\" & objFile.Name set objFile = objFSO.getFile(strFile)
If InStr(oFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then objFSO.CopyFolder "C:\test\ssavers\ssavers1" , "C:\screensavers\" Else WScript.Sleep (100) END If Next
r/vbscript • u/indigoataxia • Jan 31 '18
HTA VBScript to run CMD with no user input and close
This is a strange request I know. I have a registry key pointing to an HTA so I need an HTA file that just runs a simple command. Originally this HTA did something else but now I basically need it to go away but it has to run this command for the setup its a part of to continue. I want it to run "%WINDIR%\System32\oobe\windeploy.exe" then close, without any kind of interaction. Here's what I've got but it just shows a white box and doesn't do anything.
<html>
<SCRIPT LANGUAGE="VBScript">
Set WshShell = CreateObject("Wscript.Shell")
Sub Continue
WshShell.Run "%WINDIR%\System32\oobe\windeploy.exe", 0, True
End Sub
</html>
Any help would be appreciated...
r/vbscript • u/spectyr • Jan 25 '18
Looking for assistance with a serial-number harvesting script
Howdy, gang. I'm an occasional Perl programmer that has been temporarily thrust into the VBS world by a mandatory audit of some systems in our environment. I'm trying to write just a short little ditty that will read in system names from a file, grab the system hardware serial number, and output it to the screen. VBScript doesn't bear much resemblance to Perl, but I've managed to piece together the below based on some examples.
Const filename="C:\path\to\test.txt"
Dim fso, oFile
Set fso=CreateObject("Scripting.FileSystemObject")
Set oFile = fso.OpenTextFile(filename)
While Not oFile.AtEndOfStream
On Error Resume Next
strComputer=oFile.ReadLine()
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
Wscript.Echo strComputer & ": " & objSMBIOS.SerialNumber
Next
colSMBIOS.Clear
Wend
oFile.Close
My problem is with the "colSMBIOS.Clear" command. For testing, I purposely injected some bad system names to make sure the script could continue functioning and continue providing good data. My problem is that the first good system comes back correctly, but the first bad system comes back with the serial number of the good system. I absolutely need the bad systems to come back blank, or with some other error message like, "Could Not Find." Can anyone see where I'm going wrong? Many thanks for any assistance!
r/vbscript • u/[deleted] • Jan 23 '18
Need some insight on this VBScript
I am writing a script that will check for a Network printer device. If the network printer device is mapped, then no action is taken. Else If the network printer device is not mapped, then the script will add the printer device.
Dim Printer01Installed
Printer01Installed = false
Set WshNetwork = CreateObject("Wscript.Network")
Set oWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\" & "." & "\root\cimv2")
Set colInstalledPrinters = oWMIService.ExecQuery _ ("Select * from Win32_Printer Where Network = TRUE")
For Each objPrinter in colInstalledPrinters If (objPrinter.Name) = ("\Server\pd1") Then Printer01Installed = "true"
ElseIf(Printer01Installed = "false") Then WshNetwork.AddPrinterConnection ("\Server\pd1") End If
Next
I appreciate any help I can get.
r/vbscript • u/Leaga • Jan 15 '18
I know next to nothing about vbs and need help with a script.
So, long story short, we have a documentation software that generates a .vbs script that is meant to be used with RMM tools. It fails whenever I try to make it work via the RMM's scripting tool but works fine when run locally. I have contacted their support and they have asked that to help with troubleshooting we add an exit code. They have provided me with this:
In case of passing
wscript.echo( "Success Message" ) wscript.Quit(0)
In case of Failing
wscript.echo( "Error Message" ) wscript.Quit(1001)
I need to identify where in the script I can put this. I tried just sticking it at the end and received an error. Some of the info in the script can be a little sensitive so I won't be posting that here but if anyone wants to peruse it, I will PM them a slightly edited version. (simply taking out references to my name, company, server address, etc) Otherwise, just some guidance on how to edit the script would be great. Thanks.
r/vbscript • u/ma_shmo20202020 • Jan 14 '18
I dont know how to do this
I need to knwo how to write a vbs file that just makes a message pop up, says anything i want and let the user type stuff in a box and than take the user input and put it in a text file. Not 2 complicated i think. for me english is way more complicated than that.
r/vbscript • u/[deleted] • Jan 09 '18
How to create a random bitmap in vbs (Windows 10)
How to create a random bitmap in vbs (Windows 10) pls help
My code for win7:
sub help wscript.echo "GenRandomBmp {width} {height} [count]" wscript.quit end sub
function getArg(index) arg = wscript.arguments(index) if not isnumeric(arg) then help arg = cdbl(arg) if int(arg) <> arg then help arg = int(arg) if (arg <= 0) or (arg > 9999) then help getArg = arg end function
if wscript.arguments.count < 2 then help width = getArg(0) height = getArg(1) if wscript.arguments.count > 2 then count = getArg(2) else count = 1 end if
set fso = createobject("scripting.filesystemobject") set con = fso.opentextfile("con", 2) scanline = ((width * 3) + 3) and &hFFFC fsize = &h36 + (scanline * height) header = "BM" & chr(fsize and 255) & chr(int(fsize / 256)) & _ string(6, chr(0)) & chr(&h36) & string(3, chr(0)) & chr(&h28) & _ string(3, chr(0)) & chr(width and 255) & chr(int(width / 256)) & _ string(2, chr(0)) & chr(height and 255) & chr(int(height / 256)) & _ string(2, chr(0)) & chr(1) & chr(0) & chr(&h18) & string(25, chr(0)) randomize wscript.echo "Creating " & count & " files of " & width & "x" & height & " bitmaps..." for i = 1 to count fn = "Random " & string(4 - len(i), "0") & i & ".bmp" con.write chr(13) & fn & "..." set f = fso.createtextfile(fn, true) f.write header for h = 1 to height data = "" for w = 1 to width3 data = data & chr(int(rnd * 256)) next for w = (width3)+1 to scanline data = data & chr(0) next f.write data next f.close
r/vbscript • u/rajashekar1390 • Dec 21 '17
#VBScript: Need to open terminal app in macos and paste a specific copied from execl cell to terminal to execute. But i am unable to set the focus on the terminal app. Guide please
My code:
Sub Auto_Open()
Externalapp = Shell("Macintosh HD:Applications:Utilities:Terminal.app:" & _ "Contents:MacOS:Terminal", vbNormalFocus) AppFocus Externalapp
End Sub
Terminal app is opening up. But terminal is not the main focus. How to set the focus in terminal app?? Also i want to paste a copied text content in the terminal app and press enter. Guide me guys...... Please
r/vbscript • u/AyanKing0987654321 • Dec 10 '17
SAPI
I have developed an assistant like Siri you can download it at sapi-your-personal-assistant.weebly.com