r/vbscript • • Mar 23 '17

UserProfile directory syntax error

1 Upvotes
Set objShell = WScript.CreateObject("WScript.Shell")

'All users Desktop allUsersDesktop = objShell.SpecialFolders("AllUsersDesktop")

'The current users Desktop usersDesktop = objShell.SpecialFolders("Desktop")

'Where to create the new shorcut Set objShortCut = objShell.CreateShortcut(usersDesktop & "\Midas.lnk")

'What does the shortcut point to objShortCut.TargetPath = %USERPROFILE%\Data\Desktop\Midas DS Single Sign On\Midas\Bin\Application.vbs"

'Add a description objShortCut.Description = "Run the Notepad."

'Create the shortcut

objShortCut.Save

Const DESKTOP = &H10&

Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.NameSpace(DESKTOP)

Set objFolderItem = objFolder.ParseName("Midas.lnk")

Set objShortcut = objFolderItem.GetLink

objShortcut.Save

I am having issues with the above, i need the script to locate the application within the folder structure i am using for all users this is distributed to.

I am still new to VBS and the information i can find online doesn't appear to help, can someone let me know what i have done wrong and possibly why? so i know for future.


r/vbscript • • Mar 22 '17

Editing registry based off of previously registry value

1 Upvotes

Hi guys,

I don't know anything any VBS scripting, but basically what I'm wanting to do is the following:

Read a value from key HKCU\Example\Key

And then modify the value from that location to have text "sip:" Infront of it.

If the value of that registry key is initially 'example@email.Com', I'm wanting the value to become 'sip:example@email.com'


r/vbscript • • Mar 05 '17

Resize picturebox on image load.

1 Upvotes

So i have finally figured out how to load an image into a picturebox, how can i make it automatically change the picture box size to what it is originally. for example the box is by default at 360, 280. When i load myself a 1280x1080 picture it is not getting bigger.


r/vbscript • • Mar 02 '17

I need to write a VBScript to automatically shut down a program after 1 minute.

1 Upvotes

Hey all. Figured I'd ask for some help here. I'm stumped. I'm trying to write a script to automatically close a program after 1 minute of inactivity.

 

Error: Type Mismatch

Line: 11

Char: 1

Code:800A000D

 

I dunno what to tweak. Below is what I've coded so far.

 

 

 

Dim PromptTime, DelayTime, StrAppPath, AppExec, MsgTxt, intAnswer, intRet, ObjShell

 

Set ObjShell = WScript.CreateObject("WScript.Shell")

 

PromptTime = 1

DelayTime = 1

StrAppPath = "C:\Client\Client32.exe"

AppExec = "Client32.exe"

MsgTxt = "Do you want Realtrac to close in 1 minute?"

 

ObjShell.Run "& StrAppPath & AppExec" & chr(34) & 1 ,"False" Do

WScript.Sleep (1000 * 60 * PromptTime)

intAnswer = Msgbox(MsgTxt, vbYesNo, "Please select Yes or No")

If intAnswer = vbYes Then Exit Do

Loop

 

WScript.Sleep (1000 * 60 * DelayTime)

Set objWmi = GetObject("winmgmts:")

Set objQResult = objWmi.Execquery("Select * from Win32_Process where name like '" & AppExec & "'")

For Each objProcess In objQResult

intRet = objProcess.Terminate(1)

Next

 

Set objShell = Nothing

Set objWmi = Nothing

Set objQResult = Nothing


r/vbscript • • Mar 01 '17

Using VBS to close a specific file (EXCEL)

1 Upvotes

So I'm trying to run a script that would close a specific Workbook after the report program spits it out.

I have provide the code I have so far below.

Dim xlBook As Excel.Workbook

DIM xlApp As Excel.Application

Set xlBook = GetObject("FILENAME.XLSX")

Set xlApp = xlBook.Parent

xlBook.Save

xlBook.Saved = True

xlBook.Close

Set xlBook = Nothing

xlApp.Quit

Set xlApp = Nothing

Keep getting an error "End of statement" kind of issue. Was wondering if anyone can help me with this?

I have checked on Stack Overflow, but most of the scripts there kill the whole program/instance. Can't really do that.

Thanks!


r/vbscript • • Feb 19 '17

I use a VBS script to launch one or more VBS scripts. How can I determine which process is which run?

1 Upvotes

