Solved

combine 2 VBS scripts together

Posted on 2015-02-03
6
216 Views
Last Modified: 2015-02-03
Hi  

I have 2 individual vbs scripts that both work. one makes mapped drives and the second one makes a short cut to a office 365 login
I need to combine both scripts into the one vbs script file.

Mapped drive .vbs
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "S:" , "\\Prometheus\Student_Share"
objNetwork.MapNetworkDrive "T:" , "\\Prometheus\Teacher_Share"
objNetwork.MapNetworkDrive "x:" , "\\Prometheus\Folder Redirection"

Open in new window


Shortcut Office 365 .vbs
' CreateShortCut.vbs - Create a Desktop Shortcut.
' VBScript to create .lnk file

' ----------------------------------------------------------' 
Option Explicit
Dim objShell, objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath

' --------------------------------------------------
' Here are the variables that to change if you are making a 'real' script

strWorkDir ="C:\Documents and Settings\%username%\Desktop"
strAppPath = "https://login.microsoftonline.com/"
strIconPath = "%SystemRoot%\system32\SHELL32.dll,27"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Microsoft 365 Login.lnk")

' ---------------------------------------------------
' Section which adds the shortcut's key properties

objLink.Description = "Microsoft 365 Login"
objLink.HotKey = "CTRL+SHIFT+X"
objLink.IconLocation = strIconPath 
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save


WScript.Quit

' End of creating a desktop shortcut

Open in new window



Thanks
0
Comment
Question by:paddy086
  • 3
  • 2
6 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40586528
Combining 2 seperate VBScripts usually requires NO real knowledge
In this case, it's true. Just copy and paste both codes into a new text file and save it as newcode.vbs and it will run as expected (because there's no overlap in functions/names/variables etc).
But because there's a quit command in the second part, please copy the first part first and add the second part under it.

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "S:" , "\\Prometheus\Student_Share"
objNetwork.MapNetworkDrive "T:" , "\\Prometheus\Teacher_Share"
objNetwork.MapNetworkDrive "x:" , "\\Prometheus\Folder Redirection"

' CreateShortCut.vbs - Create a Desktop Shortcut.
' VBScript to create .lnk file

' ----------------------------------------------------------' 
Option Explicit
Dim objShell, objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath

' --------------------------------------------------
' Here are the variables that to change if you are making a 'real' script

strWorkDir ="C:\Documents and Settings\%username%\Desktop"
strAppPath = "https://login.microsoftonline.com/"
strIconPath = "%SystemRoot%\system32\SHELL32.dll,27"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Microsoft 365 Login.lnk")

' ---------------------------------------------------
' Section which adds the shortcut's key properties

objLink.Description = "Microsoft 365 Login"
objLink.HotKey = "CTRL+SHIFT+X"
objLink.IconLocation = strIconPath 
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save


WScript.Quit

' End of creating a desktop shortcut

Open in new window

0
 

Author Comment

by:paddy086
ID: 40586550
So I have done what you said but I get this error on.

Line:10
Char:1
Error: Expected statement
Code: 800A0400
Source: Microsoft VBScript compilation error

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "S:" , "\\Prometheus\Student_Share"
objNetwork.MapNetworkDrive "T:" , "\\Prometheus\Teacher_Share"
objNetwork.MapNetworkDrive "x:" , "\\Prometheus\Folder Redirection"

' CreateShortCut.vbs - Create a Desktop Shortcut.
' VBScript to create .lnk file

' ----------------------------------------------------------' 
Option Explicit
Dim objShell, objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath

' --------------------------------------------------
' Here are the variables that to change if you are making a 'real' script

strWorkDir ="C:\Documents and Settings\%username%\Desktop"
strAppPath = "https://login.microsoftonline.com/"
strIconPath = "%SystemRoot%\system32\SHELL32.dll,27"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Microsoft 365 Login.lnk")

' ---------------------------------------------------
' Section which adds the shortcut's key properties

objLink.Description = "Microsoft 365 Login"
objLink.HotKey = "CTRL+SHIFT+X"
objLink.IconLocation = strIconPath 
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save



WScript.Quit

' End of creating a desktop shortcut

Open in new window

0
 

Author Comment

by:paddy086
ID: 40586712
I've requested that this question be closed as follows:

Accepted answer: 0 points for paddy086's comment #a40586550

for the following reason:

Thanks I got it working by removing
Option Explicit
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 35

Expert Comment

by:Kimputer
ID: 40586713
I'm assuming you handing out 0 points to yourself means my answer didn't help you at all?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 40587442
Don't get rid of Option Explicit: it is actually there to help you!

Instead, move it up to the top line of the combined script.  Option Explicit, when used, must be the first line of actual code in the script file (although you can have comments and/or white space before it).
0
 

Author Closing Comment

by:paddy086
ID: 40587475
Sorry I taught I accepted your answer . Thanks for the help
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question