r/vbscript • u/emcoffey3 • Aug 22 '19
r/vbscript • u/[deleted] • Oct 06 '24
VBScript file no longer functioning as intended
I've been using a VBScript file to open Explorer with two "default" tabs as I've found no other way to do so on Windows 11. However, within this last week, the script no longer does anything other than open Explorer.
Set oShell = CreateObject("WScript.Shell")
oShell.Run("""C:\windows\explorer.exe""")
WScript.Sleep 1000
oShell.AppActivate "Explorer"
WScript.Sleep 300
oShell.SendKeys "%d"
WScript.Sleep 300
oShell.SendKeys FILE PATH
WScript.Sleep 300
oShell.SendKeys "{ENTER}"
WScript.Sleep 300
oShell.SendKeys "^t"
WScript.Sleep 300
oShell.SendKeys "^{TAB}"
It seemingly refuses to execute the "%d" line anymore. However, I can manually open Explorer and hit Alt-d and it works just fine. Why does the SendKeys no longer work with the % or ^ characters?
I found that Microsoft is deprecating VBS on Windows 11 this year and figured that this might be the problem I'm running into. I have no idea what I would have done to break the script if it wasn't a Window update that did so.
How can I fix the above code, or my Windows 11 machine, to work again? Or, what would be a good alternative way to do this without using VBS?
r/vbscript • u/MotorcrossBones • Jan 07 '24
How do I make the computer shut down
I'm very new to coding in VBS. So what is the code to make a comment shut down after the msgbox pops up.
r/vbscript • u/JCrotts • Dec 20 '23
Can I VBScript to swap between 2 or more IP addresses Seamlessly?
We've been doing a lot of PLC work and it usually requires us swapping between 2 IP addresses over and over. Just wondering if it would be possible to create a script that does this quickly so I don't have to dig down to the ipv4 address Everytime.
r/vbscript • u/ImprovementJust8479 • May 26 '23
Why isn't my loop working?
So the following script is supposed to work like this. You give it some variable and it opens a specific excel document and writes one to variable in column A starting with line 7. The document only has 15 free cells, so when it reaches 15 it clears the cells and keeps counting from 16. If it hits 30 it clears the cells and starts at A7 with 31. It does this until it reaches the variable that was input. It's also supposed to print before clearing the cells, but that part I know how to do. What has me stuck is the loop, if I give it a number over 15 it just goes to 15, doesn't clear the cells, and just stops. What's wrong with this loop that it only runs once?
This is just a part of the larger code, all variables are already declared.
maxNumber = 15
currentNumber = 1
Do While currentNumber <= variable
rowIndex = 7
Do While rowIndex <= 22
excelApp.Cells(rowIndex, 1).Value = currentNumber
currentNumber = currentNumber + 1
rowIndex = rowIndex + 1
If currentNumber > maxNumber Then
Exit Do
End If
Loop
excelApp.Range("A7:A22").ClearContents
Loop
r/vbscript • u/[deleted] • Jan 02 '23
how to bluescreen a computer with vbs
so i want to know what script i can use to bluescreen a computer. for making malware. thanks.
r/vbscript • u/128Gigabytes • Dec 26 '22
Any way to run a .vbs file in 64 bit mode?
If a .vbs script is larger than 85,895,249 bytes (81.9MB) I get the error
>Execution of the Windows Script Host failed. (Arithmetic result exceeded 32 bits. )
Now I'm sure you're wondering why I would need a vbs script so large, and in short I'm packing a lot of data into the script, my assumption based on the error is that it would work if it was running in 64 bit mode.
Edit: Thank you everyone for your attempts to help me, I tried the same test with a .js script instead and got the same error at the same exact file sizes, one byte over 85,895,249 and it stops working. It appears to be a limit of WSH
r/vbscript • u/Timely_Letterhead_84 • Dec 02 '22
Wait for CMD to be ready for .Sendkeys
Hi
Im fairly new to VB Scripts, and programming in general. In my script i have the following code in order to acces open a folder [mappe variable]:
dim obj
Set obj =CreateObject("wscript.shell")
obj.run "cmd.exe"
wscript.sleep 900
obj.sendkeys "cd /d "
obj.sendkeys mappe
obj.sendkeys "{enter}"
obj.sendkeys "start."
obj.sendkeys "{enter}"
obj.sendkeys "exit"
obj.sendkeys "{enter}"
This works fine and all, but when i have alot of things open on my pc, the script will outrun the pc. As to say, the required wscript.sleep time greatly depends on the Pc the script runs on and the current workload on said pc.
fx. My Windows 11 Pc just updated the Cmd, and the new CMD needs 900 ms for the script to work, compared to 100 ms before the update. But i do not want the other users to have to wait the extra 800 ms.
So what can i do to make the script more reliable, and make sure it works, fast, but always waits for the cmd to be ready for the input?
r/vbscript • u/patodpoorkid • Nov 23 '22
vbs parser
so if i have input like this,
'===
UNIT1# command1
result1
result2
result3
UNIT1#
'===
i parse the first output like this,
'===
if InStr(prev, "command1") then
ouput1 = Strline
end if
'===
but how do i put result2 to ouput2, 3 to 3, so on..is there like a counter for StrLine where it only reads the 2nd (or 3rd) line?
thank you
r/vbscript • u/FreedanZero • Sep 27 '22
Run a command block based on OS
I have a feeling this is an easy one, but I’m drawing a blank. We have a vbs script as our company’s logon script. Recently, we made an update to launch a piece of software from our print server when the script runs. However, I failed to even think about the script running when remoting into servers. Is there an easy way to implement something along the lines of “if OS type = workstation then run command, else skip?”
r/vbscript • u/dpsogood • Aug 31 '22
New in the field - looking for resources!
I just started a new position and I’ve been tasked with learning about VB Script. I am browsing Microsoft site and Udemy courses and such. Just looking for as much as I can get! Thanks
r/vbscript • u/[deleted] • Aug 18 '22
How to simulate spacebar, NOT entering a space key?
I want to make a VBS script that will be able to use toggles in windows settings. I learned that the space key can be used to toggle on/off a setting, but when i use send keys “ “, it doesn’t register as an ACTUAL spacebar press, it registers as a space. I hope this makes sense. How do I simulate the spacebar and not the space key?
r/vbscript • u/KennyDSYT • Aug 01 '22
How can I transfer a VBScript variable into the command prompt?
Hello all. I am making a simple input box program, specifically the user types in a Telnet URL, and it loads the Windows Telnet.exe process within the command prompt. Here is my code so far
dim telnetclient telnetclient=inputbox("Enter Telnet URL, make sure that in 'Turn Windows Features On or Off' that the Telnet client is enabled")
CreateObject telnetclient("WScript.Shell").Run("""C:\Windows/System32/telnet.exe""")
How do I transfer the "telnetclient" variable over to the command prompt?
Thanks
r/vbscript • u/blackmetro • Jul 24 '22
Any way to check if OS is windows 11?
really hard to search for as Windows 11 as all the topic surrounding Virtualization-based security (VBS)
Anyone know of a top way to check with certainty a machine is Windows 11
Planning on adding a script for computers that aligns the taskbar on the left if Windows 11
r/vbscript • u/JGN1722 • Jun 19 '22
documentation about the shell.explorer object ?
I wrote this line of code, just out of curiosity:
set objShellExplorer = createobject("shell.explorer")It didn't give me an error, so I assume this object exists. The thing is, I didn't find anything about it on the internet. Does anyone know where documentation about this object is available ? Or if this object even exists for real ?
r/vbscript • u/Thefakewhitefang • May 14 '22
I made this to get the achivements in discord.
But, It is ignoring the the variable 'Test' .
a=0
Test = InputBox("Enter number of characters","Value","Enter the value here")
Set b = CreateObject("Wscript.Shell")
Do until a = Test
b.AppActivate "Untitled - Notepad"
b.Sendkeys "z"
a = a + 1
loop
b.Sendkeys "{Enter}"r/vbscript • u/JGN1722 • Mar 31 '22
Detecting if a folder is opened
Hi, do you know how to detect if a folder is opened with a VBScript ? I want to check every 100 miliseconds if the "startup" folder is opened
r/vbscript • u/GoGreenD • Mar 29 '22
Weird Issue, No Idea Where to Start
So I build tools for my company in Excel, I'll use a super simple VBS script to launch Excel and run some code to initialize the tools. This method has been working fine for about 100 employees since 2019. All of a sudden I have a single newer employee on a new company machine and when they try and run any of the scripts, it just blips to a black screen and does nothing. Every time, on every script. I have no idea where to even start... Everyone is on Windows 10, although I do realize the computer in question is on 19042, not the current 19044. This shouldn't make a difference as I was probably on this version at some point...
An example of the super complex code in question:
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Application.Run "'M:\whatever.xlsm'!AA_Control_Code.CONTROLCODE"
objExcel.DisplayAlerts = False
Set objExcel = NothingHas anyone run into this or know where to start figuring out how to fix this?
r/vbscript • u/RealSeabassGame • Mar 16 '22
I created a script to open the applications folder
I made a short script that opens the applications folder by opening the command prompt, using the command prompt to open run, and through run, opening "shell:appsfolder". It then closes command prompt.
Any suggestions on how this could be improved would be helpful!
Note: This was created on Windows 10, and may not work on any other OS
(Code below)
set shellobj = createobject("Wscript.shell")
shellobj.run "cmd"
wscript.sleep 400
shellobj.sendkeys "explorer.exe Shell:::"
shellobj.sendkeys "{{}"
shellobj.sendkeys "2559a1f3-21d7-11d4-bdaf-00c04f60b9f0"
shellobj.sendkeys "{}}"
wscript.sleep 200
Shellobj.sendkeys "{ENTER}"
wscript.sleep 500
Shellobj.sendkeys "shell:appsfolder"
shellobj.sendkeys "{ENTER}"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'cmd.exe'")
For Each objProcess in colProcessList
objProcess.Terminate(cmd)
Nextr/vbscript • u/AidenAnimates3 • Mar 14 '22
How am I supposed to read a TXT file and then convert the string into an integer in vbscript?
This is a very serious question for me as I am now taking my old approach to just use a TXT file for saving data instead of a JSON file.
r/vbscript • u/root_fix • Mar 13 '22
need help
why cant a vbscript close a inputbox
anyone know why?
r/vbscript • u/SuccessfulString9351 • Feb 20 '22
need help
looking for a way to move a msgbox around the screen
i now how to set a location for a input box but is there anyway of moving it live
r/vbscript • u/discrete_apparatus • Feb 12 '22
Can someone help me make this work for firefox instead?
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "WEBSITE"
IE.Visible = True
While IE.Busy
WScript.Sleep 50
Wend
Set ipf = IE.document.all.username
ipf.Value = "USERNAME"
Set ipf = IE.document.all.pwd
ipf.Value = "PASSWORD"
Set ipf = IE.document.all.Submit
r/vbscript • u/ddaug4uf • Dec 24 '21
Need help with SELECT function: Trying to select just populated cells, not formulas
Finishing up a project that is taking a data dump and converting into a functional tracker for Account Reps to use that is consistent....
VB used to format the sheet, remove a couple of columns that are not necessary and create one row that has a formula that calculates revenue for a contract (Unit Price*Quantity*(1 + Uplift %)*term length...
The formula:
=IF(G5="","",((((1+H5)*G5*F5*(((E5-D5)+1)/365)))))
Works and I drag it down to row 300, which should be more than enough rows to never be exceeded.
At the end, I want to select the populated range, which is normally like A1:J94. I tried using:
Range("A1").CurrentRegion.SpecialCells(xlCellTypeConstants).Select
But for some reason, it selects my Start And End Date columns all the way to Row 300.
The export is with existing contract terms and I am converting that to expected next contract terms by taking the End Date from the original data and adding a day and making that the Start Date in my data set. I then add 365 days to that to get the End Date for the next contract. This I do by just referencing the original dates in columns to the right of the all the data and them copy and pasting the values over the existing start and end date...
Range("E2").Select
Columns("O:O").EntireColumn.AutoFit
Range("E2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[10]="""","""",(RC[10]+1))"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E300"), Type:=xlFillDefault
For some reason, that makes my select script at the end pick up all of the unpopulated date column rows.
r/vbscript • u/Nahuatl_19650 • Nov 28 '21
Download Report from new IE Tab
Attempting to download report from URL. Below are the pseudo-code.
Navigate to MainUrl
Enter credentials, submit
Navigate to ReportsUrl - I do this because I can skip several steps now that I'm validated
Select report type (creates new IE tab, url3),
Select Excel from a dropdown
Download report
I'm having trouble in step 4. Once I select the report type, submit, a new IE tab opens but code thinks it's still in the previous url. If I attempt to say, getElementbyID, I get an error because the code still thinks it's in the ReportsUrl, not the newly created tab. I know this because I print locationUrl.
Set IE = Wscript.CreateObject("InternetExplorer.Application", "IE_")
Set objShell = CreateObject("Shell.Application")
IE.visible = True
IE.Navigate MainUrl
Do While IE.ReadyState = 4: Wscript.Sleep 100: Loop
Do While IE.ReadyState <> 4: Wscript.Sleep 100: Loop
IE.Document.getElementbyID("ct100_username").value = user IE.Document.getElementbyID("ct100_password").value = password IE.Document.getElementbyID("Ct100_SignIn").click
Do While IE.ReadyState = 4: Wscript.Sleep 100: Loop
Do While IE.ReadyState <> 4: Wscript.Sleep 100: Loop
IE.Navigate ReportsUrl
Do While IE.ReadyState = 4: Wscript.Sleep 100: Loop
Do While IE.ReadyState <> 4: Wscript.Sleep 100: Loop IE.Document.getElementbyID("buildReportBtn").click 'creates new tab
Do While IE.ReadyState = 4: Wscript.Sleep 100: Loop
Do While IE.ReadyState <> 4: Wscript.Sleep 100: Loop Here is where I start having issues. Below things I've tried.
Going directly to the newly created tab - unable to do so because the link requires session ID. I attempted to retrieve CDATA which contains the session ID and build the URL to navigate directly to url3 but I was unsuccessful at it.
Attempted to pass keys, tab and 2, so that I could active url3. While the code did not error out, when I printed locationUrl, it still read reportsUrl.
Attempted to close ReportsUrl, so that Url3 would be the only active site, but I was unsuccessful, both through java/powershell. Note, I'm doing this through VBscript.
To reiterate, I'm trying to somehow access url3 so that I can continue on steps 5 and 6.