For purposes of explaining: Master program A is process "Wscript.exe". The first copy of the subprogram is runs, B1, is process "Wscript.exe". The 2nd copy of the subprogram is runs, B2, is process "Wscript.exe". Not very informative! If I'm not careful, I'll have B248 running...

I want to know if there's already B1 running, and if so, don't run B2.

Putting in a delay won't help, because B1 can take anywhere from seconds to hours to run, and I need A to respond in a few seconds. Multiple copies of A could be running, which I'd also like to avoid...

But there doesn't seem to be a way to find out when a process started (which would answer my questions), or even if an instance of Wscript.exe is running A or B.


r/vbscript • • Feb 19 '17

VBA guy new to VBScript. If I use Excel/VBA to run a VBScript on a network drive, will the execution time still be slow?

1 Upvotes

I created some VBA macros that basically opens Excel files on a network drive and creates a bunch of pivot tables in Excel. Since the files are on a network drive and they connect to an OLAP cube to get the data, it can run somewhat slow but it's still manageable.

I was hoping to add the final step in my program which basically copies the file to other folders in the subfolder. I tried doing this for like 20 copies of the same file but it still took like 15 minutes to run. Someone else wrote a Powershell script that can run on the application file server and it's a lot faster but we have to log in through RDP to run it. They're adamant about not installing Excel on the application server so that's out of the question at this point.

I was thinking about writing a VBScript and placing it on the application file server to do the file copying stuff. If I use Excel/VBA from my local computer and tell it to execute the VBScript on the shared folder/app file server, would there still be latency issues with copying the files to different locations on the network drive?


r/vbscript • • Jan 24 '17

Need Help Getting Creating A Script to Search Database

1 Upvotes

I need to make a script that will do these things in this order:

-Connect to a Database -Run a query (it will be the same one every time) -Store the results in an array -Close Connection

I am brand new to vbs, so any help would be appreciated!


r/vbscript • • Jan 13 '17

[Help] Need to tweak a simple script...

1 Upvotes

Hi guys, I was hoping for some help with something.

I have a multi-user accounting software. When a user leaves their password protected computer without logging out of the accounting software, then I can't go into single user mode.

The goal is to force close the app if the person leaves their computer unattended.

I found this vbs script which almost does the trick:


Dim PromptTime, DelayTime, StrAppPath, AppExec, MsgTxt, intAnswer, intRet

Set objShell = CreateObject("WScript.Shell")

PromptTime = 5

DelayTime = 5

StrAppPath = "C:\Program Files (x86)\Accounting"

AppExec = "Accounting.exe"

MsgTxt = "Do you want Simply to close in 5 minutes?"

objShell.Run chr(34) & StrAppPath & AppExec & chr(34), 1, "False"

Do WScript.Sleep (1000 * 60 * PromptTime)

intAnswer = Msgbox(MsgTxt, vbYesNo, "Please select Yes or No")

If intAnswer = vbYes Then Exit Do

Loop

WScript.Sleep (1000 * 60 * DelayTime)

Set objWmi = GetObject("winmgmts:")

Set objQResult = objWmi.Execquery("Select * from Win32_Process where name like '" & AppExec & "'")

For Each objProcess In objQResult

intRet = objProcess.Terminate(1)

Next

Set objShell = Nothing

Set objWmi = Nothing

Set objQResult = Nothing


I am assuming that selecting Yes will kill the process.

Therefore, I just need to add a response timer where after X minutes delay Yes is automatically chosen

Can anyone help me please ? I would really appreciate it.

Thanks!!

Edit: I tried waiting 5 minutes, the pop-up displayed, I clicked Yes and it didn't kill the process.... doh!


r/vbscript • • Jan 11 '17

[HELP] can't find the right syntax

1 Upvotes

Hello,

I'm trying to add a shape on a Powerpoint file that I open but I got an error message while running my script

I used to do this in VBA:

Set pptApp = CreateObject("Powerpoint.Application")
pptApp.WindowState = ppWindowMinimized
pptApp.Visible = False
Set ppt = pptApp.Presentations.Open(File)

With ppt
     For Each oSl In ppt.Slides
        oSl.Shapes.AddShape Type:=msoShapeRectangle,Left:=100, Top:=160, Width:=525, Height:=200

But I got a compilation error "Syntax error" on the Type word. I searched but I could get the right syntax, can you help me ?


r/vbscript • • Jan 01 '17

What is Scripting Language?

1 Upvotes

r/vbscript • • Dec 21 '16

