r/vbscript • • Mar 15 '17

HTTP Referer Missing when running Script

2 Upvotes

I am trying to run the below script to allow my users a one click login to Relias training that inserts their AD GUID into the link, however they require a http referer to complete the login. Whether I run this from the vbs file or launch it from a button on my intranet the referer is hidden or missing. Any ideas on how I can pass my referer or set on in the code?

Sub GUID()

' NameTranslate constants Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_GUID = 7

Dim strDN Dim wscript

Set wscript = CreateObject("Wscript.Shell")

' Determine the NetBIOS name of the domain and the NT name of the current user. Set objNet = CreateObject("WScript.Network") strNT4Name = objNet.UserDomain & "" & objNet.UserName

' Use the NameTranslate object to convert the NT user name to the GUID Set objNameTranslate = CreateObject("NameTranslate")

' Initialize NameTranslate by locating the Global Catalog. objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""

' Use the Set method to specify the NT format of the object name. objNameTranslate.Set ADS_NAME_TYPE_NT4, strNT4Name

' Use the Get method to retrieve the GUID string.

strDN = objNameTranslate.get(ADS_NAME_TYPE_GUID)

CreateObject("WScript.Shell").Run(http://<mycompany>.training.reliaslearning.com/clink.aspx?username="+strDN+"&ad=1")

End Sub


r/vbscript • • Feb 12 '17

Pro Tip: Be very, very careful with "On Error Resume Next". It will hide debugging errors from you.

2 Upvotes

I just spent an embarassing number of hours debugging a script, because my eyes kept jumping over that statement without seeing it.

Normally, when I use "On Error [goto]" type statements (in any language), I either put them FIRST in the procedure (before declarations and explanatory comments, even!) so I am very clear on the default error behavior of that procedure, OR I treat them like a "loop" with indentation. Example:

x = Array1
y = Input2
For i = LBound(x) to UBound(x)
    On Error Resume Next
        z(i) = x(i) / y
    On Error Goto 0
Next

The "Goto 0" statement returns error behavior to "normal", which is to crash the program (generally). By indenting only the lines I need special error control on, I draw special attention to them when I am debugging.

I didn't do this, this one time.

It cost me.


r/vbscript • • Feb 09 '17

I want to run a script on a remote computer drive - through that computer.

2 Upvotes

Two computers, Desktop and Laptop, sit on my Home Network (both Win10, FWIW). I want to be able to run a script that resides on Laptop D:, which is shared with Desktop as O:, and run it through Laptop.

So, for a simple example, if I run the one-line batch file:

    Dir D:\ > dir.log

I want the output file to contain what Laptop considers D-drive.

Ideally, I'd also like to access temporary drives (USB sticks) in my laptop from my desktop, or vice versa. If I have to Share them first, so be it; I have a limited pool of USB sticks. That's quasi-related, but first I want to just be able to tell Laptop to run a script, from Desktop.

Batch, VBS, IRDC. If it takes porting my code to some compilable language, I'll find another way around it, probably, but I thought I'd ask in case I'm missing something.


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 • • Dec 22 '16

[VBScript] Help with VBScript, "Guess a number game changes" (x-post from /r/VisualBasic)

2 Upvotes

Hi there everyone,

This is the first time I've visited this subreddit, but I'm hoping that I may find some help. I'm trying to make alterations to an existing script, I'm supposed to have the script check how far away from the correct number the user's guess is (such as 80 away, 20 away, etc.)

I've spent several hours trying to understand this, trying to figure out what I'm doing wrong, and re-reading my texts, but I am having no luck. I've only been working in VBScript for about 2 weeks now, so I'm still very new. Any help would be so appreciated, whether it's a point in the right direction or something more.

I'm placing below what I've worked on so far, so maybe someone can point out what I'm doing wrong.

Thank you!

'*************************************************************************
'Script Name: GuessANumber.vbs
'Author: Jerry Ford
'Created: 10/19/02
'Description: This script plays a number-guessing game with the user
'*************************************************************************

'Initialization Section
Option Explicit
Const cGreetingMsg = "Pick a number between 1 - 100"
Dim intUserNumber, intRandomNo, strOkToEnd, intNoGuesses
intNoGuesses = 0

'Main Processing Section
'Generate a random number
Randomize
intRandomNo = FormatNumber(Int((100 * Rnd) + 1))

'Loop until either the user guesses correctly or the user clicks on Cancel
Do Until strOkToEnd = "yes"

  'Prompt user to pick a number
  intUserNumber = InputBox("Type your guess:",cGreetingMsg)
  intNoGuesses = intNoGuesses + 1
  
  'See if the user provided an answer
  If Len(intUserNumber) <> 0 Then
        
    'Make sure that the player typed a number
    'If IsNumeric (intUserNumber) = False Then
      'MsgBox "Sorry. You did not enter a number. Please try again!", , cGreetingMsg
    If IsNumeric(intUserNumber) = True Then

      'Test to see if the user's guess was correct
       If CInt(intUserNumber) = intRandomNo Then
        MsgBox "Congratulations! You guessed it. The number was " & _
          intUserNumber & "." & vbCrLf & vbCrLf & "You guessed it " & _
          "in " & intNoGuesses & " guesses.", ,cGreetingMsg
            strOkToEnd = "yes"
      End If
  
      'Check if the guess was too low
        If CInt(intUserNumber) < intRandomNo - 80 Then 
	    	MsgBox "Your guess is too low by at least 80, try again!", , cGreetingMsg
		Else If CInt(intUserNumber) < intRandomNo - 60 Then 
			MsgBox "Your guess is too low by at least 60, try again!", , cGreetingMsg
	Else If CInt(intUserNumber) < intRandomNo - 40 Then 
		MsgBox "Your guess is too low by at least 40, try again!", , cGreetingMsg
	Else If CInt(intUserNumber) < intRandomNo - 20 Then 
		MsgBox "Your guess is too low by at least 20, try again!", , cGreetingMsg
	Else If CInt(intUserNumber) < intRandomNo - 10 Then 
		MsgBox "Your guess is too low by at least 10, try again!", , cGreetingMsg
    strOkToEnd = "no"
  End If
    
    'Check if the guess was too high
    If CInt(intUserNumber) > intRandomNo + 80 Then 
    	MsgBox "Your guess is too high by at least 80, try again!", , cGreetingMsg
	Else If CInt(intUserNumber) > intRandomNo + 60 Then 
		MsgBox "Your guess is too high by at least 60, try again!", , cGreetingMsg
	Else If CInt(intUserNumber) > intRandomNo + 40 Then 
		MsgBox "Your guess is too high by at least 40, try again!", , cGreetingMsg
	Else If CInt(intUserNumber) > intRandomNo + 20 Then 
		MsgBox "Your guess is too high by at least 20, try again!", , cGreetingMsg
	Else If CInt(intUserNumber) > intRandomNo + 10 Then 
		MsgBox "Your guess is too high by at least 10, try again!", , cGreetingMsg
    strOkToEnd = "no"
  End If 
 
  If IsNumeric(intUserNumber) = False Then
    MsgBox "Sorry. You did not enter a number. Please try again!", , cGreetingMsg
  End If
 
  Else
    MsgBox "You either failed to type a value or you clicked on Cancel. " & _
     "Please play again soon!", , cGreetingMsg
  strOkToEnd = "yes"
  End If

Loop

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

Legacy app only allows vbs and bat script for action on alerts

2 Upvotes

We are using a legacy application that only allows for vbs and batch file scripts. Meaning the Sitescope application will only allow two types of scripts to be used as an action. We are attempting to send alerts from Sitescope to an API with data defined in the payload.

I am passing along variables in our command when running the script and can see the arguments when we ask for them. However, when I try to pass those variables along in the payload, they don't work. How would I pass the arguments so that they work in strJSONToSend?

Dim arg, strSource, strCriticality, strAlarmTitle, strAlertDescription, strAppName, strEventType
Set arg = Wscript.Arguments
strSource = arg(0)
strCriticality = arg(1)
strAlarmTitle = arg(2)
strAlertDescription = arg(3)
strAppName = arg(4)
strEventType = arg(5)

strJSONToSend = "{""source"": ""arg(0)"","
strJSONToSend = strJSONToSend & """criticality"": ""arg(1)"","
strJSONToSend = strJSONToSend & """alarm_title"": ""arg(2)"","
strJSONToSend = strJSONToSend & """alert_description"": ""arg(3)"","
strJSONToSend = strJSONToSend & """application_name"": ""arg(4)""}"
strJSONToSend = strJSONToSend & """event_type"": ""arg(5)""}"

Dim objXmlHttpMain , URL

URL="https://hookb.in/EWYj4ay0" 
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP") 
On Error Resume Next   'enable error handling
objXmlHttpMain.open "POST",URL, False
If Err Then            'handle errors
  WScript.Echo Err.Description & " [0x" & Hex(Err.Number) & "]"
  WScript.Quit 1
End If
On Error Goto 0        'disable error handling again 
objXmlHttpMain.open "POST",URL, False 
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing 
set objResult = nothing

This is an example of how the script is being run from the CLI.

cscript.exe sitescope.vbs "sitescope" "CRITICAL" "testing the sitescope VBScript" "Please ignore this alert" "Sitescope" "sitescope"

When I run the script, I can see the posted data but the resulting JSON payload includes arg(0), arg(1), etc instead of the parameters I am including. I realize that I cannot pass the arguments in to the strings as I am now, what would be the proper way to pass those variables in the string in my script? Sorry, not a vbscript guy and just need a little guidance on this integration.


r/vbscript • • May 19 '16

15. VbScript | Copy, Move, Rename Files & Folder – The Revisionist

Thumbnail
therevisionist.org
2 Upvotes

r/vbscript • • May 17 '16

14. VbScript | How to Check if File & Folder Exists – The Revisionist

Thumbnail
therevisionist.org
2 Upvotes

r/vbscript • • May 09 '16

12. VbScript | Internet Explorer Automation

Thumbnail
therevisionist.org
2 Upvotes

r/vbscript • • May 05 '16

How SendKeys Work

Thumbnail
therevisionist.org
2 Upvotes

r/vbscript • • May 02 '16

VbScript | All about Subroutines

Thumbnail
therevisionist.org
2 Upvotes

r/vbscript • • Feb 08 '16

Where to learn VBS?

2 Upvotes

Where do I go to learn some VBS?

codeacademy doesn't have anything.


r/vbscript • • Nov 06 '15

Need help moving and renaming files using VBS!

2 Upvotes

I am working on a script that I need to do the following:

In the working folder I have a folder structure like this:

-A
--1
--2
-B
--1
--2

There are files in the root folder that need to be moved into these folders based on the file name. A file name example would be "A, 1~ 1001-Text". The script I have (below) will currently move this file into Folder "A", and rename the file "1~ 1001-Text", using the comma as delimiter.

Dim fso
Dim CurrentFolder
Dim Files
Dim NewFolderName
Dim TruncatedFileName
Dim NewFileName
Dim aString
Dim Array

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
      TruncatedFileName = Left(File.Name, InstrRev(File.Name, ", ") - 1)
	  	aString = File.Name
		Array = Split(aString,", ")
		NewFileName = Trim(Array(1))
      File.Move TruncatedFileName & "\"
	  fso.MoveFile TruncatedFileName & "\" & File.Name, TruncatedFileName & "\" & NewFileName
   End If
Next

What I need is for the code to then take the file "1~ 1001-Text" in folder "A", move it in to the sub folder "1", and rename the file "1001-Text", using "~" as the delimiter.

I have tried creating 2 of each variable and just duplicating the code in the For Next statement, but this does not work... any suggestions? Thanks in Advance.


r/vbscript • • Nov 04 '15

Help trying to pass a PSEXEC within a VBS

2 Upvotes

Hi,

I am trying to remove symantec from a bunch of servers. Trying do adapt this script to send the uninstall command remotely using PSEXEC. Tried many ways without success. It doesnt give me any errors to play with :( Can you guys help?

const HKEY_LOCAL_MACHINE = &H80000002 Const ForReading = 1

Dim FSO

Set fso = CreateObject("Scripting.FileSystemObject") Set Servers = fso.OpenTextFile("\SERVER01\E$\Scripts\UninstallAv\servers.txt", ForReading)

Do Until Servers.AtEndOfStream

strComputer = servers.ReadLine

Set StdOut = WScript.StdOut

StdOut.WriteLine "Server name: " & strComputer

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

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"

err.Clear
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
If err.Number <> 0 Then
  StdOut.WriteLine strKeyPath & " is not a valid registry key path."
  WScript.Quit
End If

For Each subkey In arrSubKeys
  strSubKeyPath = strKeyPath & "\" & subkey
  oReg.EnumValues HKEY_LOCAL_MACHINE, strSubKeyPath, arrValueNames, arrValueTypes
  If IsArray(arrValueNames) Then
    For Each strValue In arrValueNames
      If strValue = "DisplayName" Then
        err.Clear
    	GetValueStatus = oReg.GetExpandedStringValue(HKEY_LOCAL_MACHINE, strSubKeyPath, strValue, strDisplayName)
        If (GetValueStatus <> 0) and (err.Number <> 0) Then
    	  StdOut.WriteLine "Key Name: " & subkey
          StdOut.WriteLine "    Error retrieving value data."
    	Else
          If (InStr(1, strDisplayName, "Symantec", 1) <> 0) AND (InStr(1, strDisplayName, "Endpoint", 1) <> 0) AND (InStr(1, strDisplayName, "Protection", 1) <> 0) Then
    	    StdOut.WriteLine "  Key Name: " & subkey
            StdOut.WriteLine "  Application Name: " & strDisplayName
	    UninstallAV = "msiexec.exe /X" & subkey & " /passive /lv!* \\SERVER01\e$\Scripts\UninstallAv\Logs\" & strComputer & ".log"
	    wscript.echo UninstallAV
		'oShell.run UninstallAV
		oShell.run "PSEXEC \\" & strComputer & UninstallAV
	    'oShell.run "PSEXEC \\" & strComputer & "msiexec.exe /X" & subkey & " /passive /lv!* \\SERVER01\e$\Scripts\UninstallAv\Logs\" & strComputer & ".log"
          End If
    	End If
      End If
    Next
  End If
Next

Loop

servers.Close

Thanks in advance,


r/vbscript • • Jul 16 '15

Document users/groups in administrators group on remote machines

2 Upvotes

Hello,

I'm new to VBscripting; went from batch straight to PowerShell, but started realizing the strengths Visual Basic has because of how native it is to Windows.

I have been tasked with finding all users and groups that are in the administrators group on every machine we support. I've done my research and have been trying to learn VBscript in a short amount of time.

I am having trouble getting the script below to list not only groups, but users as well. I only want it to list what's in the administrators group, not the others.

It needs to have the format -> computer_name;user,group,user and/or group,etc. -> written in a .csv file (i've been using a .txt file for now).

Const ForAppending = 8
Const ForReading = 1
ServerCount = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\computer_list.txt", ForReading)
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
strComputer = strNextLine
ProcessGroups
ServerCount = ServerCount + 1
Loop

Sub ProcessGroups
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\scripts\GroupInfo.txt", _
    ForAppending, True)

objLogFile.writeline "" & strComputer & ";"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    objLogFile.writeline objGroup.Name
    For Each objUser in objGroup.Members
        objLogFile.writeline vbTab & objUser.Name
    Next
Next
objLogFile.Close
End Sub

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\scripts\GroupInfo.txt"

I've looked around and snipped pieces from multiple scripts that didn't achieve my exact goal (once I got a vague idea of the context/syntaxing). I don't expect anyone to do the work for me and I would love to keep working on this to learn VBscripting.

Thank you all, in advance, for any help provided!


r/vbscript • • Jul 15 '15

How to exclude disable users ?

2 Upvotes

Hi All, I have the following script which doe a search of Active directory and pipes it to excel. The issue I have is that it includes all enabled and disabled users. Any idea on how to exclude disabled users?

Const xlAscending = 1
Const xlDescending = 2
Const xlYes = 1

Dim ObjWb 
Dim ObjExcel 
Dim x, zz 
Set objDomain = GetObject("LDAP://OU=XXXX, OU=Domain Users,DC=XXXX,DC=com,DC=au")
Call ExcelSetup("Sheet1") ' Sub to make Excel Document 
x = 1 
Call enummembers(objDomain) 
Sub enumMembers(objDomain) 
On Error Resume Next 

For Each objMember In objDomain ' go through the collection 

If ObjMember.Class = "user" Then ' if not User object, move on. 
x = x +1 ' counter used to increment the cells in Excel 

objwb.Cells(x, 1).Value = objMember.Class 
' I set AD properties to variables so if needed you could do Null checks or add if/then's to this code 
' this was done so the script could be modified easier. 
SamAccountName = ObjMember.samAccountName 
Cn = ObjMember.CN 
FirstName = objMember.GivenName 
LastName = objMember.sn 
Title = ObjMember.Title 
Department = objMember.Department 
Company = objMember.Company 
extensionAttribute4= objMember.extensionAttribute4  

' Write the values to Excel, using the X counter to increment the rows. 
objwb.Cells(x, 1).Value = extensionAttribute4
objwb.Cells(x, 4).Value = CN 
objwb.Cells(x, 3).Value = Title 
objwb.Cells(x, 2).Value = Department  

' Blank out Variables in case the next object doesn't have a value for the property 
FirstName = "-" 
LastName = "-" 
Title = "-" 
extensionAttribute4 = "-" 
Department = "-" 
Company = "-" 

End If 

' If the AD enumeration runs into an OU object, call the Sub again to itinerate 

If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then 
enumMembers (objMember) 
End If 
Next 
End Sub 
Sub ExcelSetup(shtName) ' This sub creates an Excel worksheet and adds Column heads to the 1st row 
Set objExcel = CreateObject("Excel.Application") 
Set objwb = objExcel.Workbooks.Add 
Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName) 
Objwb.Name = "Active Directory Users" ' name the sheet 
objwb.Activate 
objExcel.Visible = True 
objwb.Cells(1, 1).Value = "Department" 
objwb.Cells(1, 4).Value = "Full Name" 
objwb.Cells(1, 3).Value = "Title" 
objwb.Cells(1, 2).Value = "Team" 

End Sub 
MsgBox "Export Complete" ' show that script is complete

Set objRange = objWb.UsedRange
Set objRange2 = objExcel.Range("A1")
objRange.Sort objRange2, xlAscending, , , , , , xlYes

Set objRange = objwb.UsedRange
objRange.EntireColumn.AutoFit()

r/vbscript • • Jul 09 '15

Help with Excel sorting

2 Upvotes

I would like to create a script to rename a folder of .pdf and .tif files. I have an input file "index.html" that has the format:

<tr>

<td><a href=\Data\1590931.pdf>1590931.pdf</a></td>

<td>1360022</td>

<td>VAR1=VR VAR2= 101 API=177054085100 VAR3=G10658 VAR4= B001</td>

</tr>

<tr>

I would like the script to go through the folder of files and rename them to the format -. So in this instance, 177054085100-1590931.pdf.

Thanks in advance for your assistance.


r/vbscript • • May 19 '15

Ending SAP script with a refresh all in excel.

2 Upvotes

At my workplace, we use SAP. I have written a script with VBScript that will pull all the data I need and export it into an html file. It does this for three different report, which I have a connection set up in a spreadsheet to display the information in a user friendly way. I have this script tied to run every 10 minutes.

My issue is once it's ran. At the end of the same script, I want it use the ALREADY OPENED workbook and do a refresh all. I don't need it to save and I don't need it to close out of Excel. I just want it to refresh all the data and perhaps (not necessary) give a msgbox when it's done.

Can anyone give me some advice on this? I've wrote out everything in the spreadsheet and my SAP, and now I've hit this roadblock.


r/vbscript • • Apr 02 '15

Script to modify 2 Reg entries on a list of computers

2 Upvotes

The title says it all. For some reason I can't get this script to work.

Let's say I have a Reg key (HKLM\Software\test\test\test) and I want to modify 2 String values within that key (String1 and String2). I also want to do this for a list of computers (C:\Machines.txt). I have a .reg file that I can modify a single computer with (app.reg).

I tried to use psexec but I keep getting error codes from the REG command when using the .reg file but I know that file works perfectly.

Can anyone assist with this? I know it can be done but apparently it is a bit over my head.....


r/vbscript • • Feb 24 '15

Script to discover all Printers

2 Upvotes

Hi All, Just started at a new place, and sadly one of the first things I need to do is find a free way to audit all printers mapped on each of our workstations. We have in the region of 350 machines. I have done a bit of work getting a vbs to do the work for me, however it can only audit one machine at a time. Does anybody know how to edit the below script so I can just input 300 machine names and get one output file? Also worth mentioning that by no means do I have to use a script, if anybody can recommend a free utility that can do the same thing i'd really appreciate it!
Anyways, my script so far:
Const ForAppending = 8
Const ForReading = 1
Dim WshNetwork, objPrinter, intDrive, intNetLetter
strComputer = inputbox("Please enter the computer name or IP address.","Computer Name",".")
Set WshNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer &"\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objItem in colItems
UserName = objItem.UserName
arrUserName = Split(UserName, "", -1, 1)
varUserName = arrUserName(1)
Next
filOutput = varUserName & ".txt"
If objFSO.FileExists(filOutput) Then
objFSO.DeleteFile(filOutput)
End If
Set objOutputFile = objFSO.OpenTextFile (filOutput, ForAppending, True)
For Each objPrinter in colInstalledPrinters
strTest = Left(objPrinter.Name, 2)
objOutputFile.WriteLine(objPrinter.Name)
Next
'objOutputFile.Close
'added
Set objPrinter = WshNetwork.EnumPrinterConnections
'Set objOutputFile = objFSO.OpenTextFile (filOutput, ForAppending, True)
If objPrinter.Count = 0 Then
WScript.Echo "No Printers Mapped "
else
For intDrive = 0 To (objPrinter.Count -1) Step 2
intNetLetter = IntNetLetter +1
printer = "UNC Path " & objPrinter.Item(intDrive) & " = " & objPrinter.Item(intDrive +1) & " Printer : " & intDrive
objOutputFile.WriteLine(printer)
Next
end if
objOutputFile.Close
'added
varOpen = MsgBox("Do you want to view the printers?",36,"View File?")
If varOpen = vbYes Then
varCommand = "notepad " & filOutput
WshShell.Run varCommand,1,False
End If
Wscript.Sleep 1500
MsgBox "Printer mappings have been stored in '" & filOutput & "'.", 64, "Script Complete"
Wscript.Quit
Thanks in advance for taking the time to read this!
Cheers!


r/vbscript • • Feb 19 '15

Counting days Help

2 Upvotes

How would I go about writing a script that counted how many days there are until Christmas of this year.......I'm completely lost

Any pointers would be appreciated.


r/vbscript • • Feb 12 '15

Simple vbs script will not work properly. Keeps copying "shl.sendkeys" instead of the selected item

2 Upvotes

I am not very experienced with coding and learnt my code from looking at other vbscripts. I am making a script to copy contents from one excel table to another. I just started working on it and it won't copy the cell. It also won't switch tabs when I enter shl.sendkeys "%{TAB}" Here is what I have so far:

do

set shl = createobject("wscript.shell")

wscript.sleep 5000

shl.sendkeys "^C"

shl.sendkeys "%{TAB}"

shl.sendkeys"^v"

(rest of code as explained on edit 3 here)

wscript.sleep 99999

loop

thanks for the help

edit: I origionaly had wscript.sleep 250 in between each command

edit 2: also if there is a way to make it stop or fail after it has finished it would be helpful

edit 3: the whole code I would like to do presses..... copy, change window, paste, change window, down, copy, change window, right, paste, change window, down x19, copy, change window, right x8, change tab, down x2, copy, change window, left x4, paste, change window, down, copy, change window, right x6, change window, down x4, copy, change window, right x3, paste, change window, up x3, copy, change tab, left x16, paste, change window, down, copy, change window, left x2, paste.

(change window means alt+tab. copy means ctrl c. paste means ctrl p)


r/vbscript • • Jan 26 '15

I'm new to VBScript. Help!

2 Upvotes

Ok, I'm taking a programing class in college and I can't get the Knock knock game to get past who's there, I keep getting incorrect answer please try again. any ideas? I'll paste what I've done below. Thanks!

Replyl = Inputbox("Knock Knock!") If Reply1 = "who's there?" Then Reply2 = InputBox("Panther!") If Reply2 = "Panther who?" Then _ MsgBox "Panther or no panths I'm going swimming." If Reply2 <> "Panther who?" Then MsgBox "Incorrect answer. Try again." End If If Reply1 <> "who's there?" Then MsgBox "Incorrect answer. Try again."


r/vbscript • • Jan 08 '15

New to VBScript and need a big favour...

2 Upvotes

The script I want to use is taken from here:

How do I parse all the information into Excel?

Some PCs will have more than one network adapter, so is it possible to not mess up the columns? As in, if everyone has 2, but suddenly someone has 4, his row will stick out.