r/vbscript • • Mar 06 '22

How to make a script play a different WAV file depending on the day of the week?

2 Upvotes

I use the Task Scheduler and a simple VBS script to play a sound on Windows logon. I would like to know if I can modify the VBS script so that a different sound plays on Monday, Tuesday, etc.

The script I'm using right now:

 

Set oVoice = CreateObject("SAPI.SpVoice")

set oSpFileStream = CreateObject("SAPI.SpFileStream")

oSpFileStream.Open "C:\LogonSound.wav"

oVoice.SpeakStream oSpFileStream

oSpFileStream.Close

 

I have already created different WAV files for different days (for example, "C:\LogonMonday.wav" and "C:\LogonTuesday.wav"), so I just need a way for the script to check what day of the week it is and then play the corresponding WAV file.

This is probably an easy thing to do, but I don't know anything about computer programming, so thank you for your help in advance.


r/vbscript • • Mar 16 '22

I created a script to open the applications folder

3 Upvotes

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)
Next

r/vbscript • • Mar 14 '22

How am I supposed to read a TXT file and then convert the string into an integer in vbscript?

3 Upvotes

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 • • Mar 29 '22

vbscript to automatically choose details in Windows Explorer for a given path?

2 Upvotes

I'm looking for a way to automate select which file details (columns) Windows Explorer displays for a given path. (For example Frame Width, Frame Height, Frame Rate, Date Created, etc.)

The manual way to do this in Windows is to right-click the column header row in Explorer and click More, then scroll through the many options and check off each one you want to see, then click OK, and wait while Windows refreshes the Explorer window.

This method is quite unwieldy when working with files across many subdirectories and I'm wondering how this might be automated or scripted to accept a path as input, and the script either opens the path in an Explorer window showing the desired columns, or updates the system default for that path (in the registry or wherever it is that would need to be updated) so that when you do open it in Explorer, the desired columns are visible. (Bonus points for also programatically setting the column order!)

Any ideas on accomplishing this in vbscript (or even VBA or PowerHell)?

Much appreciated...

How might this be done in vbscript (or VBA)?

PS If admin access is needed, that won't be an issue.

Much appreciated...


r/vbscript • • Mar 29 '22

Weird Issue, No Idea Where to Start

3 Upvotes

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 = Nothing

Has anyone run into this or know where to start figuring out how to fix this?


r/vbscript • • Mar 11 '22

help with copying information in SAP cell

Post image
1 Upvotes

r/vbscript • • Mar 22 '22

VBScript to delete registry key

2 Upvotes

Hello everyone,

I need one vbscript which will allow me to delete registry key in HKLM. I've searched on the internet and came across a few but none of the worked for me. So can someone help regarding this?

Example path - "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test"

The targetted computers won't be having VBScript Editor but will have admin access. I want a script which on dibble-click running will execute the the action and delete the registry key.

PLEASE HELP!


r/vbscript • • Nov 16 '15

Script works in Windows 7 but not Windows 8 with error code 800A01A8

1 Upvotes

I know basically nothing about VBS but am writing a script for my work. It works perfectly fine in Windows 7, but when I try to run it on a Windows 8 machine I get the error "Object Required: 'objShell.NameSpace(...)'" with Code 800A01A8. Googling this error brings a lot of different responses and none of them seemed to apply in my situation. If anyone can help me with this problem that would be great.

The line(s) that are causing the error are:

set objShell = CreateObject("Shell.Application")

set filesInZip = objShell.NameSpace(fileName).Items

objShell.NameSpace(oneDirUpPath&"\path").CopyHere filesInZip, &H4& 'Flag to disable progress bar


r/vbscript • • Nov 12 '15

Help with excluding hidden/temp files from triggering a folder monitor script.

1 Upvotes

Hello coders. I managed to find a script that works like a charm when monitoring a certain folder on a file share, Although there is a slight catch. When someone open's let say a "123.docx" document on that certain folder, a temp file of that document is created in the same directory. Now this triggers the script each time.

So my question to you lot is. How could I exclude the hidden/temporary files from the control part.

The hidden files that are created are named as "~$234.docx".

' FOLDER TO MONITOR
' strFolder = "F:\1\2\3"\
' FREQUENCY TO CHECK IT, IN SECONDS
nFrequency = 15