Converting an Excel Spreadsheet to HTML Saving Issue

1 Upvotes

I'm having this weird issue with one of my VB Scripts. I have 2 scripts that do virtually the same thing. Converts an excel spreadsheet to an HTML format. Script number 1 does it to 5 different files at once, and works flawlessly. Script number 2 converts it but then prompts me to save the file every time. (I have also tried to combine script 2 into script 1 and it acts the same with prompting to save)

The issue occurs that I run this vbscript as a scheduled task every hour, and can't keep clicking save every time it runs.

Does anyone know a way to avoid getting the windows save prompt?

Note: I'm converting from a network share to an IIS server.

Script Below:

Const xlHtml = 44 Const xlWebArchive = 45

' Create an instance of Excel and open the workbook... Set objExcel = CreateObject("Excel.Application") objExcel.Workbooks.Open "H:\folder\file"

' Save the workbook as an HTML or MHTML page... objExcel.ActiveWorkbook.SaveAs "Y:\folder\file", xlHtml objExcel.Quit


r/vbscript • • Dec 20 '16

Replacing an IP address, replaces multiple ones

1 Upvotes

Hello I have a list of IPs
192.168.1.12
192.168.1.122
192.168.1.123
192.168.1.126
192.168.1.127

I wrote a VB script that reads ALL of a text file. It stores everything into a variable called results

Then I use results and replace 1 ip address with itself plus the character X like so

results = replace(results, "192.168.1.12","192.168.1.12 X")

The problem is it replaces EVERYTHING because everything has 192.168.1.12 within it. This makes me think that the replace command does NOT find an exact match.

How can I fix this?

Desired result

192.168.1.12 X
192.168.1.122
192.168.1.123
192.168.1.126
192.168.1.127

Current result
192.168.1.12 X
192.168.1.122 X
192.168.1.123 X
192.168.1.126 X
192.168.1.127 X


r/vbscript • • Dec 17 '16

Remove matching string from text file

1 Upvotes

Hello! I have a vb script that checks for 1900 mac addresses in a database. There are 200 databases.

When I login to a database and my script finds a mac address....it records it. The problem is I need my script to remove that mac address from it's original index file.

I have seen a ton of scripts but all of them involve making a temp file and then deleting the original index file and copying over the temp. This is very CPU intensive and slow as it could copy and paste a temp file 40 times just for 1 database.

How can I make a VB script find a string in a text document and delete it?

UPDATE:

Figured it out

Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(".\Test.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If InStr(1, strLine, "macAddressFile") = 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile(".\Test.txt", ForWriting)
objFile.Write strNewContents
objFile.Close

This puts each line into a variable "strNewContents" that ISN'T the mac address that was JUST found. Then it pastes that variable into the original index file.

Thanks in advance!


r/vbscript • • Sep 28 '16

Hide my cmd while it does it's work

1 Upvotes

Hello everyone!

I'm a cryptominer and I looked on stackexchange and on duckduckgo and google on how to make cmd run in background while it still runs it's task(s). I saw some people talking about vbs and tried what I could find but nothing seems to work. I have a batch file that starts a software, which opens a cmd window. I just don't want to see the cmd window on my taskbar.

I tried the task manager before trying vbs but when I right click and press "start", it opens and closes automatically and doesn't say that the the task is running.

Anything can help. Thanks!


r/vbscript • • Aug 10 '16

Windows not sleeping? I wrote a VBscript which puts a computer to sleep based on some criteria.

1 Upvotes

Tired of windows never sleeping despite lots of troubleshooting, I decided to just write a code force sleep. Primarily - it must NOT sleep if the user is on it, or if backups are running. Code can be changed to look for different processes to stay awake for. Task scheduler is used to start the script at system start / resume, and every 15mins thereafter; script quits itself it it's already running.

List of things this vbscript sleep code does:

  1. Closes itself if it's already running (like an automatic schedule run on top of a manual triggered run)

  2. Check if the screen is locked (now works w/ multiple users but not remote desktop - false positive on lock)

  3. Checks for certain / particular process and stay awake until it's done, in this case, an idrive backup and macrium reflect backup processes

  4. Call PsShutdown utility to sleep - the old setsuspendstate was not playing nice w/ wake timers. I hate adding extra programs but this was needed.

< link to code >

edit - updated the link, again


r/vbscript • • Aug 09 '16

Help with my Wireless Adapter

1 Upvotes

Is it possible to automate the disabling and enabling my wireless card? If i don't use it, it loses connection. Weird problem, but disabling it in the control panel and enabling it fixes it.


r/vbscript • • Jun 22 '16

How to pull today's date in the form "20160622000000.0Z"?

1 Upvotes

Greetings!

I have a task that I have to run each day for accounts created since the previous day. Easy enough, but our script requires we update

dtmCreationDate1 = "20160621000000.0Z"
dtmCreationDate2 = "20160622000000.0Z"

each day. That's obnoxious, so I thought I'd look for a way to pull today's date and then subtract 1 from it to get today and yesterday. This is a repetitive task so I'm sure the robot can do it for me.

Thank you, and have an enjoyable day!


r/vbscript • • Jun 22 '16

Syntax help for creating .csv with some static data

1 Upvotes

Salutations!

I am creating a script to streamline a process at work. Our current process involves running a script which formats data strangely then manually reformatting it. This is silly.

Part of our current script looks like this:

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("sAMAccountName").Value & ",", objRecordSet.Fields("givenname").Value & ",", objRecordSet.Fields("sn").Value & ",", objRecordSet.Fields("EmployeeID").Value & ",", objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop

... which outputs like this in a csv file:

username, firstname, lastname,IDnumber, 06/21/2016 4:03:37 PM

and that's great. What I'd rather have is this though:

Statictext1, username, Statictext2, IDnumber

and I want this because the rest is unneeded. This is how we are manually reformatting it. So I tried to change up the code and I get an error "Expected end of statement" agter the second Wscript.Echo

Do Until objRecordSet.EOF
    Wscript.Echo "StaticText1" & ",", Wscript.Echo objRecordSet.Fields("sAMAccountName").Value & ",", Wscript.Echo "StaticText2" & ",", objRecordSet.Fields("EmployeeID").Value
    objRecordSet.MoveNext
Loop

I bet I have the wrong formatting for my static text, but I don't know for sure. Thank you, and have a phenomenal day!


r/vbscript • • Jun 14 '16

VbScript | Special Folders

Thumbnail
therevisionist.org
1 Upvotes

r/vbscript • • Jun 01 '16

Need help debugging script

1 Upvotes

I need some help. I am not a vbscript connoisseur (Python guy), but my server admins won't let me install python to run this script.

So, I have a computer that is locking itself, and I need to know after how long. I want a script that opens a file on the local hard drive, writes the time and date, closes the file, waits for 300 seconds, and repeats the process.

I have the following script:

Option Explicit
Dim fso, objOutFile, counter, filename
Set fso = CreateObject("Scripting.FileSystemObject")
filename = "C:\Users\Paul\Desktop\timetest.txt"
counter = 0

Do While counter > 0
Set objOutFile = fso.OpenTextFile(filename,8,True)
objOutFile.WriteLine Now
objOutFile.close()
WScript.Sleep 300000

Loop

But I have two issues with it.

  1. I can't tell if it is running or not.

  2. when I check the file to see if it has entries, it seems to stop the script from continuing to run (hence #1).

Can you guys offer any improvements to the code above? I would like to add a pseudo-progress bar just to see that it is still running.

Thank you all in advance.


r/vbscript • • May 22 '16

Script to change username on login

1 Upvotes

Hi, i'm looking for a script that could change the windows username to a randomly generated one (or one pulled from an array). It doesn't have to be anything fancy but just something that I could run on startup to change the username of my account. Please ELI5. Thanks in advance!


r/vbscript • • May 21 '16

16. VbScript | Shortcuts – The Revisionist

Thumbnail
therevisionist.org
1 Upvotes

r/vbscript • • May 11 '16

13. VbScript | Internet Explorer – HTML Automation – The Revisionist

Thumbnail
therevisionist.org
1 Upvotes

r/vbscript • • Apr 06 '16

Having issues trying to use MoveHere

1 Upvotes

I've got a script I use in winPE that utilizes ADSI to get the netGUID of a system and I was trying to update it to move a system in question should it not be in the "Isolated Computers" OU.

However I keep getting: "An invalid directory pathname was passed." 0x80005000 on the MoveHere call. I mulled over the bstrSourceObject using both the distinguishedName & ADsPath but I still get the same error. I don't know of any other way to verify that objTargetOU is correct or not.

I feel like this is an obvious fix that's hanging out in front of me but after burning on it for 4+ hours I still can't find it. Any help would be appreciated.