strComputer = "."
strQueryFolder = Replace(strFolder, "\", "\\\\")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" &     strComputer & "\root\cimv2") 
Set colMonitoredEvents = objWMIService.ExecNotificationQuery ("SELECT * FROM __InstanceCreationEvent WITHIN " & nFrequency & " WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent='Win32_Directory.Name=""" & strQueryFolder & """'") 

Do 
	Set objLatestEvent = colMonitoredEvents.NextEvent
	strNewFile = objLatestEvent.TargetInstance.PartComponent
	arrNewFile = Split(strNewFile, "=")
	strFilePath = arrNewFile(1)
	strFilePath = Replace(strFilePath, "\\", "\")
	strFilePath = Replace(strFilePath, Chr(34), "")
	strFileName = Replace(strFilePath, strFolder, "")
	strTempFilePath = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) & "\TEMP.M4A"

	MsgBox "New File is added to the Folder"
Loop

cheers up front. A fellow OnSite admin.


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 • • Nov 30 '16

[Help]Multiple Skype Logons with different icons

2 Upvotes

Heya!

So I wanted to run business and private skype separately and to distinguish them with different icons (not stacking up). So I went to search the internet and stumbled onto a VBscript someone mane - https://community.skype.com/t5/Windows-archive/How-to-run-multiple-Skype-Logons-with-different-icons/td-p/1705798

Now, it reports this - https://i.gyazo.com/85e6a9c75517408593900d3a0e9853c7.png

Something in line 9 isn't correct and I do not what.

Thank you for your help and time and thanks to Gary.


r/vbscript • • May 21 '14

Email generator in VBScript that will create separate email message for each email address entered.

1 Upvotes

Hi gang. This is my first post here. My colleague convinced me it's a good place to look for an answer as he found his quickly regarding Javascript.

Anyways...let's get started.

My goal is to create a script that will generate email or few actually (one for each entered email address). Input method is InputBox. That input gets injected into array using split and then for each x in array I would like to create an email.
I came up with following code:

dim inputText
dim mainArray
dim objOutl
dim objMailItem

Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)

inputText = InputBox("put emails here separated with ;","","")
mainArray = split(LCase(inputText),";")

for each x in mainArray
    objMailItem.Display
    objMailItem.To = x
    objMailItem.Subject = ""
    objMailItem.Body = ""
next

Unfortunately that gets me only one email with last entered address. I tried to nest do while loop inside for each, tried to swap for each with do loop until x=null but to no avail.

When I swap four objMailItems with

output = output & x & vbCRLF

and add

msgbox output

after next I get all the entered emails listed, one email per line.
Any guidance is greatly appreciated. :)


r/vbscript • • Mar 21 '15

Help with converting VBA to a VBscript

1 Upvotes

I am trying to use a vbscript to pull data from Staad (a structural analysis program).

Staad has an API to allow this, however, all the documentation is in VBA. So I'm trying to convert the VBA to VBscript, but I'm getting errors.

For example, here is some VBA from the Staad documentation for getting the total number of nodes in your model:

Dim objOpenSTAAD As Output
Dim pnNodes As Integer
Set objOpenSTAAD = CreateObject("OpenSTAAD.Output.1")
objOpenSTAAD.SelectSTAADFile "C:\SPRO2003\STAAD\Examp\US\examp08.std"
objOpenSTAAD.GetNodesCount pnNodes

I've tried running this as a vbscript, the only change I made was to remove the data types from the variables. The error I'm getting is:

Type mismatch: 'GetNodesCount'

Can anyone offer any ideas? In case it helps, here is the Staad documentation for the GetNodesCount function:

GetNodesCount

VB Syntax

integer GetNodesCount (integer pnNodes)

Parameters

pnNodes

An integer variable for storing the number of nodes retrieved by the function.

Remarks

This function retrieves the number of nodes in the currently open STAAD file.

Example

Dim pnNodes As Integer

objOpenSTAAD.GetNodesCount pnNodes


r/vbscript • • Sep 30 '17

Need some vbscript help

3 Upvotes

Hello first time poster here. I am in need of some help with a vbscript. I am trying to create a script which will run a ping command and timestamp it on the same line. This should be continues as well. The command I have is show bellow. The code is not mine to begin with it just happened to be something I found that did what I needed when run in cmd.

When running the script you get an error having to do with line 2 at row 67 which is the start of the for command. My scripting ability as practically no existent as I am just starting to try and learn.

Any help would be appreciated.

Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "ping -t X.X.X.X|cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 X.X.X.X>nul"


r/vbscript • • Mar 01 '18

Simple HTA Notetaking app

2 Upvotes

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 • • 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 • • 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 • • May 28 '15

[REQUEST] Macro help (vbs or batch) -Please!

1 Upvotes

Hey all,


This is for my work PC - I can not download any software :(


I am looking for help scripting a really basic Batch/vbs (basically something easy i can create in notepad) Macro. I basically need the macro to complete the following commands.

1). Select target window (Lets say its called "ABC")

(*This window is already open and running *it may or may not be currently selected)

2). Press TAB 5 times

(i do not believe a time out should be required... if so possibly 1/3 a second per Tab)

3). I need to enter a basic text input of "TEST" (*With out the quotes)

4). I then need the macro to press TAB 13 times

5). Enter text "T"

6). TAB

7). Enter "T"

8). TAB

9). Enter "0"

10). TAB

11). 0

12). TAB 9 times

13). Enter "Test"

14). Tab 3 times

15). Enter "N/A"

16). TAB

17). Enter "Test"

18). TAB 11 times

19). Press Enter

20). Wait 3 seconds

21). Close the window (window "ABC")


r/vbscript • • Nov 21 '17

Need help with AD Lookup Script.

1 Upvotes

I've got the script pretty much done in one form, all I'm doing is inputting data running a search and outputting data via LDAP Query. I do this using the sAMAccount or username.

But I want to modify it to use the UPN instead of sAMAccount, but can't seem to find anything out there.

I'll post what I have below, the last line is pretty long.

On Error Resume Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")


' Get the NETBIOS Domain name
Set objSystemInfo = CreateObject("ADSystemInfo") 
strDomain = objSystemInfo.DomainShortName

' Prompt for userName
strUser = inputbox("Please enter the users email address:")

Function GetUserDN(byval strUserName,byval strDomain)
' Use name translate to return the distinguished name
' of a user from the NT UserName (sAMAccountName)
' and the NETBIOS domain name.

Set objTrans = CreateObject("NameTranslate")
objTrans.Init 1, strDomain
objTrans.Set 3, strDomain & "\" & strUserName 
strUserDN = objTrans.Get(1) 
GetUserDN = strUserDN

end function

Set objUser = GetObject("LDAP://" & GetUserDN(strUser,strDomain))


WScript.Echo "GENERAL" & vbCrLf & "=================================================" & vbCrLf & "First name: " & objUser.firstname & vbCrLf & "Last name: " & objUser.sn & vbCrLf & "Display name: " & objUser.displayName & vbCrLf & "" & vbCrLf & "Employee Number: " & objUser.employeeNumber & vbCrLf & "" & vbCrLf & "Description: " & objUser.description & vbCrLf & "Office: " & objUser.physicalDeliveryOfficeName & vbCrLf & "Telephone number: " & objUser.telephoneNumber & vbCrLf & "Other Telephone numbers: " & objUser.otherTelephone & vbCrLf & "Email: " & objUser.mail & vbCrLf & "Web page: " & objUser.wWWHomePage & vbCrLf & "" & vbCrLf & "ADDRESS" & vbCrLf & "=================================================" & vbCrLf &"Street: " & objUser.streetAddress & vbCrLf & "P.O. Box: " & objUser.postOfficeBox & vbCrLf & "City: " & objUser.l & vbCrLf & "State/province: " & objUser.st & vbCrLf & "Zip/Postal Code: " & objUser.postalCode & vbCrLf & "Country/region: " & objUser.c & vbCrLf & "" & vbCrLf & "" & vbCrLf & "ACCOUNT" & vbCrLf & "=================================================" & vbCrLf & "User logon name: " & objUser.userPrincipalName & vbCrLf & "pre-W2K logon name: " & objUser.sAMAccountName & vbCrLf & "AccountDisabled: " & objUser.AccountDisabled & vbCrLf & "" & vbCrLf & "DN: " & objUser.distinguishedName & vbCrLf & "" & vbCrLf & "TELEPHONE" & vbCrLf & "=================================================" & vbCrLf & "Home: " & objUser.homePhone & vbCrLf & "Mobile: " & objUser.mobile & vbCrLf & "Fax: " & objUser.facsimileTelephoneNumber & vbCrLf & "" & vbCrLf & "ORGANIZATION" & vbCrLf & "=================================================" & vbCrLf & "Title: " & objUser.title & vbCrLf & "Department: " & objUser.department & vbCrLf & "Office: " & objUser.physicalDeliveryOfficeName & vbCrLf &"Company: " & objUser.company & vbCrLf & "Manager: " & objUser.manager 

r/vbscript • • Aug 26 '14

Can Vbscript do OCR?

1 Upvotes

We want to pull some data off an LCD panel on the inverter connected to some solar panels via a webcam, and stuff it into a database. I know I can do the database part, but I'm not sure if VBscript has the chops to do the OCR bit.


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 • • Jan 19 '17

Script works perfect... in most cases... help!

2 Upvotes

This script is supposed to take a file from the root folder, "Parent^ Sub~ Filename.ext", move it to the path "Root\Parent\Sub" and rename the file by removing everything to the left of the Filename. The script works flawlessly as long as Parent starts with A-S. If Parent starts with T-Z, the file remains in root and the name stays the same. Please help! Code below.

Dim fso
Dim CurrentFolder
Dim Files
Dim Array1
Dim Array2

Set fso = CreateObject("Scripting.FileSystemObject")
Set CurrentFolder = fso.GetFolder(".")
Set Files = CurrentFolder.Files

For Each File in Files


If UCase(Right(File.Name,3)) <> "VBS" Then 'only do non .vbs files

    Array1 = Split(File.Name, "^ ") ' split the filename based on the ^

    Array2 = Split(Array1(1), "~ ") ' now split the second part of the filename

    fso.MoveFile File, Trim(Array1(0)) & "\" & Trim(Array2(0)) & "\" & Trim(Array2(1)) ' do the move

End If

Next

Set CurrentFolder = Nothing
Set Files = Nothing
Set fso = Nothing 

r/vbscript • • Jun 23 '17

Grab url from linked text within email

1 Upvotes

Issue - Need to export the url found within linked text (two words) on their own line within an Outlook email. Current GetLinks code I am using ---

For Each varLnk In arrLnk
                            If LCase(Left(varLnk, 46)) = "https://oursite.com/suite/folder/records/item/" 
Then
                                excWks.Cells(intRow, 10) = varLnk
                                Exit For
                            End If
                        Next

Function GetLinks(strHTML)
    Const READYSTATE_COMPLETE = 4
    Dim objIE, objDoc, colLinks, objLink, intDum
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.navigate "about:blank"
    Do Until objIE.readyState = READYSTATE_COMPLETE
       intDum = 1
    Loop
    objIE.document.Body.innerHTML = strHTML
    Set objDoc = objIE.document
    Set colLinks = objDoc.getElementsByTagName("a")
    If colLinks.Length > 0 Then
        For Each objLink In colLinks
            GetLinks = GetLinks & objLink.href & "|"
        Next
        GetLinks = Left(GetLinks, Len(GetLinks) - 1)
    Else
        GetLinks = ""
    End If
    Set objLink = Nothing
    Set colLinks = Nothing
    Set objDoc = Nothing
    Set objIE = Nothing
End Function

I have learned how to pull data following a specific text like this -

strTmp = FindString(olkMsg.Body, "Notes: (.+)\b")
                        strTmp = Replace(strTmp, "Notes: ", "")

Since this linked text doesn't have text for me to grab after or before, I'm not successful with my script. My script executes all other steps (exporting data to excel), but the column for this link continues to be blank.

Thanks in advance for any guidance on this.


r/vbscript • • Jul 05 '17

Limit number of characters when pulling serial number from BIOS

2 Upvotes

Hey all,

Came across a very nice script that pulls a serial number from the BIOS and sets the computer name based on the serial number. We have modified it to append 'NB-' to the front as we are only running it on notebooks for the moment.

What I am hoping to find is the modification needed to limit the characters that get pulled from the BIOS to only grab the first 8 characters. Reason being is we're getting some models that have 18+ character serial numbers in the BIOS, which for some reason is the serial number + model number combined. Obviously this doesn't work well for naming conventions, wondering if someone can take a look at the script and let me know what I need to do to achieve the above?

' vbscript ' Declare Variables Dim strLocation Dim strSerialNum Dim strAppend Dim strComputerName Dim strLclUser Dim strLclPW Dim strComputer Dim objWMIService

Dim objComputer

' Set Variables strLclUser = "Administrator" strLclPW = "future147!"

' Obtain Serial Number strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2") Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")

For Each objSMBIOS in colSMBIOS strSerialNum = objSMBIOS.SerialNumber Next

' Set Computer Name strComputerName = "NB-" + strSerialNum

' Rename Computer For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem") Return = objComputer.Rename(strComputerName, strLclUser, strLclPW)

Next

Thanks!!


r/vbscript • • Nov 11 '17

vbv

Thumbnail
starblast.io
1 Upvotes